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


Python Piece.is_klass_and_color方法代码示例

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


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

示例1: get_theoretical_ep_right

# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import is_klass_and_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.fen.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_and_color(piece, PAWN, Piece.opposite_color(self.fen._to_move)):
                return True
        # Else its just not possible.
        return False
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:52,代码来源:position.py

示例2: get_king

# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import is_klass_and_color [as 别名]
    def get_king(self, color):
        """Gets the square of the king.

        :param color:
            `"w"` for the white players king. `"b"` for the black
            players king.

        :return:
            The first square with a matching king or `None` if that
            player has no king.
        """
        #if not color in ["w", "b"]:
        #   raise KeyError("Invalid color: %s." % repr(color))

        for square, piece in [(s, self._pieces[s._x88]) for s in Square.get_all() if self._pieces[s._x88]]:
            if Piece.is_klass_and_color(piece, KING, color):
                return square
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:19,代码来源:position.py

示例3: test_is_klass_and_color

# 需要导入模块: from piece import Piece [as 别名]
# 或者: from piece.Piece import is_klass_and_color [as 别名]
 def test_is_klass_and_color(self):
     self.assertEqual(True, Piece.is_klass_and_color('P', piece.PAWN, piece.WHITE))
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:4,代码来源:test_piece.py


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