So before I dive in and start writing code, let’s get some **theory **worked out. Let’s use a simple HTML table to represent the room, with the following notation for fixtures and fittings:

**R**stands for Rogue**E**stands for exit**T**stands for trap**G**stands for guard**X**stands for trap (x marks the stop right)

(0,0) |
|||||

E |
|||||

T |
G |
||||

X |
R |
(5,5) |

So, this is a room containing 36 tiles, set out in a 6 x 6 formation. At the start of the run, the Rogue is positioned at (4, 5). These (x, y) coordinates assume that the top left cell in the table is (0,0), and the cell at the bottom right of the table is (5,5). **Game** r**ule 1 – At the start of the game, the Rogue is placed on a random tile on the edge of a room.** In the room above, there are only 20 legal start positions for the Rogue. All of the legal tiles match one of these four patterns:

- (MIN, MIN),(MIN,MIN+1),…(MIN, MAX)
*(0,0),(0,1),…(0,5)* - (MIN, MAX),(MIN+1,MAX), … (MAX, MAX)
*(0,5),(1,5),…(5,5)* - (MAX,MIN+1), (MAX,MIN+2),…(MAX,MAX-1)
*(5,1),(5,2),…(5,4)* - (MIN,MIN+1), (MIN,MIN+2),…(MIN,MAX-1)
*(0,1),(0,2),…(0,4)*

Thus, for any square/rectangular room comprised of *h x w* tiles, there will be *(2h + 2w)-2* edge tiles which can be used for the Rogue’s start position.

A similar restriction applies to the exit. **Game** r**ule 2 – At the start of the game, the exit is positioned on a random tile on the edge of a room.** An exit in the middle of a room doesn’t make sense, right?