示例#1
0
 def test_combined_vertical_advance_player_1(self):
     game_1 = CCGame(width=5)
     game_2 = CCGame(width=5)
     game_1.board = TEST_BOARD_VA_1_1
     game_2.board = TEST_BOARD_VA_1_2
     heuristic = CombinedVerticalAdvance()
     self.assertTrue(heuristic.value(game_1, 1) <
                     heuristic.value(game_2, 1))
示例#2
0
 def test_combined_heuristic(self):
     game_1 = CCGame(width=5)
     game_2 = CCGame(width=5)
     game_1.board = TEST_BOARD_VA_2_1
     game_2.board = TEST_BOARD_VA_2_2
     heuristic = CombinedVerticalAdvance()
     self.assertTrue(heuristic.value(game_1, 2) <
                     heuristic.value(game_2, 2))
    def test_player_1_wins_in_one(self):
        game = CCGame(width=5, player_row_span=3)
        game.board = TEST_BOARD_STRATEGY_PLAYER_1_WINS_IN_ONE
        strategy = MinMaxStrategy(steps=0)

        move, score = strategy._select_move(game, 1, 0, -100000, 100000)
        game.apply_move_sequence(move)
        self.assertEqual(100000, score)
        self.assertEqual(1, game.state())
    def test_player_1_wins(self):
        game = CCGame(width=5, player_row_span=3)
        game.board = TEST_BOARD_STRATEGY_PLAYER_1_WINS_IN_TWO
        strategy = MinMaxStrategy(alpha_beta_pruning=False)

        move, score = strategy._select_move(game, 1, 0, -100000, 100000)
        self.assertTrue(score > 1000)
        game.apply_move_sequence(move)

        game.rotate_turn()

        move, score = strategy._select_move(game, 1, 0, -100000, 100000)
        self.assertEqual(100000, score)

        game.apply_move_sequence(move)
        self.assertEqual(1, game.state())
示例#5
0
    def test_player_1_wins(self):
        game = CCGame(width=5, player_row_span=3)
        game.board = TEST_BOARD_STRATEGY_PLAYER_1_WINS_IN_TWO
        strategy = OnlyMaxStrategy(steps=1,
                                   player=1,
                                   heuristic=CombinedVerticalAdvance())

        move, score = strategy._select_move(game, 0)
        self.assertEqual(50000, score)
        game.apply_move_sequence(move)
        game.rotate_turn()

        move, score = strategy._select_move(game, 0)
        self.assertEqual(100000, score)

        game.apply_move_sequence(move)

        self.assertEqual(1, game.state())
示例#6
0
 def test_inv_squared_sum_center_line(self):
     game = CCGame(width=5)
     game.board = TEST_BOARD_CENTER_LINE
     heuristic = InvSquaredSumCenterLine()
     self.assertTrue(heuristic.value(game, 2) <
                     heuristic.value(game, 1))
示例#7
0
 def inv_squared_sum_dest_corner_zero(self):
     game = CCGame(width=5)
     game.board = TEST_BOARD_SQUARED_SUM_ZERO
     heuristic = InvSquaredSumDestCorner()
     self.assertEqual(heuristic.value(game, 1), 0)
     self.assertEqual(heuristic.value(game, 2), 0)
示例#8
0
 def test_inv_squared_sum_dest_corner(self):
     game = CCGame(width=5)
     game.board = TEST_BOARD_SQUARED_SUM
     heuristic = InvSquaredSumDestCorner()
     self.assertTrue(heuristic.value(game, 1) <
                     heuristic.value(game, 2))
 def test_use_only_max_false(self):
     game = CCGame(width=5, player_row_span=3)
     game.board = TEST_BOARD_VA_1_1
     strat = MinMaxStrategy(steps=0, alpha_beta_pruning=False)
     self.assertFalse(strat._use_only_max(game))
 def test_use_only_max_end_game(self):
     game = CCGame(width=5, player_row_span=2)
     game.board = TEST_BOARD_END_GAME
     strat = MinMaxStrategy(steps=0, alpha_beta_pruning=False)
     self.assertTrue(strat._use_only_max(game))