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


Python lmovegen.newMove函数代码示例

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


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

示例1: on_players_changed

            def on_players_changed(game):
                # fill fools mate moves to players move queue
                p0 = game.players[0]
                p0.move_queue.put_nowait(Move(newMove(F2, F3)))
                p0.move_queue.put_nowait(Move(newMove(G2, G4)))

                p1 = gamemodel.players[1]
                p1.move_queue.put_nowait(Move(newMove(E7, E5)))
                p1.move_queue.put_nowait(Move(newMove(D8, H4)))
开发者ID:teacoffee2017,项目名称:pychess,代码行数:9,代码来源:savegame.py

示例2: validate

    def validate(self, cord0, cord1):
        if cord0 is None or cord1 is None:
            return False
        # prevent accidental NULL_MOVE creation
        if cord0 == cord1:
            return False
        if self.getBoard()[cord0] is None:
            return False

        if self.parent.setup_position:
            # prevent moving pieces inside holding
            if (cord0.x < 0 or cord0.x > self.FILES - 1) and \
                    (cord1.x < 0 or cord1.x > self.FILES - 1):
                return False
            else:
                return True

        if cord1.x < 0 or cord1.x > self.FILES - 1:
            return False
        if cord0.x < 0 or cord0.x > self.FILES - 1:
            # drop
            return validate(self.getBoard(), Move(lmovegen.newMove(
                self.getBoard()[cord0].piece, cord1.cord, DROP)))
        else:
            return validate(self.getBoard(), Move(cord0, cord1,
                                                  self.getBoard()))
开发者ID:bboutkov,项目名称:pychess,代码行数:26,代码来源:BoardControl.py

示例3: row_activated

    def row_activated(self, iter, model):
        if self.mode == HINT and self.store.get_path(iter) != Gtk.TreePath(
                self.path):
            moves = self.store[iter][0][2]
            if moves is not None:
                score = self.store[iter][1][0]
                model.add_variation(self.engine.board,
                                    moves,
                                    comment="",
                                    score=score)

        if self.mode == SPY and self.store.get_path(iter) != Gtk.TreePath(
                self.path):
            moves = self.store[iter][0][2]
            if moves is not None:
                score = self.store[iter][1][0]
                board = self.engine.board.board
                # SPY analyzer has inverted color boards
                # we need to chage it to get the board in gamemodel variations board list later
                board.setColor(1 - board.color)
                king = board.kings[board.color]
                null_move = Move(newMove(king, king, NULL_MOVE))
                model.add_variation(self.engine.board,
                                    [null_move] + moves,
                                    comment="",
                                    score=score)
开发者ID:ME7ROPOLIS,项目名称:pychess,代码行数:26,代码来源:bookPanel.py

示例4: emit_move_signal

 def emit_move_signal (self, cord0, cord1, promotion=None):
     # Game end can change cord0 to None while dragging a piece
     if cord0 is None:
         return
         
     color = self.view.model.boards[-1].color
     board = self.view.model.getBoardAtPly(self.view.shown, self.view.shownVariationIdx)
     # Ask player for which piece to promote into. If this move does not
     # include a promotion, QUEEN will be sent as a dummy value, but not used
     
     if promotion is None and board[cord0].sign == PAWN and cord1.y in (0, self.RANKS-1):
         promotion = self.getPromotion()
         if promotion is None:
             # Put back pawn moved be d'n'd
             self.view.runAnimation(redrawMisc = False)
             return
     
     if cord0.x < 0 or cord0.x > self.FILES-1:
         move = Move(lmovegen.newMove(board[cord0].piece, cord1.cord, DROP))
     else:
         move = Move(cord0, cord1, board, promotion)
     
     if self.view.model.curplayer.__type__ == LOCAL and self.view.shownIsMainLine() and \
        self.view.model.boards[-1] == board and self.view.model.status == RUNNING:
         self.emit("piece_moved", move, color)
     else:
         if board.board.next is None and not self.view.shownIsMainLine():
             self.view.model.add_move2variation(board, move, self.view.shownVariationIdx)
             self.view.shown += 1
         else:
             new_vari = self.view.model.add_variation(board, (move,))
             self.view.setShownBoard(new_vari[-1])
开发者ID:fowode,项目名称:pychess,代码行数:32,代码来源:BoardControl.py

示例5: parsePolyglot

def parsePolyglot (board, pg):
    """ Parse a 16-bit Polyglot-format move """
    
    tcord = TCORD(pg)
    fcord = FCORD(pg)
    flag = NORMAL_MOVE
    if pg >> 12:
        flag = FLAG_PIECE( (pg >> 12) + 1 )
    elif board.arBoard[fcord] == KING:
        if board.arBoard[tcord] == ROOK:
            color = board.color
            friends = board.friends[color]
            if bitPosArray[tcord] & friends:
                if board.ini_rooks[color][0] == tcord:
                    flag = QUEEN_CASTLE
                    if board.variant == NORMALCHESS: # Want e1c1/e8c8
                        tcord += 2
                else:
                    flag = KING_CASTLE
                    if board.variant == NORMALCHESS: # Want e1g1/e8g8
                        tcord -= 1
    elif board.arBoard[fcord] == PAWN and board.arBoard[tcord] == EMPTY and \
            FILE(fcord) != FILE(tcord) and RANK(fcord) != RANK(tcord):
        flag = ENPASSANT

    return newMove (fcord, tcord, flag)
开发者ID:btrent,项目名称:knave,代码行数:26,代码来源:lmove.py

示例6: validate

    def validate (self, cord0, cord1):
        if cord0 is None or cord1 is None:
            return False
        # prevent accidental NULL_MOVE creation
        if cord0 == cord1:
            return False
        if self.getBoard()[cord0] == None:
            return False

        if self.parent.setup_position:
            to_piece = self.getBoard()[cord1]
            # prevent moving pieces inside holding
            if (cord0.x < 0 or cord0.x > self.FILES-1) and \
                (cord1.x < 0 or cord1.x > self.FILES-1):
                return False
            # prevent moving kings off board
            elif self.getBoard()[cord0].piece == KING and \
                (cord1.x < 0 or cord1.x > self.FILES-1):
                return False
            # prevent taking enemy king
            elif to_piece is not None and to_piece.piece == KING:
                return False
            else:
                return True
        
        if cord1.x < 0 or cord1.x > self.FILES-1:
            return False
        if cord0.x < 0 or cord0.x > self.FILES-1:
            # drop
            return validate(self.getBoard(), Move(lmovegen.newMove(self.getBoard()[cord0].piece, cord1.cord, DROP)))
        else:
            return validate(self.getBoard(), Move(cord0, cord1, self.getBoard()))
开发者ID:ZeepXanflorp,项目名称:pychess,代码行数:32,代码来源:BoardControl.py

示例7: __init__

 def __init__ (self, cord0, cord1=None, board=None, promotion=None):
     """ Inits a new highlevel Move object.
         The object can be initialized in the follow ways:
             Move(cord0, cord1, board, [promotionPiece])
             Move(lovLevelMoveInt) """
     
     if not cord1:
         self.move = cord0
         self.flag = self.move >> 12
         self.cord0 = None if self.flag == DROP else Cord(lmove.FCORD(self.move))
         self.cord1 = Cord(lmove.TCORD(self.move))
         
     else:
         assert cord0 != None and cord1 != None, "cord0=%s, cord1=%s, board=%s" % (cord0, cord1, board)
         assert board[cord0] != None, "cord0=%s, cord1=%s, board=%s" % (cord0, cord1, board)
         self.cord0 = cord0
         self.cord1 = cord1
         if not board:
             raise ValueError("Move needs a Board object in order to investigate flags")
         
         self.flag = NORMAL_MOVE
         if board[self.cord0].piece == PAWN and  self.cord1.cord in board.PROMOTION_ZONE[board.board.color]:
             if promotion == None:
                 if board.variant == SITTUYINCHESS:
                     if cord0 == cord1:
                         self.flag = lmove.FLAG_PIECE(QUEEN)
                 else:
                     self.flag = lmove.FLAG_PIECE(QUEEN)
             else:
                 self.flag = lmove.FLAG_PIECE(promotion)
         
         elif board[self.cord0].piece == KING:
             if self.cord0 == self.cord1:
                 self.flag = NULL_MOVE
             elif board.variant == FISCHERRANDOMCHESS:
                 if (abs(self.cord0.x - self.cord1.x) > 1 and self.cord1.x==C1) or \
                     \
                     (board.board.ini_rooks[board.color][0] == self.cord1.cord and \
                     ((board.board.color == WHITE and board.board.castling & W_OOO) or \
                     (board.board.color == BLACK and board.board.castling & B_OOO))):
                     self.flag = QUEEN_CASTLE
                 elif (abs(self.cord0.x - self.cord1.x) > 1 and self.cord1.x==G1) or \
                     \
                     (board.board.ini_rooks[board.color][1] == self.cord1.cord and \
                     ((board.board.color == WHITE and board.board.castling & W_OO) or \
                     (board.board.color == BLACK and board.board.castling & B_OO))):
                     self.flag = KING_CASTLE
             elif board.variant != CAMBODIANCHESS:
                 if self.cord0.x - self.cord1.x == 2:
                     self.flag = QUEEN_CASTLE if self.cord0.x == 4 else KING_CASTLE
                 elif self.cord0.x - self.cord1.x == -2:
                     self.flag = KING_CASTLE if self.cord0.x == 4 else QUEEN_CASTLE
         
         elif board[self.cord0].piece == PAWN and \
                 board[self.cord1] == None and \
                 self.cord0.x != self.cord1.x and \
                 self.cord0.y != self.cord1.y:
             self.flag = ENPASSANT
         
         self.move = newMove(self.cord0.cord, self.cord1.cord, self.flag)
开发者ID:Alex-Linhares,项目名称:pychess,代码行数:60,代码来源:Move.py

示例8: parseAN

def parseAN(board, an):
    """ Parse an Algebraic Notation string """

    if not 4 <= len(an) <= 6:
        raise ParsingError(an, "the move must be 4 or 6 chars long",
                           board.asFen())

    try:
        fcord = cordDic[an[:2]]
        tcord = cordDic[an[2:4]]
    except KeyError as e:
        raise ParsingError(an, "the cord (%s) is incorrect" % e.args[0],
                           board.asFen())

    flag = NORMAL_MOVE

    if len(an) > 4 and not an[-1] in "QRBNMSFqrbnmsf":
        if (board.variant != SUICIDECHESS and board.variant != GIVEAWAYCHESS) or \
            (board.variant == SUICIDECHESS or board.variant == GIVEAWAYCHESS) and not an[
                -1] in "Kk":
            raise ParsingError(an, "invalid promoted piece", board.asFen())

    if len(an) == 5:
        # The a7a8q variant
        flag = chr2Sign[an[4].lower()] + 2
    elif len(an) == 6:
        # The a7a8=q variant
        flag = chr2Sign[an[5].lower()] + 2
    elif board.arBoard[fcord] == KING:
        if fcord - tcord == 2:
            flag = QUEEN_CASTLE
            if board.variant == FISCHERRANDOMCHESS:
                tcord = board.ini_rooks[board.color][0]
        elif fcord - tcord == -2:
            flag = KING_CASTLE
            if board.variant == FISCHERRANDOMCHESS:
                tcord = board.ini_rooks[board.color][1]
        elif board.arBoard[
                tcord] == ROOK:
            color = board.color
            friends = board.friends[color]
            if bitPosArray[tcord] & friends:
                if board.ini_rooks[color][0] == tcord:
                    flag = QUEEN_CASTLE
                else:
                    flag = KING_CASTLE
        else:
            flag = NORMAL_MOVE
    elif board.arBoard[fcord] == PAWN and board.arBoard[tcord] == EMPTY and \
            FILE(fcord) != FILE(tcord) and RANK(fcord) != RANK(tcord):
        flag = ENPASSANT
    elif board.arBoard[fcord] == PAWN:
        if an[3] in "18" and board.variant != SITTUYINCHESS:
            raise ParsingError(
                an, _("promotion move without promoted piece is incorrect"),
                board.asFen())

    return newMove(fcord, tcord, flag)
开发者ID:teacoffee2017,项目名称:pychess,代码行数:58,代码来源:lmove.py

示例9: emit_move_signal

    def emit_move_signal(self, cord0, cord1, promotion=None):
        # Game end can change cord0 to None while dragging a piece
        if cord0 is None:
            return
        color = self.view.model.boards[-1].color
        board = self.view.model.getBoardAtPly(self.view.shown,
                                              self.view.shown_variation_idx)
        # Ask player for which piece to promote into. If this move does not
        # include a promotion, QUEEN will be sent as a dummy value, but not used
        if promotion is None and board[
                cord0].sign == PAWN and cord1.cord in board.PROMOTION_ZONE[
                    color]:
            if self.variant.variant == SITTUYINCHESS:
                # no promotion allowed if we have queen
                if board.board.boards[color][QUEEN]:
                    promotion = None
                else:
                    # promotion is always optional
                    promotion = self.getPromotion()
                    if promotion is None and cord0 == cord1:
                        # if don't want in place promotion
                        return
            elif len(self.variant.PROMOTIONS) == 1:
                promotion = lmove.PROMOTE_PIECE(self.variant.PROMOTIONS[0])
            else:
                if conf.get("autoPromote", False):
                    promotion = lmove.PROMOTE_PIECE(QUEEN_PROMOTION)
                else:
                    promotion = self.getPromotion()
                    if promotion is None:
                        # Put back pawn moved be d'n'd
                        self.view.runAnimation(redraw_misc=False)
                        return
        if cord0.x < 0 or cord0.x > self.FILES - 1:
            move = Move(lmovegen.newMove(board[cord0].piece, cord1.cord, DROP))
        else:
            move = Move(cord0, cord1, board, promotion)

        if (self.view.model.curplayer.__type__ == LOCAL or self.view.model.examined) and \
                self.view.shownIsMainLine() and \
                self.view.model.boards[-1] == board and \
                self.view.model.status == RUNNING:
            if self.setup_position:
                self.emit("piece_moved", (cord0, cord1), board[cord0].color)
            else:
                self.emit("piece_moved", move, color)
                if self.view.model.examined:
                    self.view.model.connection.bm.sendMove(toAN(board, move))
        else:
            if board.board.next is None and not self.view.shownIsMainLine():
                self.view.model.add_move2variation(
                    board, move, self.view.shown_variation_idx)
                self.view.shown += 1
            else:
                new_vari = self.view.model.add_variation(board, (move, ))
                self.view.setShownBoard(new_vari[-1])
开发者ID:CarbonFixer,项目名称:pychess,代码行数:56,代码来源:BoardControl.py

示例10: on_book_created

            def on_book_created(persp, event):
                self.assertTrue(os.path.isfile(BIN))

                book.path = BIN
                book.bookfile = True

                testcase = testcases[0]
                board = LBoard(Board)
                board.applyFen(testcase[0])
                openings = book.getOpenings(board)
                self.assertEqual(sorted(openings), sorted([(newMove(E2, E4), 2, 0), (newMove(A2, A4), 0, 0)]))

                testcase = testcases[-1]
                board = LBoard(Board)
                board.applyFen(testcase[0])
                openings = book.getOpenings(board)
                self.assertEqual(openings, [])

                event.set()
开发者ID:leogregianin,项目名称:pychess,代码行数:19,代码来源:polyglot.py

示例11: validate

 def validate (self, cord0, cord1):
     assert cord0 != None and cord1 != None, "cord0: " + str(cord0) + ", cord1: " + str(cord1)
     if self.getBoard()[cord0] == None:
         return False
     if cord1.x < 0 or cord1.x > self.FILES-1:
         return False
     if cord0.x < 0 or cord0.x > self.FILES-1:
         # drop
         return validate(self.getBoard(), Move(lmovegen.newMove(self.getBoard()[cord0].piece, cord1.cord, DROP)))
     else:
         return validate(self.getBoard(), Move(cord0, cord1, self.getBoard()))
开发者ID:btrent,项目名称:knave,代码行数:11,代码来源:BoardControl.py

示例12: validate

 def validate (self, cord0, cord1):
     if cord0 is None or cord1 is None:
         return False
     if self.getBoard()[cord0] == None:
         return False
     if cord1.x < 0 or cord1.x > self.FILES-1:
         return False
     if cord0.x < 0 or cord0.x > self.FILES-1:
         # drop
         return validate(self.getBoard(), Move(lmovegen.newMove(self.getBoard()[cord0].piece, cord1.cord, DROP)))
     else:
         return validate(self.getBoard(), Move(cord0, cord1, self.getBoard()))
开发者ID:Alex-Linhares,项目名称:pychess,代码行数:12,代码来源:BoardControl.py

示例13: 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

示例14: validate

 def validate (self, cord0, cord1):
     if cord0 is None or cord1 is None:
         return False
     # prevent accidental NULL_MOVE creation
     if cord0 == cord1:
         return False
     if self.getBoard()[cord0] == None:
         return False
     if cord1.x < 0 or cord1.x > self.FILES-1:
         return False
     if cord0.x < 0 or cord0.x > self.FILES-1:
         # drop
         return validate(self.getBoard(), Move(lmovegen.newMove(self.getBoard()[cord0].piece, cord1.cord, DROP)))
     else:
         return validate(self.getBoard(), Move(cord0, cord1, self.getBoard()))
开发者ID:jholland6843,项目名称:pychess,代码行数:15,代码来源:BoardControl.py

示例15: parseSAN

def parseSAN(board, san):
    """ Parse a Short/Abbreviated Algebraic Notation string """
    notat = san

    color = board.color

    if notat == "--":
        return newMove(board.kings[color], board.kings[color], NULL_MOVE)

    if notat[-1] in "+#":
        notat = notat[:-1]
        # If '++' was used in place of #
        if notat[-1] == "+":
            notat = notat[:-1]

    flag = NORMAL_MOVE

    # If last char is a piece char, we assue it the promote char
    c = notat[-1]
    if c in "KQRBNSMFkqrbnsmf.":
        c = c.lower()
        if c == "k" and board.variant != SUICIDECHESS and board.variant != GIVEAWAYCHESS:
            raise ParsingError(san, _("invalid promoted piece"), board.asFen())
        elif c == "." and board.variant in (CAMBODIANCHESS, MAKRUKCHESS,
                                            SITTUYINCHESS):
            # temporary hack for xboard bug
            flag = QUEEN_PROMOTION
        else:
            flag = chr2Sign[c] + 2

        if notat[-2] == "=":
            notat = notat[:-2]
        else:
            notat = notat[:-1]

    if len(notat) < 2:
        raise ParsingError(san, _("the move needs a piece and a cord"),
                           board.asFen())

    if notat[0] in "O0o":
        fcord = board.ini_kings[color]
        flag = KING_CASTLE if notat in ("O-O", "0-0", "o-o", "OO", "00", "oo") else QUEEN_CASTLE
        side = flag - QUEEN_CASTLE
        if FILE(fcord) == 3 and board.variant in (WILDCASTLECHESS,
                                                  WILDCASTLESHUFFLECHESS):
            side = 0 if side == 1 else 1
        if board.variant == FISCHERRANDOMCHESS:
            tcord = board.ini_rooks[color][side]
        else:
            tcord = board.fin_kings[color][side]
        return newMove(fcord, tcord, flag)

    # LAN is not allowed in pgn spec, but sometimes it occures
    if "-" in notat:
        notat = notat.replace("-", "")

    if "@" in notat:
        tcord = cordDic[notat[-2:]]
        if notat[0].islower():
            # Sjeng-ism
            piece = chr2Sign[notat[0]]
        else:
            piece = chrU2Sign[notat[0]]
        return newMove(piece, tcord, DROP)

    # standard piece letters
    if notat[0] in "QRBKNSMF":
        piece = chrU2Sign[notat[0]]
        notat = notat[1:]
    # unambigious lowercase piece letters
    elif notat[0] in "qrknsm":
        piece = chr2Sign[notat[0]]
        notat = notat[1:]
    # a lowercase bishop letter or a pawn capture
    elif notat[0] == "b" and len(notat) > 2 and board.variant == NORMALCHESS:
        tcord = cordDic[notat[-2:]]
        trank = int(notat[-1])
        # if from and to lines are not neighbours -> Bishop
        if abs(ord(notat[0]) - ord(notat[-2])) > 1:
            piece = chr2Sign[notat[0]]
            notat = notat[1:]
        # if from and to lines are neighbours (or the same) but to is an empty square
        # which can't be en-passant square target -> Bishop
        elif board.arBoard[tcord] == EMPTY and ((color == BLACK and trank != 3) or (color == WHITE and trank != 6)):
            piece = chr2Sign[notat[0]]
            notat = notat[1:]
        # elif "ba3", "bc3" ,"ba6", "bc6"
        # these can be Bishop or Pawn moves, but we don't try to introspect them (sorry)
        else:
            piece = PAWN
    else:
        piece = PAWN
        if notat[-1] in "18" and flag == NORMAL_MOVE and board.variant != SITTUYINCHESS:
            raise ParsingError(
                san, _("promotion move without promoted piece is incorrect"),
                board.asFen())

    if "x" in notat:
        notat, tcord = notat.split("x")
        if tcord not in cordDic:
#.........这里部分代码省略.........
开发者ID:teacoffee2017,项目名称:pychess,代码行数:101,代码来源:lmove.py


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