예제 #1
0
  @Override
  public void fight(Individual otherIndividual) {
    NegamaxPlayer otherNegamaxPlayer = (NegamaxPlayer) otherIndividual;

    // Get the test ground.
    Board testBoard = initialTestBoard.cloneBoard();

    // Fight until a side wins, or a max number of turns has elapsed.
    boolean myTurn = true;
    int iteration = 0;
    while (testBoard.numberOf(DWARF) > 0 && testBoard.numberOf(TROLL) > 0 && iteration++ < 1000) {
      if (myTurn) {
        makeBestMove(testBoard);
      } else {
        otherNegamaxPlayer.makeBestMove(testBoard);
      }
      myTurn = !myTurn;
    }

    // Update the fitnesses of the players.
    // Since the dwarves play first, the first player, me, scores the dzqrf side.
    int score = testBoard.numberOf(DWARF) - 4 * testBoard.numberOf(TROLL);
    fitness += score;
    otherNegamaxPlayer.fitness -= score;
  }