Trapped in the amber of the moment

Rooms have traps. We have established that. All well and good. But trap-layers do not sprinkle their work around willy-nilly. A seasoned engineer would place his camouflaged pits, poison needle traps and swinging blocks close to the obvious points of interest, namely (a) the treasure and (b) the way out.






So far, when creating a room, we have allocated the trap (or traps) to random tiles.  From now on, the closer a tile is to a treasure tile or an exit tile, the more likely it is to be trapped. Here. This diagram should clear things up.












In the digram above, the probability of a tile being trapped is shown using colour. The treasure tile and the exit tile have a high chance of being trapped. The probability of a tile being trapped decreases the further you get away from these two ‘hot areas’.

How does this affect the trap placement algorithm? I am glad you asked. If you look at the diagram above, you will see that there are 5 different levels of trap likelihood, as follows:




Now, lets attach some numbers to these 5 different levels, like so:

  • Very high: 1 in 5 tiles are trapped (i.e. probability of 0.2)
  • High: 1 in 10 tiles are trapped (i.e. probability of 0.1)
  • Medium: 1 in 20 tiles are trapped (i.e. probability of 0.05)
  • Low: 1 in 40 tiles are trapped (i.e. probability of 0.025)
  • Very Low: 1 in 80 tiles are trapped (i.e. probability of 0.0125)

How do we use these trap likelihood levels? I am glad you asked. Assume we have a room with 100 tiles. If every tile in this room has an equal chance of being trapped, we can do this:

  1. Place the 100 Tile objects in a list.
  2. Generate a random number between 0 and 99.
  3. Select the Tile object whose index matches the random number

When the tiles in the room have an unequal chance of being trapped, we must modify this slightly. We do this by rigging the lottery in favour of the higher likelihood tiles. I will write the code tomorrow, but basically this means I would clone the Tile with a very high likelihood of being trapped, giving it 16 entries in the lottery. Tiles with a high chance would get cloned 8 times, and so on. It will work out, I promise 🙂