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


Python LBoard.LBoard类代码示例

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


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

示例1: testPolyglot_1

    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,代码行数:7,代码来源:polyglot.py

示例2: testFEN

 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,代码行数:7,代码来源:fen.py

示例3: benchmark

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,代码行数:27,代码来源:Benchmark.py

示例4: run

    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,代码行数:59,代码来源:newGameDialog.py

示例5: testFEN

 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,代码行数:10,代码来源:fen.py

示例6: test_paresSAN2

    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,代码行数:11,代码来源:move.py

示例7: testFRCCastlingUCI

    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,代码行数:11,代码来源:frc_castling.py

示例8: testFRCCastling

    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,代码行数:14,代码来源:frc_castling.py

示例9: add_variation

    def add_variation(self, board, moves, comment="", score="", emit=True):
        board0 = board
        board = board0.clone()
        board.board.prev = None

        # this prevents annotation panel node searches to find this instead of board0
        board.board.hash = -1

        if comment:
            board.board.children.append(comment)

        variation = [board]

        for move in moves:
            new = board.move(move)
            if len(variation) == 1:
                new.board.prev = board0.board
                variation[0].board.next = new.board
            else:
                new.board.prev = board.board
                board.board.next = new.board
            variation.append(new)
            board = new

        if board0.board.next is None:
            # If we are in the latest played board, and want to add a variation
            # we have to add a not played yet board first
            # which can hold the variation as his child
            from pychess.Utils.lutils.LBoard import LBoard
            null_board = LBoard()
            null_board.prev = board0.board
            board0.board.next = null_board

        board0.board.next.children.append(
            [vboard.board for vboard in variation])
        if score:
            variation[-1].board.children.append(score)

        head = None
        for vari in self.variations:
            if board0 in vari:
                head = vari
                break

        variation[0] = board0
        self.variations.append(head[:board0.ply - self.lowply] + variation)
        self.needsSave = True
        if emit:
            self.emit("variation_added", board0.board.next.children[-1], board0.board.next)
        return self.variations[-1]
开发者ID:bboutkov,项目名称:pychess,代码行数:50,代码来源:GameModel.py

示例10: EvalTestCase

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,代码行数:49,代码来源:eval.py

示例11: movegen

    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,代码行数:15,代码来源:movegen.py

示例12: test_parseFAN

    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,代码行数:16,代码来源:move.py

示例13: add_variation

    def add_variation(self, board, moves, comment="", score=""):
        board0 = board
        board = board0.clone()
        board.board.prev = None

        variation = [board]

        for move in moves:
            new = board.move(move)
            if len(variation) == 1:
                new.board.prev = board0.board
                variation[0].board.next = new.board
            else:
                new.board.prev = board.board
                board.board.next = new.board
            variation.append(new)
            board = new

        if board0.board.next is None:
            # If we are in the latest played board, and want to add a variation
            # we have to add a not played yet board first
            # which can hold the variation as his child
            from pychess.Utils.lutils.LBoard import LBoard

            null_board = LBoard()
            null_board.prev = board0.board
            null_board.plyCount = board0.board.plyCount + 1
            board0.board.next = null_board

        board0.board.next.children.append([board.board for board in variation])

        head = None
        for vari in self.variations:
            if board0 in vari:
                head = vari
                break

        variation[0] = board0
        self.variations.append(head[: board0.ply - self.lowply] + variation)
        self.needsSave = True
        self.emit("variation_added", board0.board.next.children[-1], board0.board.next, comment, score)
        return self.variations[-1]
开发者ID:jholland6843,项目名称:pychess,代码行数:42,代码来源:GameModel.py

示例14: test_paresSAN1

    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,代码行数:27,代码来源:move.py

示例15: movegen

    def movegen(self, positions):
        for i, (fen, depths) in enumerate(positions):
            board = LBoard(FISCHERRANDOMCHESS)
            fen = fen.split()
            castl = fen[2]
            castl = castl.replace("K", "H")
            castl = castl.replace("Q", "A")
            castl = castl.replace("k", "h")
            castl = castl.replace("q", "a")
            fen[2] = castl
            fen = ' '.join(fen)

            print(i+1, "/", len(positions), "-", fen)
            board.applyFen(fen)
            
            for depth, suposedMoveCount in enumerate(depths):
                if depth+1 > self.MAXDEPTH: break
                self.count = 0
                print("searching depth %d for %d moves" % \
                        (depth+1, suposedMoveCount))
                self.perft (board, depth+1, [])
                self.assertEqual(self.count, suposedMoveCount)
开发者ID:iamLovingJerk,项目名称:pychess,代码行数:22,代码来源:frc_movegen.py


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