当前位置: 首页>>代码示例>>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;未经允许,请勿转载。