Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
  @Override
  public Board makeBestMove(Board evaluatedBoard) {
    Board bestMove = evaluatedBoard.cloneBoard();
    negaMax(evaluatedBoard, bestMove, -INFINITY, INFINITY, 0);

    // Copy its data, and switch turns.
    evaluatedBoard.squares = bestMove.squares;
    evaluatedBoard.dwarvesTurn = bestMove.dwarvesTurn;

    return bestMove;
  }