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

Method getLegalCards

recipes/Python/580811_Uno_TextBased/recipe-580811.py:44–78  ·  view source on GitHub ↗
(self, color, value, zeroChange=False)

Source from the content-addressed store, hash-verified

42 return self.drew
43
44 def getLegalCards(self, color, value, zeroChange=False):
45 self.canSkip = False
46 self.canReverse = False
47 self.canDrawTwo = False
48 self.canDrawFour = False
49 self.canValueChange = False
50 self.canZeroChange = False
51 self.legalCards = []
52 self.wildCards = []
53 self.valueChangeCards = []
54 self.zeroCards = []
55 plusFours = []
56 for card in self.hand:
57 if card.isWild():
58 if card.getValue() == '+4':
59 plusFours.append(card)
60 else:
61 self.wildCards.append(card)
62 elif zeroChange and card.isZero():
63 self.canZero = True
64 self.zeroCards.append(card)
65 elif card.getColor() == color or card.getValue() == value:
66 if card.getColor() != color:
67 self.canValueChange = True
68 self.valueChangeCards.append(card)
69 if card.getValue() == "+2":
70 self.canDrawTwo = True
71 elif card.getValue() == 'R':
72 self.canReverse = True
73 elif card.getValue() == 'X':
74 self.canSkip = True
75 self.legalCards.append(card)
76 if len(self.legalCards) == 0 and len(plusFours) > 0:
77 self.canDrawFour = True
78 self.wildCards += plusFours
79
80 def getValidCards(self):
81 return self.legalCards

Callers 2

thinkMethod · 0.80
nextTurnMethod · 0.80

Calls 5

isWildMethod · 0.80
isZeroMethod · 0.80
getValueMethod · 0.45
appendMethod · 0.45
getColorMethod · 0.45

Tested by

no test coverage detected