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


Python Piece.is_klass_color方法代码示例

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


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

示例1: get_theoretical_ep_right

# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import is_klass_color [as 别名]
    def get_theoretical_ep_right(self, x):
        """Checks if a player could have an ep-move in theory from
        looking just at the piece positions.

        :param file:
            The file to check as a letter between `"a"` and `"h"`.

        :return:
            A boolean indicating whether the player could theoretically
            have that en-passant move.

        """
        if x < 0 or x > 7:
            raise ValueError(x)

        '''
        3 states of en-passant
        p.  pP  ..
        ..  ..  .p
        .P  ..  ..
        '''

        # Check there is a pawn on the right rank for e.p.
        y = 3 if self.fen._to_move == WHITE else 4
        x88 = X88.from_x_and_y(x, y) 

        piece = self._pieces[x88]
        if not piece:
            return False

        # If the square is not an opposite colored pawn then its not possible.
        ocolor = Piece.opposite_color(self.fen._to_move)
        if not Piece.is_klass_and_color(piece, PAWN, ocolor):
            return False

        # If the square below the pawn is not empty then it not possible.
        y = 2 if self.turn == WHITE else 5
        x88 = X88.from_x_and_y(x, y) 
        if self[x88]:
            return False

        # If there is not pawn of opposite color on a neighboring file then its not possible.
        xs = [_x for _x in range(8) if _x>=0 and  _x<8 and abs(x-_x) == 1]
        for _x in xs:
            x88 = X88.from_x_and_y(_x, y) 
            piece = self._pieces[x88] 
            if Piece.is_klass_color(piece, PAWN, Piece.opposite_color(self.fen._to_move)):
                return True
        # Else its just not possible.
        return False
开发者ID:nate1001,项目名称:python-chess,代码行数:52,代码来源:position.py


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