當前位置: 首頁>>代碼示例>>Python>>正文


Python go.IllegalMove方法代碼示例

本文整理匯總了Python中go.IllegalMove方法的典型用法代碼示例。如果您正苦於以下問題:Python go.IllegalMove方法的具體用法?Python go.IllegalMove怎麽用?Python go.IllegalMove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在go的用法示例。


在下文中一共展示了go.IllegalMove方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: play_move

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def play_move(self, c):
        '''
        Notable side effects:
          - finalizes the probability distribution according to
          this roots visit counts into the class' running tally, `searches_pi`
          - Makes the node associated with this move the root, for future
            `inject_noise` calls.
        '''
        if not self.two_player_mode:
            self.searches_pi.append(
                self.root.children_as_pi(self.root.position.n < self.temp_threshold))
        self.qs.append(self.root.Q)  # Save our resulting Q.
        self.comments.append(self.root.describe())
        try:
            self.root = self.root.maybe_add_child(coords.to_flat(c))
        except go.IllegalMove:
            print("Illegal move")
            if not self.two_player_mode:
                self.searches_pi.pop()
            self.qs.pop()
            self.comments.pop()
            return False
        self.position = self.root.position  # for showboard
        del self.root.parent.children
        return True  # GTP requires positive result. 
開發者ID:mlperf,項目名稱:training_results_v0.5,代碼行數:27,代碼來源:strategies.py

示例2: play_move

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def play_move(self, c):
        """Notable side effects:
          - finalizes the probability distribution according to
          this roots visit counts into the class' running tally, `searches_pi`
          - Makes the node associated with this move the root, for future
            `inject_noise` calls.
        """
        if not self.two_player_mode:
            self.searches_pi.append(self.root.children_as_pi(
                self.root.position.n < self.temp_threshold))
        self.comments.append(self.root.describe())
        try:
            self.root = self.root.maybe_add_child(coords.to_flat(c))
        except go.IllegalMove:
            dbg("Illegal move")
            if not self.two_player_mode:
                self.searches_pi.pop()
            self.comments.pop()
            raise

        self.position = self.root.position  # for showboard
        del self.root.parent.children
        return True  # GTP requires positive result. 
開發者ID:mlperf,項目名稱:training,代碼行數:25,代碼來源:strategies.py

示例3: make_move

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def make_move(self, color, vertex):
        coords = utils.parse_pygtp_coords(vertex)
        self.accomodate_out_of_turn(color)
        try:
            self.position = self.position.play_move(coords, color=translate_gtp_colors(color))
        except go.IllegalMove:
            return False
        return True 
開發者ID:llSourcell,項目名稱:alphago_demo,代碼行數:10,代碼來源:gtp_wrapper.py

示例4: play_valid_move

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def play_valid_move(self, position, move_probs):
        for move in sorted_moves(move_probs):
            if go.is_eyeish(position.board, move):
                continue
            try:
                candidate_pos = position.play_move(move, mutate=True)
            except go.IllegalMove:
                continue
            else:
                return candidate_pos
        return position.pass_move(mutate=True) 
開發者ID:brilee,項目名稱:MuGo,代碼行數:13,代碼來源:strategies.py

示例5: test_ko_move

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def test_ko_move(self):
        start_board = test_utils.load_board('''
            .OX......
            OX.......
        ''' + EMPTY_ROW * 7)
        start_position = Position(
            board=start_board,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=None,
            recent=tuple(),
            to_play=BLACK,
        )
        expected_board = test_utils.load_board('''
            X.X......
            OX.......
        ''' + EMPTY_ROW * 7)
        expected_position = Position(
            board=expected_board,
            n=1,
            komi=6.5,
            caps=(2, 2),
            ko=coords.from_kgs('B9'),
            recent=(PlayerMove(BLACK, coords.from_kgs('A9')),),
            to_play=WHITE,
        )
        actual_position = start_position.play_move(coords.from_kgs('A9'))

        self.assertEqualPositions(actual_position, expected_position)

        # Check that retaking ko is illegal until two intervening moves
        with self.assertRaises(go.IllegalMove):
            actual_position.play_move(coords.from_kgs('B9'))
        pass_twice = actual_position.pass_move().pass_move()
        ko_delayed_retake = pass_twice.play_move(coords.from_kgs('B9'))
        expected_position = Position(
            board=start_board,
            n=4,
            komi=6.5,
            caps=(2, 3),
            ko=coords.from_kgs('A9'),
            recent=(
                PlayerMove(BLACK, coords.from_kgs('A9')),
                PlayerMove(WHITE, None),
                PlayerMove(BLACK, None),
                PlayerMove(WHITE, coords.from_kgs('B9'))),
            to_play=BLACK,
        )
        self.assertEqualPositions(ko_delayed_retake, expected_position) 
開發者ID:mlperf,項目名稱:training_results_v0.5,代碼行數:52,代碼來源:test_go.py

示例6: test_legal_moves

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def test_legal_moves(self):
        board = load_board('''
            .XXXXXXXO
            XX.OOOOO.
            OOOOOOOOO
            XXXXXXXX.
            OOOOOOOOO
            XXXXXXXXX
            XXXXXXXXX
            XXXXXXXXX
            XXXXXXXX.
        ''')
        position = Position(
            board=board,
            n=0,
            komi=6.5,
            caps=(0, 0),
            ko=pc('J8'),
            recent=tuple(),
            to_play=BLACK,
        )
        empty_spots = pc_set('A9 C8 J8 J6 J1')
        B_legal_moves = pc_set('A9 C8 J6')
        for move in empty_spots:
            if move not in B_legal_moves:
                with self.assertRaises(go.IllegalMove):
                    position.play_move(move)
            else:
                position.play_move(move)
        # pass should also be legal
        position.play_move(None)

        pass_position = position.pass_move()
        W_legal_moves = pc_set('C8 J8 J6 J1')
        for move in empty_spots:
            if move not in W_legal_moves:
                with self.assertRaises(go.IllegalMove):
                    pass_position.play_move(move)
            else:
                pass_position.play_move(move)
        # pass should also be legal
        pass_position.play_move(None) 
開發者ID:llSourcell,項目名稱:alphago_demo,代碼行數:44,代碼來源:test_go.py

示例7: test_ko_move

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def test_ko_move(self):
        start_board = load_board('''
            .OX......
            OX.......
        ''' + EMPTY_ROW * 7)
        start_position = Position(
            board=start_board,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=None,
            recent=tuple(),
            to_play=BLACK,
        )
        expected_board = load_board('''
            X.X......
            OX.......
        ''' + EMPTY_ROW * 7)
        expected_position = Position(
            board=expected_board,
            n=1,
            komi=6.5,
            caps=(2, 2),
            ko=pc('B9'),
            recent=(PlayerMove(BLACK, pc('A9')),),
            to_play=WHITE,
        )
        actual_position = start_position.play_move(pc('A9'))

        self.assertEqualPositions(actual_position, expected_position)

        # Check that retaking ko is illegal until two intervening moves
        with self.assertRaises(go.IllegalMove):
            actual_position.play_move(pc('B9'))
        pass_twice = actual_position.pass_move().pass_move()
        ko_delayed_retake = pass_twice.play_move(pc('B9'))
        expected_position = Position(
            board=start_board,
            n=4,
            komi=6.5,
            caps=(2, 3),
            ko=pc('A9'),
            recent=(
                PlayerMove(BLACK, pc('A9')),
                PlayerMove(WHITE, None),
                PlayerMove(BLACK, None),
                PlayerMove(WHITE, pc('B9'))),
            to_play=BLACK,
        )
        self.assertEqualPositions(ko_delayed_retake, expected_position) 
開發者ID:llSourcell,項目名稱:alphago_demo,代碼行數:52,代碼來源:test_go.py

示例8: test_ko_move_mutable_board

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def test_ko_move_mutable_board(self):
        start_board = load_board('''
            .OX......
            OX.......
        ''' + EMPTY_ROW * 7)
        start_position = Position(
            board=start_board,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=None,
            recent=tuple(),
            to_play=BLACK,
        )
        expected_board = load_board('''
            X.X......
            OX.......
        ''' + EMPTY_ROW * 7)
        expected_position = Position(
            board=expected_board,
            n=1,
            komi=6.5,
            caps=(2, 2),
            ko=pc('B9'),
            recent=(PlayerMove(BLACK, pc('A9')),),
            to_play=WHITE,
        )
        actual_position = start_position.play_move(pc('A9'), mutate=True)

        self.assertEqualPositions(actual_position, expected_position)

        # Check that retaking ko is illegal until two intervening moves
        with self.assertRaises(go.IllegalMove):
            actual_position.play_move(pc('B9'), mutate=True)
        pass_twice = actual_position.pass_move(mutate=True).pass_move(mutate=True)
        ko_delayed_retake = pass_twice.play_move(pc('B9'), mutate=True)
        expected_position = Position(
            board=start_board,
            n=4,
            komi=6.5,
            caps=(2, 3),
            ko=pc('A9'),
            recent=(
                PlayerMove(BLACK, pc('A9')),
                PlayerMove(WHITE, None),
                PlayerMove(BLACK, None),
                PlayerMove(WHITE, pc('B9'))),
            to_play=BLACK,
        )
        self.assertEqualPositions(ko_delayed_retake, expected_position) 
開發者ID:llSourcell,項目名稱:alphago_demo,代碼行數:52,代碼來源:test_go.py

示例9: test_ko_move

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def test_ko_move(self):
    start_board = utils_test.load_board('''
      .OX......
      OX.......
    ''' + EMPTY_ROW * 7)
    start_position = Position(
        utils_test.BOARD_SIZE,
        board=start_board,
        n=0,
        komi=6.5,
        caps=(1, 2),
        ko=None,
        recent=tuple(),
        to_play=BLACK,
        )
    expected_board = utils_test.load_board('''
      X.X......
      OX.......
    ''' + EMPTY_ROW * 7)
    expected_position = Position(
        utils_test.BOARD_SIZE,
        board=expected_board,
        n=1,
        komi=6.5,
        caps=(2, 2),
        ko=coords.from_kgs(utils_test.BOARD_SIZE, 'B9'),
        recent=(PlayerMove(BLACK, coords.from_kgs(
            utils_test.BOARD_SIZE, 'A9')),),
        to_play=WHITE,
        )
    actual_position = start_position.play_move(coords.from_kgs(
        utils_test.BOARD_SIZE, 'A9'))

    self.assertEqualPositions(actual_position, expected_position)

    # Check that retaking ko is illegal until two intervening moves
    with self.assertRaises(go.IllegalMove):
      actual_position.play_move(coords.from_kgs(utils_test.BOARD_SIZE, 'B9'))
    pass_twice = actual_position.pass_move().pass_move()
    ko_delayed_retake = pass_twice.play_move(coords.from_kgs(
        utils_test.BOARD_SIZE, 'B9'))
    expected_position = Position(
        utils_test.BOARD_SIZE,
        board=start_board,
        n=4,
        komi=6.5,
        caps=(2, 3),
        ko=coords.from_kgs(utils_test.BOARD_SIZE, 'A9'),
        recent=(
            PlayerMove(BLACK, coords.from_kgs(utils_test.BOARD_SIZE, 'A9')),
            PlayerMove(WHITE, None),
            PlayerMove(BLACK, None),
            PlayerMove(WHITE, coords.from_kgs(utils_test.BOARD_SIZE, 'B9')),),
        to_play=BLACK)
    self.assertEqualPositions(ko_delayed_retake, expected_position) 
開發者ID:itsamitgoel,項目名稱:Gun-Detector,代碼行數:57,代碼來源:go_test.py

示例10: test_ko_move

# 需要導入模塊: import go [as 別名]
# 或者: from go import IllegalMove [as 別名]
def test_ko_move(self):
        start_board = test_utils.load_board('''
            .OX......
            OX.......
        ''' + EMPTY_ROW * 7)
        start_position = Position(
            board=start_board,
            n=0,
            komi=6.5,
            caps=(1, 2),
            ko=None,
            recent=tuple(),
            to_play=BLACK,
        )
        expected_board = test_utils.load_board('''
            X.X......
            OX.......
        ''' + EMPTY_ROW * 7)
        expected_position = Position(
            board=expected_board,
            n=1,
            komi=6.5,
            caps=(2, 2),
            ko=coords.from_gtp('B9'),
            recent=(PlayerMove(BLACK, coords.from_gtp('A9')),),
            to_play=WHITE,
        )
        actual_position = start_position.play_move(coords.from_gtp('A9'))

        self.assertEqualPositions(actual_position, expected_position)

        # Check that retaking ko is illegal until two intervening moves
        with self.assertRaises(go.IllegalMove):
            actual_position.play_move(coords.from_gtp('B9'))
        pass_twice = actual_position.pass_move().pass_move()
        ko_delayed_retake = pass_twice.play_move(coords.from_gtp('B9'))
        expected_position = Position(
            board=start_board,
            n=4,
            komi=6.5,
            caps=(2, 3),
            ko=coords.from_gtp('A9'),
            recent=(
                PlayerMove(BLACK, coords.from_gtp('A9')),
                PlayerMove(WHITE, None),
                PlayerMove(BLACK, None),
                PlayerMove(WHITE, coords.from_gtp('B9'))),
            to_play=BLACK,
        )
        self.assertEqualPositions(ko_delayed_retake, expected_position) 
開發者ID:mlperf,項目名稱:training,代碼行數:52,代碼來源:test_go.py


注:本文中的go.IllegalMove方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。