当前位置: 首页>>代码示例>>Python>>正文


Python Position.board方法代码示例

本文整理汇总了Python中position.Position.board方法的典型用法代码示例。如果您正苦于以下问题:Python Position.board方法的具体用法?Python Position.board怎么用?Python Position.board使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在position.Position的用法示例。


在下文中一共展示了Position.board方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: from_fen

# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import board [as 别名]
    def from_fen(cls, fen_str):
        # Separate the 6 components
        board_str, active_colour_str, castling_str, en_passant_str,\
           half_move_str, full_move_str = fen_str.strip().split(' ')

        position = Position()

        # Construct the board
        board = tuple()
        for rank_str in board_str.split('/'):
            rank = tuple()
            for piece_str in rank_str:
                if piece_str in '12345678':
                    # Blanks
                    rank += (None,) * int(piece_str)
                else:
                    # Piece
                    piece_colour = WHITE if piece_str.isupper() else BLACK
                    rank += (cls.mappings[piece_str.upper()](piece_colour),)
            board = (rank,) + board

        # Rest of Properties
        position.board = board
        position.active_colour = WHITE if active_colour_str=='w' else BLACK
        position.castling = '' if castling_str is '-' else castling_str
        position.en_passant = None if en_passant_str=='-' else get_coord_from_rank_file(en_passant_str)
        position.half_move = int(half_move_str)
        position.full_move = int(full_move_str)

        return position
开发者ID:js837,项目名称:chess,代码行数:32,代码来源:serializers.py

示例2: new_game

# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import board [as 别名]
def new_game(board_str = None):
    """Creates a new game based on text representation"""
    mappings = {'R': Rook, 'N': Knight, 'B': Bishop, 'Q': Queen, 'K': King, 'P': Pawn}

    position = Position()
    if board_str is None:
        # White plays North
        board_str = (' rnbqkbnr\n' #8
                     ' pppppppp\n' #7
                     ' ........\n' #6
                     ' ........\n' #5
                     ' ........\n' #4
                     ' ........\n' #3
                     ' PPPPPPPP\n' #2
                     ' RNBQKBNR')  #1
                     # abcdefgh

    # Permute the board so that Top left become bottom left
    board_str = board_str.replace(' ', '').replace('\n','')
    ranks = reversed([board_str[i:i+8] for i in range(0, 64, 8)])
    board_str = ''.join(ranks)

    board = ()
    rank = ()
    for piece in board_str:
        if piece == '.':
            rank += (None,)
        elif piece.isupper():
            rank += (mappings[piece.upper()](WHITE), )
        elif piece.islower():
            rank += (mappings[piece.upper()](BLACK), )
        if len(rank) == 8:
            board += (rank,)
            rank = ()

    position.board=board
    return position
开发者ID:js837,项目名称:chess,代码行数:39,代码来源:helpers.py


注:本文中的position.Position.board方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。