Example #1
0
 def test_capture_is_not_suicide(self):
     board = Board(19)
     board.place_stone(Player.black, Point(1, 1))
     board.place_stone(Player.black, Point(2, 2))
     board.place_stone(Player.black, Point(1, 3))
     board.place_stone(Player.white, Point(2, 1))
     board.place_stone(Player.white, Point(1, 2))
     self.assertIsNone(board.get(Point(1, 1)))
     self.assertEqual(Player.white, board.get(Point(2, 1)))
     self.assertEqual(Player.white, board.get(Point(1, 2)))
Example #2
0
 def get_handicap(sgf):
     go_board = Board(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
Example #3
0
def new_game_from_handicap(sgf):
    board = Board(19)
    first_move_done = False
    move = None
    gs = GameState.new_game(19)
    if sgf.get_handicap() is not None and sgf.get_handicap() != 0:
        print('Handicap detected')
        for setup in sgf.get_root().get_setup_stones():
            for move in setup:
                row, col = move
                board.place_stone(Player.black, Point(row + 1, col + 1))
            first_move_done = True
            gs = GameState(board, Player.white, None, move)
    return gs, first_move_done
Example #4
0
 def test_remove_liberties(self):
     board = Board(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)
Example #5
0
    def test_empty_triangle(self):
        board = Board(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)
Example #6
0
 def test_scoring(self):
     # .w.ww
     # wwww.
     # bbbww
     # .bbbb
     # .b.b.
     board = Board(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))
     scorer = AreaScore(board)
     self.assertEqual(Player.white, scorer.winner())
     self.assertEqual(9, scorer.bp)
     self.assertEqual(4, scorer.bt)
     self.assertEqual(9, scorer.wp)
     self.assertEqual(3, scorer.wt)
     self.assertEqual(0, scorer.dames)
Example #7
0
 def test_capture_two_stones(self):
     board = Board(19)
     board.place_stone(Player.black, Point(2, 2))
     board.place_stone(Player.black, Point(2, 3))
     board.place_stone(Player.white, Point(1, 2))
     board.place_stone(Player.white, Point(1, 3))
     self.assertEqual(Player.black, board.get(Point(2, 2)))
     self.assertEqual(Player.black, board.get(Point(2, 3)))
     board.place_stone(Player.white, Point(3, 2))
     board.place_stone(Player.white, Point(3, 3))
     self.assertEqual(Player.black, board.get(Point(2, 2)))
     self.assertEqual(Player.black, board.get(Point(2, 3)))
     board.place_stone(Player.white, Point(2, 1))
     board.place_stone(Player.white, Point(2, 4))
     self.assertIsNone(board.get(Point(2, 2)))
     self.assertIsNone(board.get(Point(2, 3)))