Beggar My Neighbour
I have always wanted to know if the card game “Beggar my Neighbour” can ever get into an infinite loop. I have also been wanting to experiment with ASP.NET core and containerised microservices, so I wrote a distributed system to find the longest games of “Beggar my Neighbour”.
Basic algorithm for beggar my neighbour
- Deal all the cards in the deck face down. No players look at their cards or shuffles their hand.
- Each player plays the top card from their hand and places it in a pile face up until a picture card is played.
- When a picture card is played, the next player has to pay: 1 card for a Jack; 2 for a Queen; 3 for a King; 4 for an Ace.
- If another picture card is played while the player is paying for the previous picture card then the next player must pay for the new picture card.
- When no cards are owed (i.e. the picture card has been paid for without another picture card being played) then the player that played the picture card gets the pile and places it at the bottom of their hand with the cards face down. This player then plays a new card starting a new pile.
- As soon as a player plays their last card they are out and the next player continues from where the previous player was (e.g. if the previous player still had 2 cards left to play then the new player must pay those 2 cards.)
- The last player in the game wins.
Plays virtual games of “Beggar my Neighbour” and submits games to the scoreboard API service. Can be run remotely and submits scores without authentication.
Back end for the scoreboard. Stores the current high scores. Receives new scores from beggar.compute instances. Retrieves scores for the web front end.
Runs alongside the scoreboard API Service to verify received games from anonymous clients
Communicates with the scoreboard using RabbitMQ
Web front end for the scoreboard presents and filters scores submitted to the scoreboard API