MCPcopy Index your code
hub / github.com/geekcomputers/Python / canPlay

Function canPlay

BoardGame-CLI/uno.py:98–112  ·  view source on GitHub ↗

Return True if any card in playerHand is playable on a discard with given colour and value. >>> canPlay('Red','5',['Red 3','Green 5']) True >>> canPlay('Blue','7',['Green 1']) False

(colour: str, value: str, playerHand: List[str])

Source from the content-addressed store, hash-verified

96
97
98def canPlay(colour: str, value: str, playerHand: List[str]) -> bool:
99 """
100 Return True if any card in playerHand is playable on a discard with given colour and value.
101
102 >>> canPlay('Red','5',['Red 3','Green 5'])
103 True
104 >>> canPlay('Blue','7',['Green 1'])
105 False
106 """
107 for card in playerHand:
108 if "Wild" in card:
109 return True
110 elif colour in card or value in card:
111 return True
112 return False
113
114
115# --- Global deck and initial setup ---

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected