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


Python Board.get_fen方法代码示例

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


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

示例1: GameTest

# 需要导入模块: from chess import Board [as 别名]
# 或者: from chess.Board import get_fen [as 别名]
class GameTest(TestCase):

    def test_board(self):
        self.my_board = Board()
        moves = [
            ['e4', 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1'],
            ['e5', 'rnbqkbnr/pppp1ppp/8/4p3/4P3/8/PPPP1PPP/RNBQKBNR w KQkq e6 0 2'],
            ['Nf3', 'rnbqkbnr/pppp1ppp/8/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 0 2'],
            ['d6', 'rnbqkbnr/ppp2ppp/3p4/4p3/4P3/5N2/PPPP1PPP/RNBQKB1R w KQkq - 0 3'],
            ['Bc4', 'rnbqkbnr/ppp2ppp/3p4/4p3/2B1P3/5N2/PPPP1PPP/RNBQK2R b KQkq - 0 3'],
            ['Nf6', 'rnbqkb1r/ppp2ppp/3p1n2/4p3/2B1P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 0 4'],
            ['O-O', 'rnbqkb1r/ppp2ppp/3p1n2/4p3/2B1P3/5N2/PPPP1PPP/RNBQ1RK1 b kq - 0 4']
        ]
        for move in moves:
            self.my_board.move_algebraic(move[0])
            fen = self.my_board.get_fen()
            self.assertEqual(fen, move[1],
                'erro no movimento %s \n esperado: %s \n recebido: %s' % (move[0], move[1], fen))

    def test_get_fen(self):
        #test castling
        self.my_board = Board('rn1qkbnr/ppp2ppp/3p4/4p3/2B1P1b1/5N2/PPPP1PPP/RNBQK2R w KQkq - 0 4')
        self.my_board.move_algebraic('Rg1')
        self.assertEqual(self.my_board.get_fen(), 'rn1qkbnr/ppp2ppp/3p4/4p3/2B1P1b1/5N2/PPPP1PPP/RNBQK1R1 b Qkq - 0 4')
        #test helper
        self.my_board = Board('8/8/4kr2/3p4/8/1N1K1N2/8/8 w - - 0 1')
        self.my_board.move_algebraic('Nbd4+')
        self.assertEqual(self.my_board.get_fen(), '8/8/4kr2/3p4/3N4/3K1N2/8/8 b - - 0 1')
        #test enpassant
        self.my_board = Board('r1bqkbnr/p1pp1ppp/n7/1p1PpP2/8/8/PPP1P1PP/RNBQKBNR w KQkq e6 0 5')
        self.my_board.move_algebraic('dxe6')
        self.assertEqual(self.my_board.get_fen(), 'r1bqkbnr/p1pp1ppp/n3P3/1p3P2/8/8/PPP1P1PP/RNBQKBNR b KQkq - 0 5')
开发者ID:leocarv,项目名称:chess-engine,代码行数:34,代码来源:tests.py

示例2: move

# 需要导入模块: from chess import Board [as 别名]
# 或者: from chess.Board import get_fen [as 别名]
    def move(self, move):
        try:
            # inicializa o board com o fen atual
            myBoard = Board(self.fen)
            # aplica o movimento
            myBoard.move_algebraic(move)
            # modifica o atributo FEN
            self.fen = myBoard.get_fen()
            # salva registro
            self.save()

            #for debugger
            print myBoard.to_ascii_art()

        except Exception, e:
            print e
            return False
开发者ID:leocarv,项目名称:chess,代码行数:19,代码来源:models.py


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