示例#1
0
    def test_score_time(self):
        player1 = game_agent.MinimaxPlayer()
        player2 = sample_players.GreedyPlayer()

        game = isolation.Board(player1, player2)

        for _ in range(0, 2):
            game.apply_move(random.choice(game.get_legal_moves()))

        game_agent.custom_score(game, game.get_player_location(game.active_player))
        game_agent.custom_score_2(game, game.get_player_location(game.active_player))
        game_agent.custom_score_3(game, game.get_player_location(game.active_player))
示例#2
0
 def test_custom_score(self):
     self.setUp()
     self.game.apply_move((2, 1))
     self.game.apply_move((3, 3))
     player1_custom_score = game_agent.custom_score(self.game, self.player1)
     self.assertIsNotNone(player1_custom_score)
     self.assertIsInstance(player1_custom_score, float)
示例#3
0
    def test_heuristics_lmbl(self):

        game = self.setup_board()

        print(game.to_string())
        score = game_agent.custom_score(game, game.active_player, "lmlb")
        assert (score == -1)
示例#4
0
    def test_heuristics_schadenfreude(self):

        game = self.setup_board()

        print(game.to_string())
        score = game_agent.custom_score(game, game.active_player,
                                        "schadenfreude")
        assert (score == -3)
示例#5
0
    def test_heuristics_ds(self):

        game = self.setup_board()

        print(game.to_string())
        score = game_agent.custom_score(game, game.active_player, "ds")
        assert (score > 0.05)
        assert (score < 0.06)
示例#6
0
    def test_custom_score_one_ply(self):
        self.small_g.apply_move((1, 1))
        print(self.small_g.print_board())

        actual = game_agent.custom_score(self.small_g, self.p1)
        #P1 has 4 possible moves from a middle square
        #P2 having not yet moved, can occupy any of the remaing 15 square
        expected = -11

        self.assertEqual(actual, expected)
示例#7
0
    def test_heuristic(self):
        """Test output interface of heuristic score function interface."""
        player1 = "Player1"
        player2 = "Player2"
        p1_location = (0, 0)
        p2_location = (1, 1)  # top left corner
        game = isolation.Board(player1, player2)
        game.apply_move(p1_location)
        game.apply_move(p2_location)

        self.assertIsInstance(game_agent.custom_score(game, player1), float,
            "The heuristic function should return a floating point")
示例#8
0
    def test_heuristic(self):
        """ Test output interface of heuristic score function interface."""

        player1 = "Player1"
        player2 = "Player2"
        p1_location = (0, 0)
        p2_location = (1, 1)  # top left corner
        game = isolation.Board(player1, player2)
        game.apply_move(p1_location)
        game.apply_move(p2_location)

        self.assertIsInstance(game_agent.custom_score(game, player1), float,
            "The heuristic function should return a floating point")
示例#9
0
def test6():
    player1 = AlphaBetaPlayer(search_depth=1, score_fn=custom_score)
    player2 = AlphaBetaPlayer(search_depth=1, score_fn=custom_score_3)
    game = isolation.Board(player1, player2, height=5, width=5)
    game.apply_move((0, 3))
    print(game.to_string())
    game.apply_move((4, 4))
    print(game.to_string())
    game.apply_move((3, 2))
    print(game.to_string())
    game.apply_move((1, 1))
    game.apply_move((2, 0))
    game.apply_move((3, 0))
    game.apply_move((1, 2))

    print(game.to_string())
    print(custom_score(game, game.active_player))
    print(custom_score(game, game.inactive_player))
    print(custom_score_2(game, game.active_player))
    print(custom_score_2(game, game.inactive_player))
    print(custom_score_3(game, game.active_player))
    print(custom_score_3(game, game.inactive_player))
    print(improved_score(game, game.active_player))
    print(improved_score(game, game.inactive_player))
示例#10
0
 def test_custom_score(self):
     game = self.game
     player = self.player1
     evaluate_game = game_agent.custom_score(game, player)
     self.assertTrue(evaluate_game == 49)
示例#11
0
 def custom_score_two_plies(self):
     self.small_g.apply_move((1, 1))
     self.small_g.apply_move((0, 0))
     actual = game_agent.custom_score(self.small_g, self.p1)
     expected = 2  #4 - 2
     self.assertEqual(actual, expected)
示例#12
0
 def custom_score_no_plies(self):
     # In the initial state, each player has the same amount of possible moves
     actual = game_agent.custom_score(self.small_g, self.p1)
     expected = 0  #16 - 16
     self.assertEqual(actual, expected)