Exemple #1
0
 def test_opening_move(self):
     """ Test the opening moves. It appears that none of the tests nor the tournament tests this, so
     I added some tests here"""
     player1 = CustomPlayer()
     player2 = CustomPlayer()
     board = isolation.Board(player1, player2, 5, 5)
     move1 = player1.get_move(board, board.get_legal_moves(player1), 1000)
     self.assertTrue(move1 == (3,3))
     board.apply_move(move1)
     move2 = player2.get_move(board, board.get_legal_moves(player2), 1000)
     self.assertTrue(move2 == (3,4))
    # place player 1 on the board at row 2, column 3, then place player 2 on
    # the board at row 0, column 5; display the resulting board state.  Note
    # that .apply_move() changes the calling object

    game.apply_move((5, 5))
    game.apply_move((0, 5))
    print('Start game... \n')
    print(game.to_string())

    # players take turns moving on the board, so player1 should be next to move
    assert (player1 == game.active_player)

    # get a list of the legal moves available to the active player
    print('legal moves', game.get_legal_moves())

    action = player1.get_move(game, game.get_legal_moves(),
                              timeit.default_timer())
    #print 'ACTION', action
    #new_game = game.forecast_move(action)
    #assert(new_game.to_string() != game.to_string())
    #print("\nOld state:\n{}".format(game.to_string()))
    #print("\nNew state:\n{}".format(new_game.to_string()))

    # get a successor of the current state by making a copy of the board and
    # applying a move. Notice that this does NOT change the calling object
    # (unlike .apply_move()).

    new_game = game.forecast_move((action))
    assert (new_game.to_string() != game.to_string())
    print("\nOld state:\n{}".format(game.to_string()))
    print("\nNew state:\n{}".format(new_game.to_string()))