コード例 #1
0
    def test_set_score(self):
        goban = Goban((2, 2))
        state = GameState(goban)
        state.set_score(GameState.WHITE, 5)
        state.set_score(GameState.BLACK, 2)

        self.assertEqual(state.get_score(), {1: 2, 2: 0, 3: 5})
コード例 #2
0
    def test_get_winner(self):
        goban = Goban((2, 2))
        state = GameState(goban)
        state._score = {
            GameState.BLACK: 0,
            GameState.GREY: 0,
            GameState.WHITE: 0
        }
        self.assertEqual(state.get_winner(), [GameState.BLACK,
                                              GameState.GREY,
                                              GameState.WHITE])

        state._score = {
            GameState.BLACK: 0,
            GameState.GREY: 1,
            GameState.WHITE: 1
        }
        self.assertEqual(state.get_winner(), [GameState.GREY,
                                              GameState.WHITE])

        state._score = {
            GameState.BLACK: 0,
            GameState.GREY: 1,
            GameState.WHITE: 2
        }
        self.assertEqual(state.get_winner(), [GameState.WHITE])
コード例 #3
0
    def test_try_make_move(self):
        goban = Goban((3, 3))
        state = GameState(goban)
        player = CleverVirtualPlayer(state.GREY)

        state._turn = state.GREY
        points = state.get_free_points()
        move = player.try_make_move(state, 60)
        self.assertEqual(move[0], True)
        self.assertTrue(move[1] in points)

        string = '''
        ..X
        ...
        ...
        '''
        state = GameState.convert_string_to_state(string, '\n        ')
        state._turn = state.GREY
        move = player.try_make_move(state, 60)

        self.assertEqual(move[0], True)
        self.assertTrue(move[1] in [(1, 0), (2, 1)])

        string = '''
        .X.
        O.X
        .O.
        '''
        state = GameState.convert_string_to_state(string, '\n        ')
        state._turn = state.GREY

        self.assertEqual(player.try_make_move(state, 60), (False, None, 0))
コード例 #4
0
    def test_find_point_with_lack_of_time(self):
        goban = Goban((100, 100))
        state = GameState(goban)
        player = CleverVirtualPlayer(state.BLACK)

        with self.assertRaises(multiprocessing.TimeoutError):
            player.find_point_to_move(state, 0.01)
コード例 #5
0
    def test_get_state(self):
        goban = Goban((2, 2))
        state = GameState(goban)

        self.assertEqual(state.get_state((1, 1)), GameState.FREE)

        state._state[(1, 1)] = GameState.WHITE
        self.assertEqual(state.get_state((1, 1)), GameState.WHITE)
コード例 #6
0
    def test_get_free_points(self):
        goban = Goban((2, 2))
        state = GameState(goban)

        self.assertSetEqual(state.get_free_points(),
                            {(0, 0), (0, 1), (1, 0), (1, 1)})
        state._state[(0, 0)] = GameState.BLACK
        self.assertSetEqual(state.get_free_points(),
                            {(0, 1), (1, 0), (1, 1)})
コード例 #7
0
    def test_convert_state_to_string(self):
        goban = Goban((2, 2))
        state = GameState(goban)

        state._state[(0, 0)] = GameState.BLACK
        state._state[(1, 0)] = GameState.GREY
        state._state[(0, 1)] = GameState.WHITE

        self.assertEqual(state.convert_state_to_string(), 'X#;O.;')
コード例 #8
0
    def test_move(self):
        goban = Goban((2, 2))
        state = GameState(goban)

        state.make_move((1, 1))
        self.assertEqual(state.get_state((1, 1)), GameState.BLACK)
        self.assertEqual(state._turn, GameState.GREY)

        for point in ((2, 3), (1, 1)):
            with self.assertRaises(ValueError):
                state.make_move(point)
コード例 #9
0
    def test_get_turn(self):
        goban = Goban((2, 2))
        state = GameState(goban)

        self.assertEqual(state._turn, GameState.BLACK)
        state.next_turn()
        self.assertEqual(state._turn, GameState.GREY)
        state.next_turn()
        self.assertEqual(state._turn, GameState.WHITE)
        state.next_turn()
        self.assertEqual(state._turn, GameState.BLACK)
コード例 #10
0
    def test_score(self):
        goban = Goban((2, 2))
        state = GameState(goban)

        self.assertEqual(state._score, {1: 0, 2: 0, 3: 0})

        state.increase_score(2)
        state.next_turn()
        state.increase_score(3)
        state.next_turn()
        state.increase_score(4)

        self.assertEqual(state._score, {1: 2, 2: 3, 3: 4})
コード例 #11
0
    def test_convert_string_to_state(self):
        goban = Goban((2, 2))
        state = GameState(goban)

        state._state[(0, 0)] = GameState.BLACK
        state._state[(1, 0)] = GameState.GREY
        state._state[(0, 1)] = GameState.WHITE

        first_string = '''
        X#
        O.
        '''
        first_state = state.convert_string_to_state(first_string, '\n        ')

        second_string = 'X#;O.;'
        second_state = state.convert_string_to_state(second_string, ';')

        self.assertDictEqual(first_state._state, state._state)
        self.assertDictEqual(second_state._state, state._state)
コード例 #12
0
    def test_catch_group(self):
        goban = Goban((5, 5))
        state = GameState(goban)

        state._state[(1, 1)] = GameState.BLACK
        self.assertEqual(state.catch_group((1, 1)), 1)
        self.assertEqual(state.get_state((1, 1)), GameState.FREE)

        string = '''
        XXX..
        XXX..
        .....
        .....
        .....
        '''
        state = GameState.convert_string_to_state(string, '\n        ')
        self.assertEqual(state.catch_group((1, 1)), 6)

        for x in range(0, 3):
            for y in range(0, 2):
                self.assertEqual(state.get_state((x, y)), GameState.FREE)
コード例 #13
0
    def test_try_make_move(self):
        goban = Goban((2, 2))
        state = GameState(goban)
        player = SimpleVirtualPlayer(state.GREY)

        state._turn = state.GREY
        move = player.try_make_move(state, 60)
        self.assertEqual(move[0], True)
        self.assertTrue(move[1] in [(0, 0), (1, 0), (0, 1), (1, 1)])

        state._turn = state.GREY
        state._state[(0, 0)] = GameState.BLACK
        move = player.try_make_move(state, 60)
        self.assertEqual(move[0], True)
        self.assertTrue(move[1] in [(0, 1), (1, 0), (1, 1)])

        string = '''
        XX
        XX
        '''
        state = GameState.convert_string_to_state(string, '\n        ')
        state._turn = state.GREY

        self.assertEqual(player.try_make_move(state, 60), (False, None, 0))
コード例 #14
0
 def test_init_error(self):
     with self.assertRaises(TypeError):
         GameState([])
コード例 #15
0
    def test_init_state(self):
        goban = Goban((2, 2))
        state = GameState(goban)

        for point in ((0, 0), (1, 0), (0, 1), (1, 1)):
            self.assertEqual(GameState.FREE, state._state[point])
コード例 #16
0
    def test_set_turn(self):
        goban = Goban((2, 2))
        state = GameState(goban)
        state.set_turn(GameState.WHITE)

        self.assertEqual(state.get_turn(), GameState.WHITE)
コード例 #17
0
    def test_init_player(self):
        goban = Goban((2, 2))
        state = GameState(goban)
        player = CleverVirtualPlayer(state.GREY)

        self.assertEqual(player.get_colour(), state.GREY)
コード例 #18
0
    def test_init_player(self):
        goban = Goban((2, 2))
        state = GameState(goban)
        player = RealPlayer(state.BLACK)

        self.assertEqual(player.get_colour(), state.BLACK)
コード例 #19
0
    def test_get_full_state(self):
        goban = Goban((2, 2))
        state = GameState(goban)
        state.set_state((1, 1), GameState.WHITE)

        self.assertDictEqual(state.get_full_state(), state._state)
コード例 #20
0
    def test_get_goban_size(self):
        goban = Goban((3, 3))
        state = GameState(goban)

        self.assertEqual(state.get_goban_size(), 3)