public void testAvoidStarvation() {
    Game game = ServerTestHelper.startServerGame(getTestMap(marsh));

    int unitsBeforeNewTurn = 3;
    Colony colony = getStandardColony(unitsBeforeNewTurn);
    ServerPlayer player = (ServerPlayer) colony.getOwner();
    assertEquals("Wrong number of units in colony", unitsBeforeNewTurn, colony.getUnitCount());

    final Building townHall = colony.getBuilding(townHallType);
    for (Unit u : colony.getUnitList()) {
      u.setLocation(townHall);
    }
    colony.removeGoods(foodGoodsType);
    colony.invalidateCache();

    int consumption = colony.getFoodConsumption();
    int production = colony.getTile().getType().getPotentialProduction(grainType, null);
    assertEquals(6, consumption);
    assertEquals(3, production);
    assertEquals(-3, colony.getNetProductionOf(foodType));
    assertEquals(0, colony.getGoodsCount(foodType));
    assertEquals(0, colony.getTile().getUnitCount());

    colony.addGoods(foodType, 202);
    ServerTestHelper.newTurn();
    assertEquals(199, colony.getGoodsCount(foodType));
    assertEquals(0, colony.getTile().getUnitCount());
    assertEquals(3, colony.getUnitCount());

    colony.addGoods(foodType, 15);
    ServerTestHelper.newTurn();
    assertEquals(11, colony.getGoodsCount(foodType));
    assertEquals(1, colony.getTile().getUnitCount());
  }
Esempio n. 2
0
  /**
   * If there are two teachers with the same skill level, the first to be put in the school should
   * be used for teaching.
   */
  public void testSingleGuyTwoTeachers2() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit lumber = units.next();
    lumber.setType(expertLumberJackType);

    Unit ore = units.next();
    ore.setType(expertOreMinerType);

    // It should take 4 turns to train an expert lumber jack and
    // also 4 to train a ore miner.  First come first serve, the
    // lumber jack wins.
    lumber.setLocation(university);
    ore.setLocation(university);
    assertEquals(colonist.getTeacher(), lumber);
    assertNull(ore.getStudent());

    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    ServerTestHelper.newTurn();
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, expertLumberJackType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
  /** Tests invalid completion of buildable, having enough resources */
  public void testInvalidCompletion() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getStandardColony(2);
    Building carpenterHouse = colony.getBuilding(carpenterHouseType);
    assertEquals(
        "Colony should not have lumber mill", carpenterHouse, colony.getBuilding(lumberMillType));
    assertFalse("Colony should not be able to build lumber mill", colony.canBuild(lumberMillType));
    colony.setCurrentlyBuilding(lumberMillType);
    assertEquals(
        "Colony should be building lumber mill", lumberMillType, colony.getCurrentlyBuilding());
    // Add sufficient units and goods to build lumber mill.
    Unit unit = new ServerUnit(game, colony.getTile(), colony.getOwner(), colonistType);
    unit.setLocation(colony);
    for (AbstractGoods ag : lumberMillType.getRequiredGoods()) {
      GoodsType type = ag.getType();
      int amount = ag.getAmount() + 1;
      colony.addGoods(type, amount);
      assertEquals("Wrong quantity of " + type, amount, colony.getGoodsCount(type));
    }

    // Allow the building to finish
    ServerTestHelper.newTurn();

    assertEquals(
        "Colony should have lumber mill",
        lumberMillType,
        colony.getBuilding(lumberMillType).getType());
    assertFalse(
        "Colony should no longer be building lumber mill",
        colony.getCurrentlyBuilding() == lumberMillType);
  }
  public void testNoBuildingMaterialsProductionWhenBuildingNothing() {
    Game game = getGame();
    game.setMap(getTestMap(true));

    Colony colony = getStandardColony(4);
    Building carpenterHouse = colony.getBuilding(carpenterHouseType);
    Unit unit = colony.getFirstUnit();
    // necessary for work production
    int initialLumber = 100;
    int initialHammers = 0;
    colony.addGoods(lumberGoodsType, initialLumber);
    colony.setCurrentlyBuilding(null);

    assertEquals(
        "Wrong initial lumber quantity.", initialLumber, colony.getGoodsCount(lumberGoodsType));
    assertEquals(
        "Colony should not have initial hammers.",
        initialHammers,
        colony.getGoodsCount(hammerGoodsType));

    unit.setLocation(carpenterHouse);

    assertTrue(
        "Colony should be producing hammers.", colony.getTotalProductionOf(hammerGoodsType) > 0);

    ServerTestHelper.newTurn();

    assertEquals(
        "Colony should not have produced hammers.",
        initialHammers,
        colony.getGoodsCount(hammerGoodsType));
    assertEquals(
        "Wrong final lumber quantity.", initialLumber, colony.getGoodsCount(lumberGoodsType));
  }
Esempio n. 5
0
  /**
   * Progress in teaching is bound to the teacher and not the learner.
   *
   * <p>Moving students around does not slow education. This behavior is there to simplify gameplay.
   */
  public void testTeacherStoresProgress() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();
    Unit outsider = new ServerUnit(game, colony.getTile(), colony.getOwner(), freeColonistType);

    Building townHall = colony.getBuilding(townHallType);
    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(townHall);

    Unit teacher = units.next();
    teacher.setType(expertOreMinerType);
    teacher.setLocation(university);
    assertEquals(teacher.getStudent(), colonist);
    assertEquals(colonist.getTeacher(), teacher);

    // Train to become free colonist then swap the colonist with
    // another one.
    trainForTurns(colony, teacher.getNeededTurnsOfTraining() - 1);
    colonist.setLocation(colony.getTile());
    outsider.setLocation(townHall);
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(teacher.getStudent(), outsider);

    ServerTestHelper.newTurn();
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(expertOreMinerType, outsider.getType());

    FreeColTestUtils.setStudentSelection(selection);
  }
Esempio n. 6
0
  public void testCaseTwoTeachersWithDifferentExp() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit teacher1 = units.next();
    teacher1.setType(expertOreMinerType);

    Unit teacher2 = units.next();
    teacher2.setType(masterCarpenterType);

    // First we let the teacher1 train for 3 turns
    teacher1.setLocation(university);
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    assertEquals(3, teacher1.getTurnsOfTraining());

    // Then teacher2 for 1 turn
    teacher1.setLocation(colony.getWorkLocationFor(teacher1, grainType));
    teacher2.setLocation(university);
    ServerTestHelper.newTurn();
    assertEquals(0, teacher1.getTurnsOfTraining());
    assertEquals(1, teacher2.getTurnsOfTraining());

    // If we now also add teacher1 to the university, but
    // teacher2 should still be the teacher in charge
    teacher1.setLocation(university);
    assertNull(teacher1.getStudent());
    ServerTestHelper.newTurn();

    assertEquals(0, teacher1.getTurnsOfTraining());
    assertEquals(2, teacher2.getTurnsOfTraining());

    FreeColTestUtils.setStudentSelection(selection);
  }
Esempio n. 7
0
  /**
   * Trains partly one colonist then put another teacher.
   *
   * <p>Should not save progress but start all over.
   */
  public void testPartTraining() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit lumberjack = units.next();
    lumberjack.setType(expertLumberJackType);

    Unit miner = units.next();
    miner.setType(expertOreMinerType);

    // Put Lumberjack in School
    lumberjack.setLocation(university);
    assertEquals(lumberjack.getStudent(), colonist);
    assertEquals(colonist.getTeacher(), lumberjack);

    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();

    // After 2 turns replace by miner. Progress starts from scratch.
    lumberjack.setLocation(colony.getWorkLocationFor(lumberjack, grainType));
    assertNull(lumberjack.getStudent());
    assertNull(colonist.getTeacher());

    miner.setLocation(university);
    assertEquals(miner.getStudent(), colonist);
    assertEquals(colonist.getTeacher(), miner);

    trainForTurns(colony, miner.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
  public void testLibertyAndImmigration() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    final int population = 3;
    Colony colony = getStandardColony(population);

    ServerBuilding townHall = (ServerBuilding) colony.getBuilding(townHallType);
    Unit statesman = colony.getUnitList().get(0);
    townHall.setWorkFor(statesman);
    assertEquals(bellsType, statesman.getWorkType());

    ServerBuilding church = (ServerBuilding) colony.getBuilding(chapelType);
    church.upgrade();
    Unit preacher = colony.getUnitList().get(1);
    church.setWorkFor(preacher);
    assertEquals(crossesType, preacher.getWorkType());

    assertEquals(0, colony.getGoodsCount(bellsType));
    ServerTestHelper.newTurn();

    int bells = 3;
    assertEquals(population, colony.getUnitCount());
    assertEquals(bells, colony.getNetProductionOf(bellsType));
    assertEquals(bells, colony.getGoodsCount(bellsType));

    colony.addGoods(bellsType, 7);
    bells += 7;
    assertEquals(bells, colony.getGoodsCount(bellsType));
    assertEquals(bells, colony.getLiberty());

    colony.removeGoods(bellsType, 5);
    bells -= 5;
    assertEquals(bells, colony.getGoodsCount(bellsType));
    assertEquals(bells, colony.getLiberty());

    int crosses = colony.getTotalProductionOf(crossesType) - colony.getConsumptionOf(crossesType);
    assertEquals(crosses, colony.getNetProductionOf(crossesType));
    assertEquals(crosses, colony.getGoodsCount(crossesType));
    assertEquals(crosses, colony.getImmigration());

    colony.addGoods(crossesType, 7);
    crosses += 7;
    assertEquals(crosses, colony.getGoodsCount(crossesType));
    assertEquals(crosses, colony.getImmigration());

    colony.removeGoods(crossesType, 5);
    crosses -= 5;
    assertEquals(crosses, colony.getGoodsCount(crossesType));
    assertEquals(crosses, colony.getImmigration());
  }
  /** Tests completion of buildable */
  public void testBuildingCompletion() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getStandardColony();
    ServerBuilding initialWarehouse = new ServerBuilding(getGame(), colony, depotType);
    colony.addBuilding(initialWarehouse);
    assertTrue("Colony should be able to build warehouse", colony.canBuild(warehouseType));

    // Simulate that the build is done
    colony.setCurrentlyBuilding(warehouseType);
    colony.addGoods(hammerGoodsType, 90);
    assertFalse(
        "Colony should not have warehouse", colony.getWarehouse().getType() == warehouseType);

    ServerTestHelper.newTurn();

    assertTrue("Colony should have warehouse", colony.getWarehouse().getType() == warehouseType);
  }
Esempio n. 10
0
  public void testFoodConsumption() {
    Game game = ServerTestHelper.startServerGame(getTestMap(plains));
    ServerPlayer dutch = (ServerPlayer) game.getPlayerByNationId("model.nation.dutch");
    // Setting test colony and colonist
    Colony colony =
        FreeColTestUtils.getColonyBuilder().colonyTile(game.getMap().getTile(5, 8)).build();
    new ServerUnit(game, colony.getWorkLocationForProducing(bellsType), dutch, colonistType);
    assertEquals(0, colony.getGoodsCount(foodType));

    int quantity = colony.getFoodConsumption() * 2;
    colony.addGoods(foodGoodsType, quantity);
    int foodStored = colony.getGoodsCount(foodGoodsType);
    assertEquals(quantity, foodStored);
    int foodExpected = foodStored - colony.getFoodConsumption() + colony.getFoodProduction();

    ServerTestHelper.newTurn();
    assertEquals(
        "Unexpected value for remaining food, ", foodExpected, colony.getGoodsCount(foodGoodsType));
  }
Esempio n. 11
0
  public void testDeathByStarvation() {
    Game game = ServerTestHelper.startServerGame(getTestMap(marsh));

    int consumption, production, unitsBeforeNewTurn = 3;
    Colony colony = getStandardColony(unitsBeforeNewTurn);
    ServerPlayer player = (ServerPlayer) colony.getOwner();

    final Building townHall = colony.getBuilding(townHallType);
    for (Unit u : colony.getUnitList()) {
      u.setLocation(townHall);
    }
    colony.removeGoods(foodGoodsType);
    colony.invalidateCache();

    consumption = colony.getFoodConsumption();
    production = colony.getFoodProduction();
    assertTrue(
        "Food consumption ("
            + consumption
            + ") should be higher than production ("
            + production
            + ")",
        consumption > production);
    assertEquals("No food stored in colony", 0, colony.getGoodsCount(foodType));
    assertEquals("Wrong number of units in colony", unitsBeforeNewTurn, colony.getUnitCount());

    ServerTestHelper.newTurn();

    consumption = colony.getFoodConsumption();
    production = colony.getFoodProduction();
    assertTrue(
        "Food consumption ("
            + consumption
            + ") should be higher than production ("
            + production
            + ")",
        consumption > production);
    assertEquals("No food stored in colony", 0, colony.getGoodsCount(foodType));
    assertEquals("Wrong number of units in colony", unitsBeforeNewTurn - 1, colony.getUnitCount());
  }
Esempio n. 12
0
  public void testConcurrentUpgrade() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(2, SchoolLevel.SCHOOLHOUSE);
    Building school = colony.getBuilding(schoolType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit lumber = units.next();
    lumber.setType(expertLumberJackType);

    Unit student = units.next();
    student.setType(pettyCriminalType);
    student.setLocation(colony.getBuilding(townHallType));

    assertTrue(school.canTeach());
    assertTrue(colony.canTrain(lumber));
    lumber.setLocation(school);

    ServerTestHelper.newTurn();
    assertEquals(student, lumber.getStudent());

    // lumber jack can teach indentured servant
    student.changeType(indenturedServantType);
    assertEquals(student, lumber.getStudent());

    // lumber jack can teach free colonist
    student.changeType(freeColonistType);
    assertEquals(student, lumber.getStudent());

    // lumber jack can not teach expert
    student.changeType(masterCarpenterType);
    assertNull(lumber.getStudent());
    assertNull(student.getTeacher());

    FreeColTestUtils.setStudentSelection(selection);
  }
Esempio n. 13
0
 private void trainForTurns(Colony colony, int requiredTurns) {
   for (int turn = 0; turn < requiredTurns; turn++) {
     ServerTestHelper.newTurn();
   }
 }
Esempio n. 14
0
  /**
   * [ 1616384 ] Teaching
   *
   * <p>One LumberJack and one BlackSmith in a college. 4 Free Colonists, one as LumberJack, one as
   * BlackSmith two as Farmers.
   *
   * <p>After some turns (2 or 3 I don't know) a new LumberJack is ready. Removing the teacher
   * LumberJack replaced by an Ore Miner.
   *
   * <p>Next turn, a new BlackSmith is ready. Removing the teacher BlackSmith replaced by a Veteran
   * Soldier. There is still 2 Free Colonists as Farmers in the Colony.
   *
   * <p>Waiting during more than 8 turns. NOTHING happens.
   *
   * <p>Changing the two Free Colonists by two other Free Colonists.
   *
   * <p>After 2 or 3 turns, a new Ore Miner and a new Veteran Soldier are ready.
   *
   * <p>http://sourceforge.net/tracker/index.php?func=detail&aid=1616384&group_id=43225&atid=435578
   *
   * <p>CO: I think this is a special case of the testSingleGuyTwoTeachers. But since already the
   * TwoTeachersSimple case fails, I think that needs to be sorted out first.
   */
  public void testTrackerBug1616384() {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    // otherwise this test will crash and burn
    boolean selection = FreeColTestUtils.setStudentSelection(false);

    Colony colony = getSchoolColony(8, SchoolLevel.COLLEGE);
    // prevent starvation
    colony.addGoods(foodType, 100);

    Building college = colony.getBuilding(collegeType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist1 = units.next();
    colonist1.setType(freeColonistType);
    colonist1.setLocation(colony.getBuilding(townHallType));

    Unit colonist2 = units.next();
    colonist2.setType(freeColonistType);
    colonist2.setLocation(colony.getBuilding(townHallType));

    Unit colonist3 = units.next();
    colonist3.setType(freeColonistType);
    colonist3.setLocation(colony.getBuilding(lumberMillType));

    Unit colonist4 = units.next();
    colonist4.setType(freeColonistType);
    colonist4.setLocation(colony.getBuilding(lumberMillType));

    Unit lumberjack = units.next();
    lumberjack.setType(expertLumberJackType);

    Unit blacksmith = units.next();
    blacksmith.setType(masterBlacksmithType);

    Unit veteran = units.next();
    veteran.setType(veteranSoldierType);

    Unit ore = units.next();
    ore.setType(expertOreMinerType);

    blacksmith.setLocation(college);
    lumberjack.setLocation(college);
    assertNotNull(blacksmith.getStudent());
    assertNotNull(lumberjack.getStudent());

    assertEquals(4, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, masterBlacksmithType).size());
    assertEquals(1, getUnitList(colony, expertLumberJackType).size());

    while (4 == getUnitList(colony, freeColonistType).size()) {
      ServerTestHelper.newTurn();
    }

    assertEquals(3, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, masterBlacksmithType).size());
    assertEquals(2, getUnitList(colony, expertLumberJackType).size());

    lumberjack.setLocation(colony.getWorkLocationFor(lumberjack, grainType));
    assertNull(lumberjack.getStudent());
    Unit smithToBe = blacksmith.getStudent();
    assertNotNull(smithToBe);
    ore.setLocation(college);
    assertNotNull(ore.getStudent());

    while (3 == getUnitList(colony, freeColonistType).size()) {
      ServerTestHelper.newTurn();
    }
    assertEquals(masterBlacksmithType, smithToBe.getType());
    assertEquals(2, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(2, getUnitList(colony, masterBlacksmithType).size());

    blacksmith.setLocation(colony.getWorkLocationFor(blacksmith, grainType));
    assertNull(blacksmith.getStudent());
    veteran.setLocation(college);
    assertNotNull(veteran.getStudent());

    while (2 == getUnitList(colony, freeColonistType).size()) {
      ServerTestHelper.newTurn();
    }
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());

    ore.setLocation(colony.getWorkLocationFor(ore, grainType));
    assertNull(ore.getStudent());

    while (1 == getUnitList(colony, freeColonistType).size()) {
      ServerTestHelper.newTurn();
    }
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, veteranSoldierType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
Esempio n. 15
0
  /**
   * Progress in teaching is bound to the teacher and not the learner.
   *
   * <p>Moving a teacher inside the colony should not reset its training.
   */
  public void testMoveTeacherInside() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    // prevent starvation
    colony.addGoods(foodType, 100);

    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit criminal = units.next();
    criminal.setType(pettyCriminalType);
    criminal.setLocation(colony.getBuilding(townHallType));

    Unit teacher1 = units.next();
    teacher1.setType(expertOreMinerType);

    Unit teacher2 = units.next();
    teacher2.setType(masterCarpenterType);

    // The carpenter is set in the school before the miner.
    // In this case, the colonist will become a miner (and the criminal
    // will become a servant).
    teacher2.setLocation(university);
    teacher1.setLocation(university);
    assertEquals(4, teacher1.getNeededTurnsOfTraining());
    assertEquals(4, teacher2.getNeededTurnsOfTraining());

    // wait a little
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    assertEquals(2, teacher1.getTurnsOfTraining());
    assertEquals(2, teacher2.getTurnsOfTraining());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, pettyCriminalType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(1, getUnitList(colony, masterCarpenterType).size());

    // Now we want the colonist to be a carpenter. We just want to
    // shuffle the teachers.  Move them out of the school.
    teacher2.setLocation(colony.getWorkLocationFor(teacher2, grainType));
    teacher1.setLocation(colony.getTile());
    assertNull(teacher1.getStudent());
    assertNull(teacher2.getStudent());

    // Moving outside school resets training
    ServerTestHelper.newTurn();
    assertEquals(0, teacher1.getTurnsOfTraining());
    assertEquals(0, teacher2.getTurnsOfTraining());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, pettyCriminalType).size());

    // Move teachers back to school, miner first to pick up the criminal
    teacher1.setLocation(university);
    teacher2.setLocation(university);

    ServerTestHelper.newTurn();
    assertEquals(1, teacher1.getTurnsOfTraining());
    assertEquals(1, teacher2.getTurnsOfTraining());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, pettyCriminalType).size());

    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    assertEquals(0, teacher1.getTurnsOfTraining());
    assertEquals(0, teacher2.getTurnsOfTraining());

    // Teacher1's student (criminal) should be a servant now
    // Teacher2's student (colonist) should be a carpenter now
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(0, getUnitList(colony, pettyCriminalType).size());
    assertEquals(1, getUnitList(colony, indenturedServantType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(2, getUnitList(colony, masterCarpenterType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
Esempio n. 16
0
  /**
   * Progress in teaching is bound to the teacher and not the learner.
   *
   * <p>Moving a teacher outside the colony should reset its training.
   */
  public void testMoveTeacherOutside() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony otherColony = getStandardColony(1, 10, 10);
    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    // prevent starvation
    colony.addGoods(foodType, 100);

    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit criminal = units.next();
    criminal.setType(pettyCriminalType);
    criminal.setLocation(colony.getBuilding(townHallType));

    Unit teacher1 = units.next();
    teacher1.setType(expertOreMinerType);

    Unit teacher2 = units.next();
    teacher2.setType(masterCarpenterType);

    // The carpenter is set in the school before the miner
    // In this case, the colonist will become a miner (and the criminal
    // will become a servant).
    teacher2.setLocation(university);
    teacher1.setLocation(university);

    // wait a little
    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, pettyCriminalType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(1, getUnitList(colony, masterCarpenterType).size());
    assertEquals(2, teacher1.getTurnsOfTraining());
    assertEquals(2, teacher2.getTurnsOfTraining());

    // Now we move the teachers somewhere beyond the colony
    teacher1.setLocation(getGame().getMap().getTile(6, 8));
    teacher2.setLocation(otherColony);
    assertEquals(0, teacher1.getTurnsOfTraining());
    assertEquals(0, teacher2.getTurnsOfTraining());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, pettyCriminalType).size());
    assertEquals(0, getUnitList(colony, expertOreMinerType).size());
    assertEquals(0, getUnitList(colony, masterCarpenterType).size());

    // Put them back here
    teacher2.setLocation(university);
    teacher1.setLocation(university);
    assertEquals(0, teacher1.getTurnsOfTraining());
    assertEquals(0, teacher2.getTurnsOfTraining());
    assertEquals(teacher1, colonist.getTeacher());
    assertEquals(teacher2, criminal.getTeacher());

    // Check that 2 new turns aren't enough for training
    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, pettyCriminalType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(1, getUnitList(colony, masterCarpenterType).size());

    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, pettyCriminalType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(1, getUnitList(colony, masterCarpenterType).size());

    ServerTestHelper.newTurn();
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, pettyCriminalType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(1, getUnitList(colony, masterCarpenterType).size());

    ServerTestHelper.newTurn();
    assertEquals(0, getUnitList(colony, freeColonistType).size());
    assertEquals(0, getUnitList(colony, pettyCriminalType).size());
    assertEquals(1, getUnitList(colony, indenturedServantType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());
    assertEquals(1, getUnitList(colony, masterCarpenterType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
Esempio n. 17
0
  /**
   * Test that free colonists are trained before indentured servants, which are preferred to petty
   * criminals.
   */
  public void testTeachingOrder() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getSchoolColony(4, SchoolLevel.UNIVERSITY);
    // prevent starvation
    colony.addGoods(foodType, 100);

    Building university = colony.getBuilding(universityType);
    Iterator<Unit> units = colony.getUnitIterator();

    Unit colonist = units.next();
    colonist.setType(freeColonistType);
    colonist.setLocation(colony.getBuilding(townHallType));

    Unit indenturedServant = units.next();
    indenturedServant.setType(indenturedServantType);
    indenturedServant.setLocation(colony.getBuilding(townHallType));

    Unit criminal = units.next();
    criminal.setType(pettyCriminalType);
    criminal.setLocation(colony.getBuilding(townHallType));

    Unit teacher = units.next();
    teacher.setType(expertOreMinerType);
    teacher.setLocation(university);

    assertTrue(colonist.canBeStudent(teacher));
    assertTrue(indenturedServant.canBeStudent(teacher));
    assertTrue(criminal.canBeStudent(teacher));

    // Criminal training
    assertEquals(teacher, criminal.getTeacher());
    assertEquals(criminal, teacher.getStudent());
    trainForTurns(colony, teacher.getNeededTurnsOfTraining());

    assertEquals(0, getUnitList(colony, pettyCriminalType).size());
    assertEquals(indenturedServantType, criminal.getType());
    criminal.setLocation(getGame().getMap().getTile(10, 8));

    // Servant training
    assertNull(teacher.getStudent());
    ServerTestHelper.newTurn();
    assertEquals(teacher, indenturedServant.getTeacher());
    assertEquals(indenturedServant, teacher.getStudent());
    trainForTurns(colony, teacher.getNeededTurnsOfTraining());

    assertEquals(0, getUnitList(colony, indenturedServantType).size());
    assertEquals(2, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, expertOreMinerType).size());
    assertEquals(freeColonistType, indenturedServant.getType());

    // Colonist(former servant) training continues
    assertEquals(teacher, indenturedServant.getTeacher());
    assertEquals(indenturedServant, teacher.getStudent());
    assertEquals(colonist.getTeacher(), null);

    trainForTurns(colony, teacher.getNeededTurnsOfTraining());
    assertEquals(0, getUnitList(colony, indenturedServantType).size());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());
    assertEquals(expertOreMinerType, indenturedServant.getType());
    assertEquals(indenturedServant.getTeacher(), null);

    FreeColTestUtils.setStudentSelection(selection);
  }