def __init__(self, boardArr, carCh): # takes the board and the car character if misc.isCarInBoard(boardArr, carCh) == False: print 'Car Constructer __init__() ', CarNotIn return self.carChar = carCh self.allCoordinates = misc.findAll(boardArr, carCh) self.end1 = self.allCoordinates[0] # end1 comes before end2 self.end2 = self.allCoordinates[len(self.allCoordinates)-1] self.length = len(self.allCoordinates) if self.end1[1] == self.end2[1]: # checking for orientation # if y coordinate is same self.orientation = 'vertical' elif self.end1[0] == self.end2[0]: self.orientation = 'horizontal'
def next_Board_for_car(self, carCh): CLOSED = [] # list to store the states that have already been achieved if misc.isCarInBoard(self.boardArr, carCh) == False: print 'next_for_car(): ', CarNotIn car = Car.Car(self.boardArr, carCh) cloneBoard = Board() #car.printDetails() if car.orientation == 'horizontal': directions = ['left', 'right'] for direction in directions: for i in range(1, 5): cloneBoard.clone(self) newBoardArr = cloneBoard.moveCar(carCh, direction, i) #cloneBoard.printBoard() if newBoardArr not in CLOSED and newBoardArr is not None: #print newBoardArr #CLOSED.append(cloneBoard) newClone = Board() newClone.createBoard(stringifyBoardArr(newBoardArr)) CLOSED.append(newClone) elif car.orientation == 'vertical': directions = ['down', 'up'] for direction in directions: for i in range(1, 5): cloneBoard.clone(self) newBoardArr = cloneBoard.moveCar(carCh, direction, i) #cloneBoard.printBoard() if newBoardArr not in CLOSED and newBoardArr is not None: #print newBoardArr #CLOSED.append(cloneBoard) newClone = Board() newClone.createBoard(stringifyBoardArr(newBoardArr)) CLOSED.append(newClone) #CLOSED.remove(None) #print CLOSED #misc.printCLOSED(CLOSED) #for board in CLOSED: #print board #board.printBoard() #misc.printBoardArr(board) #for row in board: #print row #print return CLOSED