Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def search():
- open_nodes = []
- open_nodes.append([0] + init)
- seen = []
- world_w = len(grid)
- world_h = len(grid[0])
- # the loop ends if open empty (no more nodes to expand)
- while open_nodes:
- print open_nodes
- # 1st item in the queue has the lowest g
- current = open_nodes.pop(0)
- pos = current[1:]
- if pos == goal:
- return current
- g = current[0]
- if pos not in seen:
- seen.append(pos)
- for movement in delta:
- newcell = [pos[0] + movement[0], pos[1] + movement[1]]
- newx = newcell[0]
- newy = newcell[1]
- if (newcell not in seen and
- newcell[0] >= 0 and
- newcell[0] < world_w and
- newcell[1] >= 0 and
- newcell[1] < world_h and
- not grid[newx][newy]):
- open_nodes.append([g + cost] + newcell)
- seen.append(newcell)
- return 'fail'
Advertisement
Add Comment
Please, Sign In to add comment