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


Python LBoard.applyFen方法代码示例

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


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

示例1: test_paresSAN1

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def test_paresSAN1(self):
        """Testing parseSAN with unambiguous notations variants"""
        
        board = LBoard()
        board.applyFen("4k2B/8/8/8/8/8/8/B3K3 w - - 0 1")        

        self.assertEqual(repr(Move(parseSAN(board, 'Ba1b2'))), 'a1b2')
        self.assertEqual(repr(Move(parseSAN(board, 'Bh8b2'))), 'h8b2')

        self.assertEqual(repr(Move(parseSAN(board, 'Bab2'))), 'a1b2')
        self.assertEqual(repr(Move(parseSAN(board, 'Bhb2'))), 'h8b2')

        self.assertEqual(repr(Move(parseSAN(board, 'B1b2'))), 'a1b2')
        self.assertEqual(repr(Move(parseSAN(board, 'B8b2'))), 'h8b2')


        board = LBoard()
        board.applyFen("4k2B/8/8/8/8/8/1b6/B3K3 w - - 0 1")        

        self.assertEqual(repr(Move(parseSAN(board, 'Ba1xb2'))), 'a1b2')
        self.assertEqual(repr(Move(parseSAN(board, 'Bh8xb2'))), 'h8b2')

        self.assertEqual(repr(Move(parseSAN(board, 'Baxb2'))), 'a1b2')
        self.assertEqual(repr(Move(parseSAN(board, 'Bhxb2'))), 'h8b2')

        self.assertEqual(repr(Move(parseSAN(board, 'B1xb2'))), 'a1b2')
        self.assertEqual(repr(Move(parseSAN(board, 'B8xb2'))), 'h8b2')
开发者ID:Alex-Linhares,项目名称:pychess,代码行数:29,代码来源:move.py

示例2: testPolyglot_1

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def testPolyglot_1(self):
        """Testing hash keys agree with Polyglot's"""

        for testcase in testcases:
            board = LBoard(Board)
            board.applyFen(testcase[0])
            self.assertEqual(board.hash, testcase[1])
开发者ID:CarbonFixer,项目名称:pychess,代码行数:9,代码来源:polyglot.py

示例3: testFEN

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
 def testFEN(self):
     """Testing board-FEN conversion with several positions"""
     for i, fenstr in enumerate(self.positions[1:]):
         board = LBoard()
         board.applyFen(fenstr)
         fenstr2 = board.asFen()
         self.assertEqual(fenstr, fenstr2)
开发者ID:CarbonFixer,项目名称:pychess,代码行数:9,代码来源:fen.py

示例4: benchmark

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
def benchmark(maxdepth=6):
    """ Times a search of a static list of positions. """

    suite_time = time()
    suite_nodes = lsearch.nodes
    lsearch.endtime = sys.maxsize
    lsearch.searching = True
    for i, fen in enumerate(benchmarkPositions):
        lsearch.table.clear()
        clearPawnTable()
        board = LBoard(NORMALCHESS)
        board.applyFen(fen)
        pos_start_time = time()
        pos_start_nodes = lsearch.nodes
        for depth in range(1, maxdepth):
            mvs, scr = lsearch.alphaBeta(board, depth)
            pos_time = time() - pos_start_time
            pos_nodes = lsearch.nodes - pos_start_nodes
            pv = " ".join(listToSan(board, mvs))
            time_cs = int(100 * pos_time)
            print(depth, scr, time_cs, pos_nodes, pv)
        print("Searched position", i, "at", int(pos_nodes / pos_time) if pos_time > 0 else pos_nodes, "n/s")
    suite_time = time() - suite_time
    suite_nodes = lsearch.nodes - suite_nodes
    print("Total:", suite_nodes, "nodes in", suite_time, "s: ", suite_nodes /
          suite_time, "n/s")
    lsearch.nodes = 0
开发者ID:leogregianin,项目名称:pychess,代码行数:29,代码来源:Benchmark.py

示例5: run

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def run(cls, fenstr, variant):
        cls._ensureReady()
        if cls.widgets["newgamedialog"].props.visible:
            cls.widgets["newgamedialog"].present()
            return

        cls._hideOthers()
        for button in ("copy_button", "clear_button", "paste_button", "initial_button"):
            cls.widgets[button].show()
        cls.widgets["newgamedialog"].set_title(_("Setup Position"))
        cls.widgets["setupPositionSidePanel"].show()

        cls.setupmodel = SetupModel()
        cls.board_control = BoardControl(cls.setupmodel,
                                         {},
                                         setup_position=True)
        cls.setupmodel.curplayer = SetupPlayer(cls.board_control)
        cls.setupmodel.connect("game_changed", cls.game_changed)

        child = cls.widgets["setupBoardDock"].get_child()
        if child is not None:
            cls.widgets["setupBoardDock"].remove(child)
        cls.widgets["setupBoardDock"].add(cls.board_control)
        cls.board_control.show_all()
        if fenstr is not None:
            lboard = LBoard(variant)
            lboard.applyFen(fenstr)
            cls.setupmodel.boards = [cls.setupmodel.variant(setup=fenstr, lboard=lboard)]
            cls.setupmodel.variations = [cls.setupmodel.boards]
            cls.ini_widgets(fenstr, lboard)
        else:
            fenstr = cls.get_fen()
            cls.ini_widgets(True)
        cls.widgets["fen_entry"].set_text(fenstr)

        cls.setupmodel.start()

        def _validate(gamemodel):
            try:
                fenstr = cls.get_fen()
                cls.setupmodel.variant(setup=fenstr)
                return True
            except (AssertionError, LoadingError, SyntaxError) as e:
                d = Gtk.MessageDialog(mainwindow(), type=Gtk.MessageType.WARNING,
                                      buttons=Gtk.ButtonsType.OK,
                                      message_format=e.args[0])
                if len(e.args) > 1:
                    d.format_secondary_text(e.args[1])
                d.connect("response", lambda d, a: d.hide())
                d.show()
                return False

        def _callback(gamemodel, p0, p1):
            text = cls.get_fen()
            perspective = perspective_manager.get_perspective("games")
            create_task(perspective.generalStart(
                gamemodel, p0, p1, (StringIO(text), fen, 0, -1)))

        cls._generalRun(_callback, _validate)
开发者ID:leogregianin,项目名称:pychess,代码行数:61,代码来源:newGameDialog.py

示例6: testFEN

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
 def testFEN(self):
     """Testing board-FEN conversion with several positions"""
     print
     board = LBoard(Board)
     for i, fenstr in enumerate(self.positions[1:]):
         sys.stdout.write("#")
         board.applyFen(fenstr)
         fenstr2 = board.asFen()
         self.assertEqual(fenstr, fenstr2)
     print
开发者ID:jskurka,项目名称:PyChess-Learning-Module,代码行数:12,代码来源:fen.py

示例7: test_paresSAN2

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def test_paresSAN2(self):
        """Testing parseAN and parseSAN with bad promotions moves"""
        
        board = LBoard()
        board.applyFen("4k3/P7/8/8/8/8/8/4K3 w - - 0 1")        

        self.assertRaises(ParsingError, parseAN, board, 'a7a8K')
        self.assertRaises(ParsingError, parseAN, board, 'a7a8')

        self.assertRaises(ParsingError, parseSAN, board, 'a8K')
        self.assertRaises(ParsingError, parseSAN, board, 'a8')
开发者ID:Alex-Linhares,项目名称:pychess,代码行数:13,代码来源:move.py

示例8: testFRCCastlingUCI

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def testFRCCastlingUCI(self):
        """Testing UCI engine FRC castling move"""
        print()

        fen = "rbq1krb1/pp1pp1pp/2p1n3/5p2/2PP1P1n/4B1N1/PP2P1PP/RBQNKR2 w FAfa - 2 6"
        print(fen)
        board = LBoard(FISCHERRANDOMCHESS)
        board.applyFen(fen)
        # print board
        moves = [move for move in genCastles(board)]
        self.assertTrue(parseAN(board, "e1g1") in moves)
开发者ID:bboutkov,项目名称:pychess,代码行数:13,代码来源:frc_castling.py

示例9: feed_book

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def feed_book(self, records, positions):
        for rec in records:
            model = GameModel()

            if rec["Result"] == DRAW:
                score = (1, 1)
            elif rec["Result"] == WHITEWON:
                score = (2, 0)
            elif rec["Result"] == BLACKWON:
                score = (0, 2)
            else:
                score = (0, 0)

            fenstr = rec["FEN"]
            variant = self.chessfile.get_variant(rec)

            if variant:
                model.variant = name2variant[variant]
                board = LBoard(model.variant.variant)
            else:
                model.variant = NormalBoard
                board = LBoard()

            if fenstr:
                try:
                    board.applyFen(fenstr)
                except SyntaxError as err:
                    continue
            else:
                board.applyFen(FEN_START)

            boards = [board]

            movetext = self.chessfile.get_movetext(rec)
            boards = self.chessfile.parse_movetext(movetext, boards[0], -1)

            for board in boards:
                if board.plyCount > BOOK_DEPTH:
                    break
                move = board.lastMove
                if move is not None:
                    poly_move = toPolyglot(board.prev, move)
                    # move_str = "%s%s" % (reprCord[FCORD(move)], reprCord[TCORD(move)])
                    # print("%0.16x" % board.prev.hash, poly_move, board.prev.asFen(), move_str)
                    if board.prev.hash in positions:
                        if poly_move in positions[board.prev.hash]:
                            positions[board.prev.hash][poly_move] += score[board.prev.color]
                        else:
                            positions[board.prev.hash][poly_move] = score[board.prev.color]
                    else:
                        # board.prev.asFen(), move_str,
                        positions[board.prev.hash] = {poly_move: score[board.prev.color]}
开发者ID:leogregianin,项目名称:pychess,代码行数:54,代码来源:__init__.py

示例10: testFRCCastling

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def testFRCCastling(self):
        """Testing FRC castling movegen"""
        print()

        for fen, castles in data:
            print(fen)
            board = LBoard(FISCHERRANDOMCHESS)
            board.applyFen(fen)
            # print board
            moves = [move for move in genCastles(board)]
            self.assertEqual(len(moves), len(castles))
            for i, castle in enumerate(castles):
                kfrom, kto, flag = castle
                self.assertEqual(moves[i], newMove(kfrom, kto, flag))
开发者ID:bboutkov,项目名称:pychess,代码行数:16,代码来源:frc_castling.py

示例11: EvalTestCase

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
class EvalTestCase(unittest.TestCase):
    
    def setUp (self):
        self.board = LBoard(NORMALCHESS)
        self.board.applyFen("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w - - 0 1")
    
    def test1(self):
        """Testing eval symmetry with startboard (WHITE)"""
        score = evaluateComplete(self.board, color=WHITE)
        self.assertEqual(score, 0)
    
    def test2(self):
        """Testing eval symmetry with startboard (BLACK)"""
        score = evaluateComplete(self.board, color=BLACK)
        self.assertEqual(score, 0)
    
    def test3(self):
        """Testing eval symmetry of each function"""
        funcs = (f for f in dir(leval) if f.startswith("eval"))
        funcs = (getattr(leval,f) for f in funcs)
        funcs = (f for f in funcs if callable(f) \
                                    and f != leval.evaluateComplete\
                                    and f != leval.evalMaterial\
                                    and f != leval.evalPawnStructure\
                                    and f != leval.evalTrappedBishops)
        
        sw, phasew = leval.evalMaterial (self.board, WHITE)
        sb, phaseb = leval.evalMaterial (self.board, BLACK)

        self.assertEqual(phasew, phaseb)
        
        pawnScore, passed, weaked = leval.cacheablePawnInfo (self.board, phasew)
        sw = leval.evalPawnStructure (self.board, WHITE, phasew, passed, weaked)

        pawnScore, passed, weaked = leval.cacheablePawnInfo (self.board, phaseb)
        sb = leval.evalPawnStructure (self.board, BLACK, phaseb, passed, weaked)

        self.assertEqual(sw, sb)

        sw = leval.evalTrappedBishops (self.board, WHITE)
        sb = leval.evalTrappedBishops (self.board, BLACK)

        self.assertEqual(sw, sb)

        for func in funcs:
            sw = func(self.board, WHITE, phasew)
            sb = func(self.board, BLACK, phaseb)
            #print func, sw, sb
            self.assertEqual(sw, sb)
开发者ID:Alex-Linhares,项目名称:pychess,代码行数:51,代码来源:eval.py

示例12: movegen

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def movegen(self, positions, variant):
        for i, (fen, depths) in enumerate(positions):
            print(i + 1, "/", len(positions), "-", fen)
            board = LBoard(variant)
            board.applyFen(fen)
            hash = board.hash

            for depth, suposedMoveCount in depths:
                if depth > self.MAXDEPTH:
                    break
                self.count = 0
                print("searching depth %d for %d moves" % (depth, suposedMoveCount))
                self.perft(board, depth, [])
                self.assertEqual(board.hash, hash)
                self.assertEqual(self.count, suposedMoveCount)
开发者ID:bboutkov,项目名称:pychess,代码行数:17,代码来源:movegen.py

示例13: test_apply_pop

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def test_apply_pop(self):
        """Testing Atomic applyMove popMove"""

        board = LBoard(variant=ATOMICCHESS)
        board.applyFen(FEN1)
        print(board)
        hist_exploding_around0 = [a[:] for a in board.hist_exploding_around]
        print_apply_pop = False

        for lmove1 in genAllMoves(board):
            board.applyMove(lmove1)
            if board.opIsChecked():
                if print_apply_pop: print("popMove1 (invalid)", Move(lmove1))
                board.popMove()
                continue
                
            hist_exploding_around1 = [a[:] for a in board.hist_exploding_around]
            for lmove2 in genAllMoves(board):
                board.applyMove(lmove2)
                if print_apply_pop: print("   applyMove2", Move(lmove2))
                if board.opIsChecked():
                    if print_apply_pop: print("   popMove2 (invalid)", Move(lmove2))
                    board.popMove()
                    continue

                hist_exploding_around2 = [a[:] for a in board.hist_exploding_around]
                for lmove3 in genAllMoves(board):
                    board.applyMove(lmove3)
                    if print_apply_pop: print("      applyMove3", Move(lmove3))
                    if board.opIsChecked():
                        if print_apply_pop: print("      popMove3 (invalid)", Move(lmove3))
                        board.popMove()
                        continue

                    board.popMove()
                    if print_apply_pop: print("      popMove3", Move(lmove3))

                    self.assertEqual(hist_exploding_around2, board.hist_exploding_around)

                board.popMove()
                if print_apply_pop: print("   popMove2", Move(lmove2))

                self.assertEqual(hist_exploding_around1, board.hist_exploding_around)
                
            board.popMove()
            if print_apply_pop: print("popMove1", Move(lmove1))

            self.assertEqual(hist_exploding_around0, board.hist_exploding_around)
开发者ID:vgupta2507,项目名称:pychess,代码行数:50,代码来源:atomic.py

示例14: test_parseFAN

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
    def test_parseFAN(self):
        """Testing parseFAN"""

        board = LBoard()
        board.applyFen("rnbqkbnr/8/8/8/8/8/8/RNBQKBNR w KQkq - 0 1")        

        for lmove in genAllMoves(board):
            board.applyMove(lmove)
            if board.opIsChecked():
                board.popMove()
                continue

            board.popMove()

            fan = toFAN(board, lmove)
            self.assertEqual(parseFAN(board, fan), lmove)
开发者ID:Alex-Linhares,项目名称:pychess,代码行数:18,代码来源:move.py

示例15: create_fen

# 需要导入模块: from pychess.Utils.lutils.LBoard import LBoard [as 别名]
# 或者: from pychess.Utils.lutils.LBoard.LBoard import applyFen [as 别名]
def create_fen(pieces):
    """ Create a random FEN position using given pieces """

    pos = pieces.rfind("k")
    pieces = pieces[:pos], pieces[pos:]

    ok = False
    while not ok:
        lboard = LBoard()
        lboard.applyFen("8/8/8/8/8/8/8/8 w - - 0 1")
        bishop_cords = [[], []]
        bishop_colors_ok = True

        cords = list(range(0, 64))
        pawn_cords = list(range(0 + 8, 64 - 8))

        # Order of color is important here to prevent offering
        # positions with trivial captures in first move
        for color in (WHITE, BLACK):
            for char in pieces[color]:
                piece = chrU2Sign[char.upper()]
                attacked = True
                limit = 100
                while attacked and limit > 0:
                    cord = random.choice(pawn_cords if char == "p" else cords)
                    attacked = isAttacked(lboard, cord, 1 - color)
                    limit -= 1
                lboard._addPiece(cord, piece, color)
                cords.remove(cord)
                if cord in pawn_cords:
                    pawn_cords.remove(cord)
                if char == "b":
                    bishop_cords[color].append(cord)

            # 2 same color bishop is not ok
            if len(bishop_cords[color]) == 2 and bishop_colors_ok:
                b0, b1 = bishop_cords[color]
                b0_color = BLACK if RANK(b0) % 2 == FILE(b0) % 2 else WHITE
                b1_color = BLACK if RANK(b1) % 2 == FILE(b1) % 2 else WHITE
                if b0_color == b1_color:
                    bishop_colors_ok = False
                    break

        ok = (not lboard.isChecked()) and (not lboard.opIsChecked()) and bishop_colors_ok

    fen = lboard.asFen()
    return fen
开发者ID:teacoffee2017,项目名称:pychess,代码行数:49,代码来源:EndgamesPanel.py


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