def move(movingNode, swappingNode, childGrid, grid): movingNodeOriginal = movingNode.value originalmovingNode = [] for row in range(0, len(grid)): for column in range(0, len(grid[row])): if grid[row][column] is movingNode.value: grid[row][column] = swappingNode.value originalmovingNode = [row, column] else: if grid[row][column] is swappingNode.value: if [row, column] is not originalmovingNode: grid[row][column] = movingNodeOriginal print(grid) childGrid = gridToNodes(grid) return [childGrid, grid]
def move(movingNode, swappingNode, childGrid, grid): movingNodeOriginal = movingNode.value originalmovingNode = [] for row in range(0, len(grid)): for column in range(0, len(grid[row])): if grid[row][column] is movingNode.value: grid[row][column] = swappingNode.value originalmovingNode = [row,column] else: if grid[row][column] is swappingNode.value: if [row,column] is not originalmovingNode: grid[row][column] = movingNodeOriginal print(grid) childGrid = gridToNodes(grid) return [childGrid, grid]
originalmovingNode = [row,column] else: if grid[row][column] is swappingNode.value: if [row,column] is not originalmovingNode: grid[row][column] = movingNodeOriginal print(grid) childGrid = gridToNodes(grid) return [childGrid, grid] grid = [[4,6,2,14],[15,8,13,1],[10,5,9,12],[7,11,16,3]] grid2 = [[1, 2, 3, 4], [15, 6, 14, 8], [9, 10, 13, 12], [7, 11, 5, 16]] goalGrid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]] newgrid = gridToNodes(grid) def getGoal(movingNode, grid, goalGrid): for r in range(0, len(grid)): for c in range(0, len(grid)): if movingNode.value is goalGrid[r][c]: goal = Node(c+1,r+1, grid[r][c]) return goal def getNextmove(movingNode, nodeGrid): goalNode = getGoal(movingNode,grid,goalGrid) nextSpot = aStar(movingNode, goalNode, newgrid) return nextSpot
originalmovingNode = [row, column] else: if grid[row][column] is swappingNode.value: if [row, column] is not originalmovingNode: grid[row][column] = movingNodeOriginal print(grid) childGrid = gridToNodes(grid) return [childGrid, grid] grid = [[4, 6, 2, 14], [15, 8, 13, 1], [10, 5, 9, 12], [7, 11, 16, 3]] grid2 = [[1, 2, 3, 4], [15, 6, 14, 8], [9, 10, 13, 12], [7, 11, 5, 16]] goalGrid = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] newgrid = gridToNodes(grid) def getGoal(movingNode, grid, goalGrid): for r in range(0, len(grid)): for c in range(0, len(grid)): if movingNode.value is goalGrid[r][c]: goal = Node(c + 1, r + 1, grid[r][c]) return goal def getNextmove(movingNode, nodeGrid): goalNode = getGoal(movingNode, grid, goalGrid) nextSpot = aStar(movingNode, goalNode, newgrid)