Skip to content

Instantly share code, notes, and snippets.

@rodrickbrown
Last active August 29, 2015 14:03
Show Gist options
  • Save rodrickbrown/bab200d0ecc8440ad217 to your computer and use it in GitHub Desktop.
Save rodrickbrown/bab200d0ecc8440ad217 to your computer and use it in GitHub Desktop.
Rummikub
import random
class Rummikub(object):
decks = [0,1]
colors = ["red", "blue", "black", "orange"]
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
jokers = ["black", "red"]
bag = []
def __init__(self, players):
self.players = players
print('----- Intialzing game with {0} players -----'.format(players))
for deck in self.decks:
for color in self.colors:
for number in self.numbers:
self.bag.append({"deck":deck, "color":color, "number":number})
[ self.bag.append(joker) for joker in self.jokers ]
def dealTiles(self, n):
tiles = []
for c in range(n):
tiles.append(self.bag.pop(random.randint(0, len(self.bag)-1)))
return tiles
game = Rummikub(4)
print("Size of bag is now {0}".format(len(game.bag)))
print(game.dealTiles(2))
print("Size of bag is now {0}".format(len(game.bag)))
--- EOF ---
/usr/local/bin/python3.4 /Users/rbrown/PycharmProjects/untitled/Main
----- Intialzing game with 4 players -----
Size of bag is now 106
[{'color': 'blue', 'deck': 1, 'number': 13}, {'color': 'red', 'deck': 1, 'number': 2}]
Size of bag is now 104
Process finished with exit code 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment