def moves(self): # case for if no piece is select if self.selectedPiece == False: print("No Piece Select") return piece = Piece(self.board, self.selectedPiece) # print(piece.getMoves()) return piece.getMoves()
def getAllMoves(self, color): x = 0 y = 0 movesPerPiece = [] for i in self.board: for j in i: if str(self.board[x][y])[0] == color: self.selectedPiece = [x, y] # return the coordinates board = self.board selectedPiece = self.selectedPiece piece = Piece(board, selectedPiece) moves = piece.getMoves() movesPerPiece += [[str(self.board[x][y]), moves]] y += 1 y = 0 x += 1 self.selectedPiece = False return movesPerPiece
def check(self, map: dict = None, player: bool = None, move: Tuple = None) -> bool: map = map if map else self.map player = self.player if player == None else player if move != None: map = map.copy() map[move[1][0], move[1][1]] = map[move[0][0], move[0][1]] map[move[0][0], move[0][1]] = Piece.EMPTY return len([ move for x, y in map for move in [(_, (ax, ay)) for (_, (ax, ay)) in Piece.getMoves(x=x, y=y, map=map, player=not player, logs=self.logs, casteling=False) if map[ax, ay].hasSameTypeAs(Piece.P1_KING)] ]) > 0
def findMove(self): # max level depth if self.level == 4: return board = self.board[:] # store current board # create new board instance # boardClass = Board(setBoard) # boardClass.printBoard() # get all moves for board for color x = 0 y = 0 movesPerPiece = [] # search over all board for i in board: for j in i: piece = board[x][y] # check side case if str(piece)[0] == self.botColor: # set selectedPiece selectedPiece = [x, y] # get all the moves pieceClass = Piece(board, selectedPiece) moves = pieceClass.getMoves() # print list movesPerPiece += [[str(board[x][y]), moves]] print("-------------" + piece + "-------------") # boardClass.setSelectedPiece(selectedPiece) # print(boardClass.selectedPiece) # create boards for each move for move in moves: print("-------------" + str(move) + "-------------") # # boardClass.setBoard(board) # start with current bord # boardClass.move(move[0], move[1]) # make move # the move space moveSpace = board[move[0]][move[1]] # weight score if moveSpace != False: pass # make the move board[move[0]][move[1]] = str(piece) board[x][y] = False # clear the old space for i in self.setBoard: print(i) # reset board board = self.setBoard[:] # self.board = self.setBoard # board[move[0]][move[1]] = self.board[self.selectedPiece[0]][self.selectedPiece[1]] # board[self.selectedPiece[0]][self.selectedPiece[1]] = False # print(board) # # boardClass.printBoard() # board = Board(setBoard) y += 1 y = 0 x += 1 # self.selectedPiece = False print(movesPerPiece)