Exemplo n.º 1
0
def getHitlistFor(piece, board, isWhite):
   hitlist = []
   t = Piece.getType(piece)
   l = board.locationOfPiece(piece)
   if not l:
      return []
   if t == 'R':
      hitlist.extend( piecesInHorzView(l, board))
   elif t == 'N':
      hitlist.append( board.pieceAt( (l[0]+1, l[1]+2) ) )
      hitlist.append( board.pieceAt( (l[0]-1, l[1]+2) ) )
      hitlist.append( board.pieceAt( (l[0]+1, l[1]-2) ) )
      hitlist.append( board.pieceAt( (l[0]-1, l[1]-2) ) )
      hitlist.append( board.pieceAt( (l[0]+2, l[1]+1) ) )
      hitlist.append( board.pieceAt( (l[0]+2, l[1]-1) ) )
      hitlist.append( board.pieceAt( (l[0]-2, l[1]+1) ) )
      hitlist.append( board.pieceAt( (l[0]-2, l[1]-1) ) )
   elif t == 'B':
      hitlist.extend( piecesInDiagonalView(l, board))
   elif t == 'Q':
      hitlist.extend( piecesInHorzView(l, board))
      hitlist.extend( piecesInDiagonalView(l, board))
   elif t == 'K':
      for a in range(-1,2):
         for b in range(-1,2):
            if (not (a == 0)) or (not (b == 0)):
               hitlist.append( board.pieceAt( (l[0]+a, l[1]+b) ) )
   else: #pawn
      if isWhite:
         hitlist.append( board.pieceAt( (l[0]-1, l[1]+1) ) )
         hitlist.append( board.pieceAt( (l[0]+1, l[1]+1) ) )
      else:
         hitlist.append( board.pieceAt( (l[0]-1, l[1]-1) ) )
         hitlist.append( board.pieceAt( (l[0]+1, l[1]-1) ) )
   s = set(hitlist);
   return [p for p in s if not p == None and p >= 0 and not Piece.isWhite(p) == isWhite]
Exemplo n.º 2
0
 def movesForPiece(self, piece):
    if Piece.isWhite(piece):
       return [move for move in self.whiteMoves if move.piece == piece]
    else:
       return [move for move in self.blackMoves if move.piece == piece]
Exemplo n.º 3
0
 def movesForPiece(self, piece):
    if Piece.isWhite(piece):
       return [move for move in self.whiteMoves if move.piece == piece]
    else:
       return [move for move in self.blackMoves if move.piece == piece]