def findLegalMoves(self, board): legalMoves = [] for i in range(8): canidateDestinatonCoordinate = self.piecePosition + self.possibleMoves[ i] if (self.isFirstColumnExclusion(self.piecePosition, self.possibleMoves[i]) or \ self.isEighthColumnExclusion(self.piecePosition, self.possibleMoves[i])): continue if (king(canidateDestinatonCoordinate, self.Alliance).isValidCoordinate()): canidateDestinatonTile = board.board[ canidateDestinatonCoordinate] if (canidateDestinatonTile.isTileOccupied() is False): #if no piece there #move legalMoves.append( majorMove(self, board, canidateDestinatonCoordinate)) else: pieceOnTile = canidateDestinatonTile.getPiece() pieceAlliance = canidateDestinatonTile.getPiece( ).getPieceAlliance() if (self.Alliance != pieceAlliance): #capture legalMoves.append( attackMove(self, board, canidateDestinatonTile, pieceOnTile)) return legalMoves.copy()
def findLegalMoves(self, board): legalMoves = [] for i in range(8): destination = self.piecePosition + self.possibleMoves[i] if knight(destination, self.Alliance).isValidCoordinate(): #if valid move #use python dictionary destinationTile = board.board[destination] #print(self.piecePosition, destination) #possibleMoves[i] if (self.isFirstColumnExclusion(self.piecePosition, self.possibleMoves[i])or \ self.isSecondColumnExclusion(self.piecePosition, self.possibleMoves[i])or \ self.isSeventhColumnExclusion(self.piecePosition,self.possibleMoves[i]) or \ self.isEighthColumnExclusion(self.piecePosition, self.possibleMoves[i])): continue if (destinationTile.isTileOccupied() is False): #if no piece there #move legalMoves.append(majorMove(self, board, destination)) else: pieceOnTile = destinationTile.getPiece() pieceAlliance = destinationTile.getPiece( ).getPieceAlliance() if (self.Alliance != pieceAlliance): #capture legalMoves.append( attackMove(self, board, destination, pieceOnTile)) return legalMoves.copy()
def findLegalMoves(self, board): legalMoves = [] for i in range(4): canidateDestinationCoordinate = self.piecePosition while (0 <= canidateDestinationCoordinate < 64): if(self.isFirstColumnExclusion(canidateDestinationCoordinate, self.possibleMoves[i])or \ self.isEighthColumnExclusion(canidateDestinationCoordinate, self.possibleMoves[i])): break canidateDestinationCoordinate += self.possibleMoves[i] if (queen(canidateDestinationCoordinate, self.Alliance).isValidCoordinate()): destinationTile = board.board[ canidateDestinationCoordinate] if (destinationTile.isTileOccupied() is False): # if no piece there # move legalMoves.append( majorMove(self, board, canidateDestinationCoordinate)) else: pieceOnTile = destinationTile.getPiece() pieceAlliance = destinationTile.getPiece( ).getPieceAlliance() if (self.Alliance != pieceAlliance): # capture legalMoves.append( attackMove(self, board, canidateDestinationCoordinate, pieceOnTile)) break return legalMoves.copy()