Exemplo n.º 1
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);
  }
Exemplo n.º 2
0
  public void testTwoTeachersSimple() {
    boolean selection = FreeColTestUtils.setStudentSelection(false);

    Game game = ServerTestHelper.startServerGame(getTestMap(true));
    Colony colony = getSchoolColony(5, SchoolLevel.UNIVERSITY);
    // prevent starvation
    colony.addGoods(foodType, 100);

    Building university = colony.getBuilding(universityType);
    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(townHallType));

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

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

    black.setLocation(university);
    ore.setLocation(university);

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

    trainForTurns(colony, ore.getNeededTurnsOfTraining());
    assertEquals(2, getUnitList(colony, freeColonistType).size());
    assertEquals(1, getUnitList(colony, masterBlacksmithType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());
    assertNotNull(ore.getStudent());
    assertNotNull(black.getStudent());

    trainForTurns(colony, black.getNeededTurnsOfTraining() - black.getTurnsOfTraining());
    assertEquals(1, getUnitList(colony, freeColonistType).size());
    assertEquals(2, getUnitList(colony, masterBlacksmithType).size());
    assertEquals(2, getUnitList(colony, expertOreMinerType).size());

    FreeColTestUtils.setStudentSelection(selection);
  }
Exemplo n.º 3
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);
  }
Exemplo n.º 4
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);
  }