Part of Code Golf Advent Calendar 2022 event. See the linked meta post for details.
Happy Hanukkah!
A beloved Hanukkah tradition for many, the game of Dreidel (s'vivon in Hebrew) is a betting game (for money or for chocolate gelt (coins)) centered on the titular spinning tops called dreidels. Dreidels have four sides: נ (nun), ג (gimel), ה (hei), and ש (shin), an acronym for the phrase "neis gadol haya sham": a great miracle happened there, referring to the famous Hanukkah miracle.
The game starts with an ante of one coin put forth by all players. Then, players take turns spinning the dreidel and lose or gain money according to the following rules:
- נ (nun): Do nothing
- ג (gimel): Win all the money in the pot
- ה (hei): Win half the money in the pot, rounding up
- ש (shin): Add one coin to the pot
If at any point the pot becomes empty, all players put forth one coin. If a player must put forth a coin and they have none, they are out of the game. The game ends when players agree to stop or when only one player is remaining.
Task
Your task is to implement the game of Dreidel.
Input:
- (mapping: str -> int) A number of players, guaranteed to be ≥2, each represented by a string. Each player maps to the starting number of coins for that player, guaranteed to be ≥1.
- (int) The number of rounds, guaranteed to be ≥1. (In each round, every player who's still in the game will spin the dreidel once).
Output:
- (mapping: str -> int) Each player and their corresponding final number of coins at the end of the game.
Rules:
- Standard rules of code-golf apply. Shortest answer in bytes wins!
- Dreidel outcomes must be random, and must appear with the same probability (25% for each outcome).
- Any reasonable form of input or output is allowed. For instance, to represent the mapping of players to coins, one can use a Python-style dictionary, an array of pairs, etc. The mapping need not have a consistent ordering.
- All players must be represented in the output, even if they have no money left.
- You can use whatever order for the players within each round is easiest, as long as each player who's still in the game spins once per round.
Notes:
- It is not guaranteed that the total number of coins at the end of the game is equal to the total number of coins at the beginning of the game (there may be some left over in the pot.)
Examples: (bear in mind that results are random)
>>> dreidel({"Abraham": 5, "Batya": 5, "Claire": 5}, 3)
{"Abraham": 3, "Batya": 8, "Claire": 4}
>>> dreidel({"David": 3, "Eliana": 9, "Fievel": 2, "Gabriella": 2}, 15)
{"David": 0, "Eliana": 16, "Fievel": 0, "Gabriella": 0}