def test_is_point_an_eye(self):
        test_grid = np.array([[0, 1, 2, 0, 2], [1, 1, 2, 2,
                                                2], [0, 1, 1, 0, 0],
                              [0, 1, 0, 1, 0], [0, 1, 1, 1, 0]])
        test_board = godomain.GoBoard(5, 5, 0)
        test_board.grid = test_grid
        assert gohelper.is_point_an_eye(test_board, gohelper.Point(0, 0),
                                        gohelper.Player.black) == True

        assert gohelper.is_point_an_eye(test_board, gohelper.Point(3, 2),
                                        gohelper.Player.black) == True

        test_grid = np.array([[0, 1, 2, 0, 2], [1, 0, 2, 2,
                                                0], [0, 1, 1, 0, 0],
                              [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]])
        test_board = godomain.GoBoard(5, 5, 0)
        test_board.grid = test_grid
        assert gohelper.is_point_an_eye(test_board, gohelper.Point(3, 2),
                                        gohelper.Player.black) == False
        assert gohelper.is_point_an_eye(test_board, gohelper.Point(0, 0),
                                        gohelper.Player.black) == False
        assert gohelper.is_point_an_eye(test_board, gohelper.Point(0, 3),
                                        gohelper.Player.white) == False

        test_grid = np.array([[0, 1, 2, 0, 2], [0, 1, 1, 0,
                                                2], [0, 1, 0, 1, 0],
                              [0, 0, 1, 1, 0], [0, 0, 1, 0, 0]])
        test_board = godomain.GoBoard(5, 5, 0)
        test_board.grid = test_grid
        assert gohelper.is_point_an_eye(test_board, gohelper.Point(2, 2),
                                        gohelper.Player.black) == True

        test_grid = np.array([[0, 1, 2, 0, 2], [0, 0, 1, 1,
                                                2], [0, 1, 0, 1, 0],
                              [0, 1, 1, 0, 0], [0, 0, 1, 0, 0]])
        test_board = godomain.GoBoard(5, 5, 0)
        test_board.grid = test_grid
        assert gohelper.is_point_an_eye(test_board, gohelper.Point(2, 2),
                                        gohelper.Player.black) == True

        test_grid = np.array([[0, 1, 2, 0, 2], [1, 1, 2, 2,
                                                2], [0, 2, 2, 0, 0],
                              [0, 2, 0, 2, 0], [0, 0, 2, 2, 0]])
        test_board = godomain.GoBoard(5, 5, 0)
        test_board.grid = test_grid
        assert gohelper.is_point_an_eye(test_board, gohelper.Point(3, 2),
                                        gohelper.Player.white) == True
 def test_find_connected(self):
     test_grid = np.array([[0, 1, 2, 0, 2], [1, 1, 2, 2,
                                             2], [0, 1, 1, 0, 0],
                           [0, 1, 0, 1, 0], [0, 1, 1, 1, 0]])
     test_board = godomain.GoBoard(5, 5, 0)
     test_board.grid = test_grid
     assert len(
         gohelper.find_connected(test_board, gohelper.Point(1, 0),
                                 gohelper.Player.black)[0]) == 10
Exemple #3
0
    def test_is_suicide(self) :

        boards =  [godomain.GoBoard(5,5,0) for i in range(6)]
        boards[0].grid = np.zeros((5,5))
        boards[1].grid = np.array([
            [0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ])
        boards[2].grid = np.array([
            [0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0],
            [1, 0, 1, 0, 0],
            [0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ])
        boards[3].grid = np.array([
            [0, 1, 0, 0, 0],
            [1, 1, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ])
        boards[4].grid = np.array([
            [0, 2, 0, 0, 0],
            [2, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ])
        boards[5].grid = np.array([
            [0, 2, 0, 0, 0],
            [2, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0]
        ])

        states = [godomain.GameState(boards[0],1,None,None)]
        player = godomain.Player.black
        for i in range(1,5) :
            state = godomain.GameState(boards[i],player.opp,states[i-1],None)
            states.append(state)
        move = godomain.Move(gohelper.Point(row=2,col=1))
        assert states[1].is_suicide(godomain.Player.white, godomain.Move(gohelper.Point(row=2, col=1))) == False
        assert states[2].is_suicide(godomain.Player.white, godomain.Move(gohelper.Point(row=2, col=1))) == True
        assert states[3].is_suicide(godomain.Player.white, godomain.Move(gohelper.Point(row=0, col=0))) == True
        assert states[4].is_suicide(godomain.Player.black, godomain.Move(gohelper.Point(row=0, col=0))) == True
        assert states[4].is_suicide(godomain.Player.white, godomain.Move(gohelper.Point(row=0, col=0))) == False
Exemple #4
0
 def test_remove_dead_stones(self):
     board = godomain.GoBoard(5, 5, 0)
     board.grid= np.array([
         [1, 0, 2, 0, 0],
         [2, 2, 0, 0, 0],
         [0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0]
         ])
     gs = godomain.GameState(board, godomain.Player.black, None, None)
     move = godomain.Move(gohelper.Point(row=0, col=1))
     assert gs.is_suicide(godomain.Player.black, move) == True
     with pytest.raises(ValueError):
         gs = gs.apply_move(move)
         gs.board.display_board()