9
5
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
I was thinking about trying this one---maybe as a curses exercise---but I find the rigid specifications for the interaction environment unappealing (I mean, why "continue" and not just a prompt?!? Why 4--5 character directions; I want to play nethack, man!) and the "both parts on the standard input" requirement to be nonsensical. – dmckee --- ex-moderator kitten – 2011-02-13T02:58:48.627
@dmckee: It easier to interact with an AI player. I will change to read the maze from file. – Alexandru – 2011-02-13T11:10:43.777
This blog has excellent articles on maze generation using various and mixed algorithms
http://weblog.jamisbuck.org/
Check out the growing tree algorithm in-particular
http://weblog.jamisbuck.org/2011/1/27/maze-generation-growing-tree-algorithm
@Alexandru: What are we using to generate our mazes? Can we use other peoples maze algorithms (obviously with due credit)? Or must we complete your first assignment? – snmcdonald – 2011-02-02T15:06:49.980
@snmcdonald: Fixed typo. Use other people's mazes. Remember that the engine reads the maze from standard input. – Alexandru – 2011-02-02T15:07:02.787
I'm confused as to how both the maze and the user interaction come from standard input. Is the user supposed to type in his maze and then solve it? Kinda defeats the purpose of only showing a portion of the maze... – Keith Randall – 2011-02-04T04:22:03.900
You can build an app (this task is left for another question) on top of it to separate maze input from commands input. – Alexandru – 2011-02-04T11:46:00.680