Bob got kidnapped and is stuck in a maze. Your job is to help him find a way out. But since it is a very dark and scary maze, he can't see anything. He can only feel walls when he runs in to it, and knows when he has found the exit, but doesn't know anything more that.
Since he has to run your program by memory, it has to be as short as possible.
Note: I took this problem from http://acmgnyr.org/year2016/problems.shtml, but adapted it slightly, and wrote the judge program/test cases myself.
Specification
- This is an interactive problem, so you program will output moves to stdout, and take in responses from stdin.
- Your program can output one of the moves
right
,left
,down
,up
. - It will then get as input one of the following:
wall
- this means that Bob has hit a wall. Bob will stay in the same place.solved
- Bob has found the exit! Your program should now also exit without printing anything else.ok
- Bob was able to move in the given direction.
- If the maze has no exit, your program should output
no exit
to let Bob know that he should give up. Your program should then exit without printing anything else. - Since Bob is in a hurry to get out, your program should not make any extraneous moves. In other words, your program is not allowed to move in the same direction from the same square twice.
- This is code-golf, so shortest program wins!
Examples
In the following examples, S
is the starting square, X
is the exit, #
is a wall, and spaces are valid squares. Since there is no single correct answer, these are just example runs of a solution. Also note that the drawings of the maze are just there for you to see, and your program will not get them as input.
########
#S #
###### #
# #
#X#
right
ok
right
ok
right
ok
right
ok
right
ok
right
wall
down
ok
right
wall
down
ok
right
wall
down
solved
#####
# S #
#####
right
ok
right
wall
down
wall
up
wall
left
ok
down
wall
up
wall
left
ok
down
wall
up
wall
left
wall
right
ok
no exit
solved
###############################
#S #
############## ### #
# #X# #
# #
##################
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
ok
right
wall
down
ok
right
wall
down
ok
right
wall
down
ok
right
wall
down
wall
left
ok
down
wall
up
ok
up
ok
left
ok
down
ok
down
ok
down
wall
left
ok
down
wall
up
ok
up
ok
left
ok
down
ok
down
ok
down
wall
left
ok
down
wall
up
ok
up
ok
left
wall
down
ok
left
wall
down
ok
left
ok
down
wall
up
wall
left
ok
down
wall
up
solved
Checker Program
- I have written a solution checker in Python. You can find it at https://gist.github.com/Maltysen/f0186019b3aa3812d812f8bb984fee19.
- Run it like
python mazechecker.py ./mazesolver
. - It will test your program on all the mazes in a folder called
mazes
. - The mazes are in separate files in the same format from above.
- It checks all the conditions listed above, and notifies you if your solution violates any.
- You can have it print additional diagnostic info with
python mazechecker.py -d ./mazesolver
. - You can find a zipped
mazes
folder here. You can also add your own to it if you want.
solved
when outputtingno exit
? If so please state so in the rules, not only in the test cases! \$\endgroup\$x,y
and goup
, with respondwall
, thenright
with again respondwall
, may I then tryup
again, or are onlyleft
anddown
still available since I haven't moved from this square yet? \$\endgroup\$