예제 #1
0
  @Test
  public final void testIsPotentialMill() {
    Board b = TestAccessor.Game.getBoard(game);
    Node[] nodes = TestAccessor.Board.getNodes(b);

    // Set up board:
    //  AI------------AI------------AI
    //  |             |              |
    //  |    03-------AI------AI     |
    //  |    |        |        |     |
    //  |    |    06--07--08   |     |
    //  |    |    |        |   |     |
    //  AI---10---AI      AI---13---14
    //  |    |    |        |   |     |
    //  |    |    15--16--17   |     |
    //  |    |        |        |     |
    //  |    AI-------AI------20     |
    //  |             |              |
    //  21------------AI------------23

    nodes[0].setPlayer(aiPlayer);
    nodes[1].setPlayer(aiPlayer);
    nodes[2].setPlayer(aiPlayer);
    nodes[4].setPlayer(aiPlayer);
    nodes[5].setPlayer(aiPlayer);
    nodes[9].setPlayer(aiPlayer);
    nodes[11].setPlayer(aiPlayer);
    nodes[12].setPlayer(aiPlayer);
    nodes[18].setPlayer(aiPlayer);
    nodes[19].setPlayer(aiPlayer);
    nodes[22].setPlayer(aiPlayer);

    // Potential mills: 3, 7, 10, 16, 20, 21
    assertTrue(TestAccessor.AI.isPotentialMill(ai, 3, aiPlayer));
    assertTrue(TestAccessor.AI.isPotentialMill(ai, 7, aiPlayer));
    assertTrue(TestAccessor.AI.isPotentialMill(ai, 10, aiPlayer));
    assertTrue(TestAccessor.AI.isPotentialMill(ai, 16, aiPlayer));
    assertTrue(TestAccessor.AI.isPotentialMill(ai, 20, aiPlayer));
    assertTrue(TestAccessor.AI.isPotentialMill(ai, 21, aiPlayer));

    // Non-potential mills: 0-2, 4-6, 8, 9, 11-15, 17-19, 22, 23
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 0, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 1, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 2, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 4, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 5, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 6, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 8, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 9, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 11, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 12, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 13, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 14, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 15, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 17, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 18, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 19, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 22, aiPlayer));
    assertFalse(TestAccessor.AI.isPotentialMill(ai, 23, aiPlayer));
  }
예제 #2
0
  @Before
  public void setUp() throws Exception {
    game = new Game();
    aiPlayer = TestAccessor.Game.getPlayer2(game);

    ai = new AI(aiPlayer, game, true);
  }
예제 #3
0
  @Test
  public final void testMyNodes() {
    Board b = TestAccessor.Game.getBoard(game);
    Node[] nodes = TestAccessor.Board.getNodes(b);

    // Set up board:
    nodes[0].setPlayer(aiPlayer);
    nodes[1].setPlayer(aiPlayer);
    nodes[2].setPlayer(aiPlayer);
    nodes[4].setPlayer(aiPlayer);
    nodes[5].setPlayer(aiPlayer);
    nodes[9].setPlayer(aiPlayer);
    nodes[11].setPlayer(aiPlayer);
    nodes[12].setPlayer(aiPlayer);
    nodes[18].setPlayer(aiPlayer);
    nodes[19].setPlayer(aiPlayer);
    nodes[22].setPlayer(aiPlayer);

    LinkedList<Node> mynodes = TestAccessor.AI.myNodes(ai);
    assertEquals(mynodes.size(), 11);
    assertTrue(mynodes.contains(nodes[0]));
    assertTrue(mynodes.contains(nodes[1]));
    assertTrue(mynodes.contains(nodes[2]));
    assertFalse(mynodes.contains(nodes[3]));
    assertTrue(mynodes.contains(nodes[4]));
    assertTrue(mynodes.contains(nodes[5]));
    assertFalse(mynodes.contains(nodes[6]));
  }
예제 #4
0
 @Test
 public final void testEasyVsHard() {
   for (int i = 0; i < 10; i++) {
     try {
       setUp();
       Player aiPlayer1 = TestAccessor.Game.getPlayer1(game);
       AI ai1 = new AI(aiPlayer1, game, false);
       while (game.getWinner() == null) {
         Player currPlayer = TestAccessor.Game.getCurrentPlayer(game);
         if (currPlayer == aiPlayer) ai.doNextMove();
         else ai1.doNextMove();
       }
       //        System.out.println("Winner: " + game.getWinner().name);
     } catch (IllegalMoveException e) {
       e.printStackTrace();
       fail();
     } catch (Exception e) {
       e.printStackTrace();
       fail();
     }
   }
 }
예제 #5
0
 @Test
 public final void testGetOpponent() {
   Player player1 = TestAccessor.Game.getPlayer1(game);
   Player opponent = TestAccessor.AI.getOpponent(ai);
   assertEquals(player1, opponent);
 }