This is a follow up of Print a maze question. If you like this question, please add more maze generation algorithms ;).
For this task you'll have to implement a game engine for one player who must find the treasure in a maze and get out of the dungeon.
The engine starts by reading the maze from standard input followed by a line containing a a file given as argument in the command line. Next the player .
(dot)@
is placed in a random location on the map. Then engine starts interacting with the player through standard io:
Commands from engine to player:
continue
: Game not finished. The surroundings are printed followed by a.
. Player is represented by@
character. Unobservable cells are represented by?
.finished
: Game finished. The number of steps is printed and the game stops.
Commands from player to engine:
north
: Moves player up.south
: Moves player down.west
: Move player left.east
: Move player right.
Any invalid command (such as hitting a wall) from player is ignored, but still counted. You are free to define the surroundings to your liking.
- Points for the shortest code.
- Points for complex surroundings (e.g. print large regions and replace cells that are not visible by
?
). - No points for code that doesn't respect the io format
Example:
In this example the surroundings is defined as the 3x3 cell with the player in the middle.
$ cat maze
+-+-+
|#|
| |
+---+
$ python engine.py maze
|#
@
---
.
east
|#|
@|
--+
.
north
+-+
|@|
|
.
south
|#|
@|
--+
.
west
|#
@
---
.
west
|
|@
+--
.
north
+-+
@|
|
.
west
finished
7