コード例 #1
0
 def move(self, color, movetext):
     m = list(movetext)
     
     logging.debug("starting move with len(m): " + str(len(m)))
     
     # Nbxd2(+|#) -- kNight in column B takes piece in d2
     
     destination = None
     x = None
     y = None
     for i in range(len(m)-1, -1, -1):
         logging.debug("i=" + str(i) + ", m[i]=" + m[i])
         
         if m[i] == "x" or m[i] == "+" or m[i] == "#":
             skip = True
         else:
             if destination is not None:
                 x = None
                 y = None
             
             if m[i] not in ["K", "Q", "B", "N", "R"]:
                 if m[i].isdigit():
                     y = m[i]
                 else:
                     if m[i] == "a":
                         x = 1
                     elif m[i] == "b":
                         x = 2
                     elif m[i] == "c":
                         x = 3
                     elif m[i] == "d":
                         x = 4
                     elif m[i] == "e":
                         x = 5
                     elif m[i] == "f":
                         x = 6
                     elif m[i] == "g":
                         x = 7
                     elif m[i] == "h":
                         x = 8
                 if destination is None and x is not None and y is not None:
                     destination = int(y) * 8 - int(x)
                 else:
                     if x is not None and y is not None:
                         origin = int(y) * 8 - int(x)
                     else:
                         origin = m[i]
             else:
                 if m[i] == "K" and color == "W":
                     piece = whiteking
                 elif m[i] == "Q" and color == "W":
                     piece = whitequeen
                 elif m[i] == "B" and color == "W":
                     piece = whitebishop
                 elif m[i] == "N" and color == "W":
                     piece = whiteknight
                 elif m[i] == "R" and color == "W":
                     piece = whiterook
                 elif color == "W":
                     piece = whitepawn
                 elif m[i] == "K" and color == "B":
                     piece = blackking
                 elif m[i] == "Q" and color == "B":
                     piece = blackqueen
                 elif m[i] == "B" and color == "B":
                     piece = blackbishop
                 elif m[i] == "N" and color == "B":
                     piece = blackknight
                 elif m[i] == "R" and color == "B":
                     piece = blackrook
                 else:
                     piece = blackpawn
     
     if not origin.isdigit():
         pos = Position(self.moves)
         origin = pos.find_origin(piece, destination, origin)
         
     
     # TODO: castling, king-side and queen-side
     
     # if origin is non specific (None or just a column), determine origin square
     
     # modify BitVector to move piece to new square
         # use concat (+) with two splices to move bits around - bv1[6:9]  = bv2[0:3]
     
     return piece, destination, origin