Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

https://imgur.com/VBsht

  while (true) do
    if not (wall to the left) then
      (turn left)
    while (wall ahead) do
      (turn right)
    (move forward)
This uses the general maze-solving logic of following the outer wall in one direction until you find the exit. It never turns then turns back or runs into a wall.


This will not solve general mazes. S=Start, G=Goal, O=Empty

    O-O-O
    |   |
    O S-O-G
    |   |
    O-O-O


I should have been more clear. That's the general logic for mazes where both the entrance and exit are on the outer edge.


Nice. I didn't realize you could parameterize the conditionals so I did this (bumps into walls):

while (true) do if(wall ahead) then turn left else move forward turn left if(wall ahead) turn right




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: