示例#1
0
文件: Board.py 项目: btrent/knave
 def __init__ (self, setup=False, lboard=None):
     self.data = [dict(enumerate([None]*self.FILES)) for i in xrange(self.RANKS)]
     if lboard is None:
         self.board = LBoard(self.variant)
     else:
         self.board = lboard
     self.board.pieceBoard = self
     
     if setup:
         if lboard is None:
             if setup == True:
                 self.board.applyFen(FEN_START)
             elif isinstance(setup, basestring):
                 self.board.applyFen(setup)
         
         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)
         
         if self.variant == CRAZYHOUSECHESS:
             for color in (BLACK, WHITE):
                 holding = self.board.holding[color]
                 for piece in holding:
                     for i in range(holding[piece]):
                         self[self.newHoldingCord(color, 1)] = Piece(color, piece)
示例#2
0
文件: logic.py 项目: btrent/knave
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)
示例#3
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)
示例#4
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)
示例#5
0
 def __init__ (self, setup=False):
     self.data = [[None]*8 for i in xrange(8)]
     self.board = LBoard()
     
     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)