Exemplo n.º 1
0
    def test_bug(self):
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ○ ○ ● ●
        # ● ● ● ● ● ● . ● ●
        # ● ● ● ● ● ● ○ ○ ○
        size = conf['SIZE']
        board = np.zeros((1, size, size, 17), dtype=np.float32)
        player = 1
        board[:, :, :, -1] = player

        for i in range(size * size):
            x, y = index2coord(i)
            if (x, y) in [(5, 6), (6, 6), (6, 8), (7, 8), (8, 8)]:
                make_play(x, y, board)  # black
                make_play(0, size, board)  # white pass
            elif (x, y) in [(6, 7)]:
                make_play(0, size, board)  # black pass
                make_play(0, size, board)  # white pass
            else:
                make_play(0, size, board)  # black pass
                make_play(x, y, board)  # white

        make_play(0, size, board)  # black pass
        make_play(6, 7, board)  # white

        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● . . ● ●
        # ● ● ● ● ● ● ● ● ●
        # ● ● ● ● ● ● . . .
        for i in range(size * size - 1):
            x, y = index2coord(i)
            if (x, y) in [(5, 6), (6, 6), (6, 8), (7, 8), (8, 8)]:
                self.assertEqual(board[0][y][x][0], 0)  # empty
                self.assertEqual(board[0][y][x][1], 0)  # emtpy
            else:
                self.assertEqual(board[0][y][x][0], 0)  # white
                self.assertEqual(board[0][y][x][1], 1)  # white
Exemplo n.º 2
0
    def test_legal_moves_not_ko(self):
        board = np.zeros((1, 19, 19, 17), dtype=np.float32)
        player = 1
        board[:, :, :, -1] = player

        make_play(0, 0, board)  # black
        make_play(1, 0, board)  # white
        make_play(1, 1, board)  # black
        make_play(2, 0, board)  # white
        make_play(2, 1, board)  # black
        make_play(8, 8, board)  # white random pos
        # ○ ● ● . . .
        # . ○ ○ . . .
        # . . . . . .
        make_play(3, 0, board)  # black captures_first
        # ○ . . ○ . .
        # . ○ ○ . . .
        # . . . . . .
        mask = legal_moves(board)
        self.assertEqual(board[0][0][1][0], 0)  # white stone 1
        self.assertEqual(board[0][0][1][1], 0)  # was taken
        self.assertEqual(board[0][0][2][0], 0)  # white stone 2
        self.assertEqual(board[0][0][2][1], 0)  # was taken
        self.assertEqual(board[0][0][1][2], 1)  # white stone 1 was here
        self.assertEqual(board[0][0][1][3], 0)  # black stone was not here
        self.assertEqual(board[0][0][2][2], 1)  # white stone 2 was here
        self.assertEqual(board[0][0][2][3], 0)  # black stone was not here
        self.assertEqual(mask[1], False)
        self.assertEqual(mask[2], False)
Exemplo n.º 3
0
    def test_full_board_capture(self):
        size = conf['SIZE']
        board = np.zeros((1, size, size, 17), dtype=np.float32)
        player = 1
        board[:, :, :, -1] = player

        for i in range(size * size - 2):
            x, y = index2coord(i)
            make_play(x, y, board)  # black
            make_play(0, size, board)  # white pass

        # ○ ○ ○ ○ ○ ○
        # ○ ○ ○ ○ ○ ○
        # ○ ○ ○ ○ ○ ○
        # ○ ○ ○ ○ . .
        make_play(0, size, board)  # black pass
        make_play(size - 1, size - 1, board)  # white corner
        # ○ ○ ○ ○ ○ ○
        # ○ ○ ○ ○ ○ ○
        # ○ ○ ○ ○ ○ ○
        # ○ ○ ○ ○ . ●

        for i in range(size * size - 2):
            x, y = index2coord(i)
            self.assertEqual(board[0][y][x][0], 1)  # black stone i
            self.assertEqual(board[0][y][x][1], 0)  # black stone i

        self.assertEqual(board[0][size - 1][size - 1][0], 0)  # white stone
        self.assertEqual(board[0][size - 1][size - 1][1], 1)  # white stone
        self.assertEqual(board[0][size - 1][size - 2][0], 0)  # empty
        self.assertEqual(board[0][size - 1][size - 2][1], 0)  # empty

        make_play(size - 2, size - 1, board)  # black
        # ○ ○ ○ ○ ○ ○
        # ○ ○ ○ ○ ○ ○
        # ○ ○ ○ ○ ○ ○
        # ○ ○ ○ ○ ○ .
        for i in range(size * size - 1):
            x, y = index2coord(i)
            self.assertEqual(board[0][y][x][0], 0)  # black stone i
            self.assertEqual(board[0][y][x][1],
                             1)  # black stone i (it's white's turn)
        self.assertEqual(board[0][size - 1][size - 1][0], 0)  # empty
        self.assertEqual(board[0][size - 1][size - 1][1], 0)  # empty

        make_play(size - 1, size - 1, board)  # white
        # . . . . . .
        # . . . . . .
        # . . . . . .
        # . . . . . ●
        for i in range(size * size - 1):
            x, y = index2coord(i)
            self.assertEqual(board[0][y][x][0], 0)  # empty
            self.assertEqual(board[0][y][x][1], 0)  # empty
        self.assertEqual(board[0][size - 1][size - 1][0], 0)  # white
        self.assertEqual(board[0][size - 1][size - 1][1], 1)  # white
Exemplo n.º 4
0
    def test_self_sucide(self):
        board = np.zeros((1, 19, 19, 17), dtype=np.float32)
        player = 1
        board[:, :, :, -1] = player

        make_play(0, 0, board)  # black
        make_play(1, 0, board)  # white
        make_play(8, 9, board)  # black random
        make_play(2, 1, board)  # white
        make_play(8, 8, board)  # black random pos
        make_play(3, 0, board)  # white
        # ○ ● . ● . .
        # . . ● . . .
        # . . . . . .
        make_play(2, 0, board)  # black sucides
        self.assertEqual(board[0][0][1][0], 1)  # white stone
        self.assertEqual(board[0][0][1][1], 0)  # was not taken

        self.assertEqual(board[0][0][2][0], 0)  # black stone
        self.assertEqual(board[0][0][2][1], 0)  # was taken