MCPcopy Create free account
hub / github.com/ActiveState/code / Deck

Class Deck

recipes/Python/580811_Uno_TextBased/recipe-580811.py:337–381  ·  view source on GitHub ↗

shuffle' (bool) : shuffle deck.

Source from the content-addressed store, hash-verified

335 return self.mainMenuElements
336
337class Deck():
338 ''''shuffle' (bool) : shuffle deck.'''
339
340 colors = ('red','yellow','green','blue')
341 values = ('0','1','2','3','4','5','6','7','8','9','X','R','+2')
342
343 def __init__(self, populate):
344 '''Initializes proper deck of 108 Uno Cards.'''
345 self.deck = []
346 if populate:
347 self.populate(True)
348
349 def __getitem__(self, index):
350 return self.deck[index]
351
352 def populate(self, shuffle=True):
353 for color in self.colors:
354 for value in self.values:
355 self.deck.append(Card(color, value))
356 if value != '0':
357 self.deck.append(Card(color, value))
358 for i in range(4):
359 i #unused
360 self.deck.append(Card('wild', '+4'))
361 self.deck.append(Card('wild', 'W'))
362 if shuffle:
363 self.shuffle()
364
365 def __iter__(self):
366 return iter(self.deck)
367
368 def __len__(self):
369 return len(self.deck)
370
371 def draw(self):
372 return self.deck.pop()
373
374 def place(self, card):
375 return self.deck.append(card)
376
377 def insert(self, card):
378 self.deck.insert(0, card)
379
380 def shuffle(self):
381 random.shuffle(self.deck)
382
383class ComputerPlayer(Player):
384

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected