Ludii Forum
Map Function - Printable Version

+- Ludii Forum (https://ludii.games/forums)
+-- Forum: Questions (https://ludii.games/forums/forumdisplay.php?fid=13)
+--- Forum: About the Ludii Grammar (https://ludii.games/forums/forumdisplay.php?fid=15)
+--- Thread: Map Function (/showthread.php?tid=19)



Map Function - tylerkuper13 - 01-24-2020

I'm currently trying to create a game in ludii currently for a project based on the game senet and I can't figure out what map is for.

For example: (map{{0 5}})


RE: Map Function - DennisSoemers - 01-25-2020

Here's the line you mentioned in your post, from the Senet game description:

Code:
(equipment
{
  ...
  (map { {0 5} })
  ...
}
)

On its own, that line does not yet have any effect on the game's rules. It just defines that we have some "map" or "mapping" that maps the number "0" to "5". Later on in the game description, you'll see that we also use "(map ...)" expressions when defining how pieces move.

Those later occurrences of "(map ...)" take the number inside them as a "key", and replace it with the value that any map defined in the equipment maps to for the given key.

Specifically, in the Senet rules we have "(map (sumDice))". If the sum of all the rolled dice is equal to 0, we map this to a value of 5, because the map in the equipment states that the value 0 should be replaced by 5. This basically means that, after getting 0 pips on all of the D2s that we roll in (this reconstruction of) Senet, we're allowed to move a distance of 5.

If the sum of dice equals 1, 2, 3, or 4, we simply use that number and don't map it to anything; this is because the map as defined in the equipment doesn't have any mappings for those values. It will replace the key with a value if there is a mapping defined for that key (i.e. 0 --> 5), but will just return the original key again if nothing has been defined.


RE: Map Function - tylerkuper13 - 01-29-2020

Thank you! That clears up things a lot.