示例#1
0
文件: processor.py 项目: ntwuxc/dlgo
    def get_handicap(sgf):
        """
        sgfファイルの初期ハンディキャップを適用した盤を返す

        Parameters
        ----------
        sgf : str
            sgfの棋譜データコンテンツ
        
        Returns
        -------
        game_state : GameState
            ハンディキャップ適用後の盤
        first_move_done : bool
            ハンディキャップ適用があったか(盤面が空でないか)
        """
        go_board = Board(19, 19)
        first_move_done = False
        move = None
        game_state = GameState.new_game(19)
        if sgf.get_handicap() != 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
示例#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)
示例#3
0
 def get_handicap(self, sgf):
     go_board = Board(19, 19)
     first_move_done = False
     game_state = GameState.new_game(19)
     if sgf.get_handicap() != 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
示例#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)
示例#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)))
示例#6
0
    def game(self) -> GameState:
        if not self._game:
            black = batch_translate_labels_to_coordinates(self.initial_black)
            white = batch_translate_labels_to_coordinates(self.initial_white)
            move_points = batch_translate_labels_to_coordinates(self.moves)
            player = Player.black if self.initial_player == 'b' else Player.white

            board = Board(19, 19)
            for b in black:
                board.place_stone(Player.black, b)
            for w in white:
                board.place_stone(Player.white, w)

            self._game = GameState(board, player, None, None)
            for move_point in move_points:
                move = Move.pass_turn() if not move_point else Move.play(
                    move_point)
                self._game = self._game.apply_move(move)

        return self._game
示例#7
0
    def test_not_self_capture_is_other_capture(self):
        # xx...
        # oox..
        # x.o..
        board = Board(5, 5)
        board.place_stone(Player.black, Point(3, 1))
        board.place_stone(Player.black, Point(3, 2))
        board.place_stone(Player.black, Point(2, 3))
        board.place_stone(Player.black, Point(1, 1))
        board.place_stone(Player.white, Point(2, 1))
        board.place_stone(Player.white, Point(2, 2))
        board.place_stone(Player.white, Point(1, 3))

        self.assertFalse(board.is_self_capture(Player.black, Point(1, 2)))
示例#8
0
    def get_handicap(sgf):  # Get handicap stones
        go_board = Board(19, 19)

        first_move_done = False
        move = None
        game_state = GameState.new_game(19)
        board_ext = Board_Ext(game_state.board)
        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))  # black gets handicap
                    #My inserting Nail
                    point = Point(row + 1, col + 1)
                    ret = board_ext.place_stone_ext(
                        go_board, 'b', point)  # Handicap for black Player
                    #### Nail

            first_move_done = True
            game_state = GameState(go_board, Player.white, None, move)
        return game_state, first_move_done, board_ext
示例#9
0
    def test_not_self_capture(self):
        # o.o..
        # x.xo.
        board = Board(5, 5)
        board.place_stone(Player.black, Point(1, 1))
        board.place_stone(Player.black, Point(1, 3))
        board.place_stone(Player.white, Point(2, 1))
        board.place_stone(Player.white, Point(2, 3))
        board.place_stone(Player.white, Point(1, 4))

        self.assertFalse(board.is_self_capture(Player.black, Point(1, 2)))
示例#10
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)