This game is played with "pencil-and-paper" but on the other hand it resembles various role-playing table games.
I do not know who invented it but those of my acquaintances who know it, generally were somehow related to
locally famous "Physical-Mathematical School" # 239
in St-Petersburg.
Game is played among elected "game master" who creates maze and conducts the further process - and general players who do not know the maze and suggest moves, listen to the master's answers and gradually figure out the map.
In this problem you are to create a code for "game master" which, given some maze configuration and sequence of player's moves, outputs the path (string of the types of cells visited). Actually it is a kind of intro to some advanced problem (of which I'm yet unsure).
We'll use a variation of original rules (anyway I'm not sure that some "true" or "official" rules exist).
Here is a Labyrinth (well, maze), usually square with square cells - which have some unusual properties, making travelling between them a bit confusing. Normally players propose moves "blindly", guided by game master and try to find a treasure or to kill each other. However just mapping the maze is a great puzzle by itself. You may try playint it with your friends or relatives to see what I mean. Or write the code for maze generator and attach to the "game master" you are going to create in this task...
Possible cell types are (more details on each of them are given further):
island
or safe spot
- when player gets there, nothing special happensriver
- every such cell has a direction in which player is drawn (to the next sell)bog
- almost like island
but has one side impassablecave
or pit
- acts like teleporter - when player falls into it, he or she is transferred to other entranceestuary
- end of the river, in most aspects it is like island
.wall
- completely impassable cell (in original game walls are between cells, but it is unnecessary complication)Player starts at one of the islands (chosen randomly) so there is no controversy of
whether anything happens at this first cell. Moves are possible in four directions N
(row up), S
(row down),
W
(column left) or E
(column right).
If in the chosen direction leads to the cell with Wall
, player remains where he/she was (game master
announces "wall"). This situation is the same when chosen direction leads out of the borders of the maze
(so borders are indistinguishable from inner wals).
If player is in the bog and tries to leave the cell in the "swamped" direction, position also is not changed, but game master doesn't specially notifies of this - instead just saying that player again appears in a bog. Thus such situation may be confused with two bog cells adjacent. Any bog cell has exactly one impassable side. If player tries to leave bog at swamped direction and at next cell there is a wall, then the "bog" condition is checked before "wall" condition, which is logical - he/she can't leave the current cell to run into the wall in the next one. But for the current problem this is not important.
If player gets into the river
, he/she is immediately shifted one cell in the direction of the current. River
cells are generated in chains, every chain ending with estuary
. Current does not affect the player when
travelling downstream or upstream. I.e. when player wades the river by direction of the current river cell, or
moves to the cell which is preceding in the river sequence - no shift occurs. Master announces if the
player is drawn by current and where he/she appears then, e.g. "you fall into the river, you are
drawn by current to the next cell, which is river/estuary". If player steps from one river to another, or even
to the same river but the cell different than upstream/downstream - current works as usually.
In this regard estuary
differs from the simple island
- if player goes from estuary to the river which
flows in this estuary, current doesn't have an effect. All rivers have exactly one estuary. There is no
branching or merging of rivers.
Caves are organized into one or several chains, i.e. they have some numbers, so that when player steps onto
the cell with cave#1
master says "you have fallen into the cave and climb out at some different place" - but
actually it is predetermined cave#2
cell - in other words falling into the same pit always brings player to
the same other entrance. Falling into the last cave of a chain brings player to the first cave in the chain
again.
Let's see an example:
b> o w r1v
bv r1v r1< r1<
y10 e1 bv y11
y20 w y12 o
Here b
means "bog" and "arrow" shows impassable direction (where its point is), o
marks islands, w
is for wall
, r
for river, with "arrow" showing current (and pointing to next river cell in chain); y
is
for cave/pit, the last digit of which is the index in the given cave chain. Both rivers, estuaries and caves
have digit denoting chain itself in the middle position. I.e. y12
means "cave #2
of chain 1
". Actually
chains digits are not necessary for rivers but they help visually.
Suppose, 1st
player (Alice) starts at the lower-right corner (row=3, col=3)
. The 2nd (Bob) starts at the
second cell of the topmost row (row=0, col=1)
.
player & direction master's comment
Alice: south wall
Bob: west bog
Alice: north cave, you emerged at other place (at y12 but it is not said)
Bob: east bog (swamped direction, he does not move, but it is not said)
Alice: west wall
Bob: south bog (just another bog cell, confusing poor Bob)
Alice: north bog
Bob: south bog (swamped direction again)
Alice: north river, you are drawn by current to the next cell which is also river
Bob: east river, you are drawn by current to the next cell which is estuary
Alice: north island
Thus Alice got to the island from where Bob have started while he mainly was trying to find his way out of two bog cells.
The problem is easily described by input and output. Input contains 2 main parts - labyrinth map and several "walks" (as if by several players), generated randomly.
Input starts with 7
lines denoting the map, there are 7
cells in each of these lines. There could
be one or more spaces between cells simply to improve readability.
Then 8th
line has a single value P
- number or player "walks".
Next there are P
lines describing these walks (one line per "walk") - they have two integers first, row and
column of the start (zero-based) - then a sequence of N, S, W, E
letters - commands given by player.
Answer should contain exactly P
sequences of letters o
, r
, y
, e
, b
- describing sequence
of cells visited on each of player walks. Do not include starting o
(for it is evident).
Example
y12 o b< y11 o y22 b<
r2v o o o b< y21 o
r2> r2> r2v o o w o
w w r2v r5> r5v r5> e5
y10 o e2 b^ r5v r5^ b^
o o r3> r3v r5> r5^ y20
o o r3^ r3> e3 o y23
4
2 3 SWNSS
5 0 NWSSWEES
1 2 EWWSWEWES
1 3 SWSEWNENNS
rrorr yborrreb ooorrrrrr oreberrobo