Skip to content

Instantly share code, notes, and snippets.

@objectiveSee
Last active December 22, 2015 14:58
Show Gist options
  • Save objectiveSee/6488719 to your computer and use it in GitHub Desktop.
Save objectiveSee/6488719 to your computer and use it in GitHub Desktop.
Optimal card shuffling and dealing algorithm for a multi-player game server.
THE PROBLEM:
A game server deals hands of cards to each player in a multi-player game.
The ideal user experience is for players to be able to play multiple
games (with random opponents) and not be dealt repeated cards until
they have seen most of the cards in the deck.
CONDITIONS:
1. Each card has a unique id.
2. Each player has 7 cards in their hand. At the end of each round the
players are dealt new cards to fill their hands.
3. Each card is never dealt more than once in any given game.
4. A card can not be dealt that any player has already been
dealt (in any game past or present), unless it is impossible to satisfy
this condition.
5. Players may be in multiple games which may or may not be simultaneous.
6. If it is impossible to satisfy all conditions then a card can be
dealt twice.
VARIABLES:
Number of cards in Deck, N ~= 500.
Number of players in a game, P = 3 to 10
Number of rounds in a game, R ~= P * 5.
TECHNICAL CONSIDERATIONS:
* The shuffling is done by a Node.js server and must be close to real time :D
* There is a Mongo document for each game and each user.
* This question is for improving the Evil Apples (iPhone App) game server.
Contact @TopWobble or @EvilApplesApp on Twitter with questions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment