Write a function comp10001huxxy_valid_table() which takes a single argument: groups , a list of…
Write a function comp10001huxxy_valid_table()
which takes a single argument:
groups
, a list of lists of cards (each a 2-element string, where the first letter is the card value and the second letter is the card suit, e.g.'3H'
for the 3 of Hearts), where each list of cards represents a single group on the table, and the combined list of lists represents the combined groups played to the table.-
Your function should return a
bool
, which evaluates whether the table state is valid or not. Recall from the rules of the game that the table is valid if all groups are valid, where a group can take one of the following two forms:-
an N-of-a-kind (i.e. three or more cards of the same value), noting that in the case of a 3-of-a-kind, each card must have a unique suit (e.g.
['2S', '2S', '2C']
is not a valid 3-of-a-kind, as the Two of Spades has been played twice), and if there are 4 or more cards, all suits must be present. -
a run (i.e. a group of 3 or more cards, starting from the lowest-valued card, and ending with the highest-valued card, forming a continuous sequence in terms of value, and alternating in colour; note that the specific ordering of cards in the list is not significant, i.e.
['2C', '3D', '4S']
and['4S', '2C', '3D']
both make up the same run.Example function calls are as follows:
>>> comp10001huxxy_valid_table([])
True
>>> comp10001huxxy_valid_table([[‘AC’]])
False
>>> comp10001huxxy_valid_table([[‘AC’, ‘2S’]]) # run too short
False
>>> comp10001huxxy_valid_table([[‘AC’, ‘2S’, ‘3H’]]) # run doesn’t alternate in colour
False
>>> comp10001huxxy_valid_table([[‘AC’, ‘2S’, ‘4H’]]) # values not adjacent
False
>>> comp10001huxxy_valid_table([[‘AC’, ‘2H’, ‘3S’]])
True
>>> comp10001huxxy_valid_table([[‘3C’, ‘AS’, ‘2H’]]) # test unsorted run
True
>>> comp10001huxxy_valid_table([[‘0C’, ‘JH’, ‘QS’, ‘KH’, ‘9D’]])
True
>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’]]) # n-of-kind too short
False
>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2C’]]) # same suit twice for 3-of-kind
False
>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’, ‘2C’]]) # same suit twice for 4-of-kind
False
>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’]])
True
>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’, ‘2D’]])
True
>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’, ‘2D’, ‘2S’]])
True
>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’, ‘2D’, ‘2S’], [‘0D’, ‘9C’, ‘8H’]])
True
-
Needs help with similar assignment?
We are available 24x7 to deliver the best services and assignment ready within 3-4 hours? Order a custom-written, plagiarism-free paper

