Ejemplo n.º 1
0
 def test_corner(self):
     board = Board(19, 19)
     board.place_stone(Player.black, Point(1, 2))
     board.place_stone(Player.black, Point(2, 2))
     board.place_stone(Player.black, Point(2, 1))
     self.assertTrue(is_point_an_eye(board, Point(1, 1), Player.black))
     self.assertFalse(is_point_an_eye(board, Point(1, 1), Player.white))
Ejemplo n.º 2
0
    def test_empty_triangle(self):
        board = Board(5, 5)
        board.place_stone(Player.black, Point(1, 1))
        board.place_stone(Player.black, Point(1, 2))
        board.place_stone(Player.black, Point(2, 2))
        board.place_stone(Player.white, Point(2, 1))

        black_string = board.get_go_string(Point(1, 1))
        six.assertCountEqual(
            self,
            [Point(3, 2), Point(2, 3), Point(1, 3)], black_string.liberties)
Ejemplo n.º 3
0
 def get_handicap(sgf):
     go_board = Board(19, 19)
     first_move_done = False
     move = None
     game_state = GameState.new_game(19)
     if sgf.get_handicap() is not None and sgf.get_handicap() != 0:
         for setup in sgf.get_root().get_setup_stones():
             for move in setup:
                 row, col = move
                 go_board.place_stone(Player.black, Point(row + 1, col + 1))
         first_move_done = True
         game_state = GameState(go_board, Player.white, None, move)
     return game_state, first_move_done
Ejemplo n.º 4
0
 def test_remove_liberties(self):
     board = Board(5, 5)
     board.place_stone(Player.black, Point(3, 3))
     board.place_stone(Player.white, Point(2, 2))
     white_string = board.get_go_string(Point(2, 2))
     six.assertCountEqual(
         self,
         [Point(2, 3), Point(2, 1),
          Point(1, 2), Point(3, 2)], white_string.liberties)
     board.place_stone(Player.black, Point(3, 2))
     white_string = board.get_go_string(Point(2, 2))
     six.assertCountEqual(
         self,
         [Point(2, 3), Point(2, 1), Point(1, 2)], white_string.liberties)
Ejemplo n.º 5
0
 def test_capture(self):
     board = Board(19, 19)
     board.place_stone(Player.black, Point(2, 2))
     board.place_stone(Player.white, Point(1, 2))
     self.assertEqual(Player.black, board.get(Point(2, 2)))
     board.place_stone(Player.white, Point(2, 1))
     self.assertEqual(Player.black, board.get(Point(2, 2)))
     board.place_stone(Player.white, Point(2, 3))
     self.assertEqual(Player.black, board.get(Point(2, 2)))
     board.place_stone(Player.white, Point(3, 2))
     self.assertIsNone(board.get(Point(2, 2)))
Ejemplo n.º 6
0
 def test_middle(self):
     board = Board(19, 19)
     board.place_stone(Player.black, Point(2, 2))
     board.place_stone(Player.black, Point(3, 2))
     board.place_stone(Player.black, Point(4, 2))
     board.place_stone(Player.black, Point(4, 3))
     board.place_stone(Player.white, Point(4, 4))
     board.place_stone(Player.black, Point(3, 4))
     board.place_stone(Player.black, Point(2, 4))
     board.place_stone(Player.black, Point(2, 3))
     self.assertTrue(is_point_an_eye(board, Point(3, 3), Player.black))
Ejemplo n.º 7
0
 def test_scoring(self):
     # .w.ww
     # wwww.
     # bbbww
     # .bbbb
     # .b.b.
     board = Board(5, 5)
     board.place_stone(Player.black, Point(1, 2))
     board.place_stone(Player.black, Point(1, 4))
     board.place_stone(Player.black, Point(2, 2))
     board.place_stone(Player.black, Point(2, 3))
     board.place_stone(Player.black, Point(2, 4))
     board.place_stone(Player.black, Point(2, 5))
     board.place_stone(Player.black, Point(3, 1))
     board.place_stone(Player.black, Point(3, 2))
     board.place_stone(Player.black, Point(3, 3))
     board.place_stone(Player.white, Point(3, 4))
     board.place_stone(Player.white, Point(3, 5))
     board.place_stone(Player.white, Point(4, 1))
     board.place_stone(Player.white, Point(4, 2))
     board.place_stone(Player.white, Point(4, 3))
     board.place_stone(Player.white, Point(4, 4))
     board.place_stone(Player.white, Point(5, 2))
     board.place_stone(Player.white, Point(5, 4))
     board.place_stone(Player.white, Point(5, 5))
     territory = scoring.evaluate_territory(board)
     self.assertEqual(9, territory.num_black_stones)
     self.assertEqual(4, territory.num_black_territory)
     self.assertEqual(9, territory.num_white_stones)
     self.assertEqual(3, territory.num_white_territory)
     self.assertEqual(0, territory.num_dame)