示例#1
0
def getMoveKillingKing(board):
    """ Returns a move from the current color, able to capture the opponent
        king """

    lboard = board.board
    color = lboard.color
    opking = lboard.kings[1 - color]

    for cord in iterBits(getAttacks(lboard, opking, color)):
        return Move(Cord(cord), Cord(opking), board)
示例#2
0
def getDestinationCords(board, cord):
    tcords = []
    for move in lmovegen.genAllMoves(board.board):
        if FCORD(move) == cord.cord:
            if not board.willLeaveInCheck(Move(move)):
                tcords.append(Cord(TCORD(move)))
    return tcords
示例#3
0
    def __init__(self, setup=False):
        self.data = [[None] * 8 for i in xrange(8)]
        self.board = LBoard(self.variant)

        if setup:
            if setup == True:
                self.board.applyFen(FEN_START)
            else:
                self.board.applyFen(setup)

            arBoard = self.board.arBoard
            wpieces = self.board.boards[WHITE]
            bpieces = self.board.boards[BLACK]

            for cord in iterBits(wpieces[PAWN]):
                self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, PAWN)
            for cord in iterBits(wpieces[KNIGHT]):
                self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, KNIGHT)
            for cord in iterBits(wpieces[BISHOP]):
                self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, BISHOP)
            for cord in iterBits(wpieces[ROOK]):
                self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, ROOK)
            for cord in iterBits(wpieces[QUEEN]):
                self.data[RANK(cord)][FILE(cord)] = Piece(WHITE, QUEEN)
            if self.board.kings[WHITE] != -1:
                self[Cord(self.board.kings[WHITE])] = Piece(WHITE, KING)

            for cord in iterBits(bpieces[PAWN]):
                self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, PAWN)
            for cord in iterBits(bpieces[KNIGHT]):
                self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, KNIGHT)
            for cord in iterBits(bpieces[BISHOP]):
                self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, BISHOP)
            for cord in iterBits(bpieces[ROOK]):
                self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, ROOK)
            for cord in iterBits(bpieces[QUEEN]):
                self.data[RANK(cord)][FILE(cord)] = Piece(BLACK, QUEEN)
            if self.board.kings[BLACK] != -1:
                self[Cord(self.board.kings[BLACK])] = Piece(BLACK, KING)
示例#4
0
    def simulateMove(self, board1, move):
        moved = []
        new = []
        dead = []

        cord0, cord1 = move.cords

        moved.append((self[cord0], cord0))

        if self[cord1]:
            dead.append(self[cord1])

        if move.flag == QUEEN_CASTLE:
            if self.color == WHITE:
                moved.append((self[Cord(A1)], Cord(A1)))
            else:
                moved.append((self[Cord(A8)], Cord(A8)))
        elif move.flag == KING_CASTLE:
            if self.color == WHITE:
                moved.append((self[Cord(H1)], Cord(H1)))
            else:
                moved.append((self[Cord(H8)], Cord(H8)))

        elif move.flag in PROMOTIONS:
            newPiece = board1[cord1]
            moved.append((newPiece, cord0))
            new.append(newPiece)
            newPiece.opacity = 1
            dead.append(self[cord0])

        elif move.flag == ENPASSANT:
            if self.color == WHITE:
                dead.append(self[Cord(cord1.x, cord1.y - 1)])
            else:
                dead.append(self[Cord(cord1.x, cord1.y + 1)])

        return moved, new, dead
示例#5
0
 def _get_enpassant(self):
     if self.board.enpassant != None:
         return Cord(self.board.enpassant)
     return None
示例#6
0
    def move(self, move):

        assert self[move.cord0], "%s %s" % (move, self.asFen())

        newBoard = self.clone()
        newBoard.board.applyMove(move.move)

        cord0, cord1 = move.cords
        flag = FLAG(move.move)

        newBoard[cord1] = newBoard[cord0]
        newBoard[cord0] = None

        if self.color == WHITE:
            if flag == QUEEN_CASTLE:
                newBoard[Cord(D1)] = newBoard[Cord(A1)]
                newBoard[Cord(A1)] = None
            elif flag == KING_CASTLE:
                newBoard[Cord(F1)] = newBoard[Cord(H1)]
                newBoard[Cord(H1)] = None
        else:
            if flag == QUEEN_CASTLE:
                newBoard[Cord(D8)] = newBoard[Cord(A8)]
                newBoard[Cord(A8)] = None
            elif flag == KING_CASTLE:
                newBoard[Cord(F8)] = newBoard[Cord(H8)]
                newBoard[Cord(H8)] = None

        if flag in PROMOTIONS:
            newBoard[cord1] = Piece(self.color, PROMOTE_PIECE(flag))

        elif flag == ENPASSANT:
            newBoard[Cord(cord1.x, cord0.y)] = None

        return newBoard