Write a function comp10001huxxy_valid_play() which takes five arguments.

Write a function comp10001huxxy_valid_play() which takes five arguments.

[ad_1]

Write a function comp10001huxxy_valid_play() which takes five arguments:
play, a 3-tuple representing the play that is being attempted; see below for details;
play_history, a list of 3-tuples representing all plays that have taken place in the game so far (in chronological order); each 3-tuple is based on the same structure as for play;
active_player, an integer between 0 and 3 inclusive which represents the player number of the player whose turn it is to play;
hand, a list of the cards (each in the form of a 2-character string, as for Q1) held by the player attempting the play;
table, a list of list of cards representing the table (in the same format as for Q2).
Your function should return a Boolean indicating whether the play is valid or not given the current game state (i.e. the combination of the plays made to date, the content of the player’s hand, and the groups on the table). In this, you only need to validate the state of the table (using comp10001huxxy_valid_table from Q2, which you are provided with a reference implementation of) if the play ends the player’s turn and they have played to the table. Note that play_history, hand, and table all represent the respective states prior to the proposed play being made (e.g. play_history will not contain play).
The composition of the 3-tuple used to represent each play is (player_turn, play_type, play_details), where player_turn is an integer (between 0 and 3 inclusive) indicating which player is attempting to play, and play_type and play_details are structured as follows, based on the play type:
pick up a card from stock (and thereby end the turn): play_type = 0, play_details = None;
play a card from the hand to the table: play_type = 1, play_details = (card, to_group) where card is the card from the hand that is to be played, and to_group is the (zero-offset) index of group in table to play to; in the instance that the card is to start a new group, to_groupshould be set to the one more than the index of the last group on the table (i.e. if there are three groups, the last group will be index 2, so 3 would represent that the card is to be used to start a new group);
play a card from one group on the table to another: play_type = 2, play_details = (card, from_group,to_group) where card is the card to be played from the group, from_group is the (zero-offset) index of the group in table to play card from, and to_group is the index of the group in table to play card to (and, similarly to above, a value of one more than the index of the last group indicates that a new group is to be formed)
end the turn, after playing from the hand or play between groups on the table: play_type = 3, play_details = None.
Note that picking up a card (play_type = 0) implicitly ends the turn, whereas if plays are made from the hand/between groups on the table, an explicit “end of turn” play (play_type = 3) must be used to confirm that the player is ending their turn.
Example function calls are as follows:
>>> comp10001huxxy_valid_play((0, 0, None), [], 0, [‘3S’, ‘KC’, ‘8C’, ‘3S’, ‘8S’, ‘KH’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [])
True
>>> comp10001huxxy_valid_play((0, 1, (‘KC’, 0)), [], 0, [‘3S’, ‘KC’, ‘8C’, ‘3S’, ‘8S’, ‘KH’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [])
True
>>> comp10001huxxy_valid_play((0, 1, (‘KC’, 1)), [], 0, [‘3S’, ‘KC’, ‘8C’, ‘3S’, ‘8S’, ‘KH’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [])
False # invalid group no.
>>> comp10001huxxy_valid_play((0, 1, (‘AC’, 0)), [], 0, [‘3S’, ‘KC’, ‘8C’, ‘3S’, ‘8S’, ‘KH’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [])
False # can’t play card you don’t hold
>>> comp10001huxxy_valid_play((0, 1, (‘KH’, 0)), [(0, 1, (‘KC’, 0))], 0, [‘3S’, ‘8C’, ‘3S’, ‘8S’, ‘KH’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [[‘KC’]])
True
>>> comp10001huxxy_valid_play((0, 1, (‘KD’, 0)), [(0, 1, (‘KC’, 0)), (0, 1, (‘KH’, 0))], 0, [‘3S’, ‘8C’, ‘3S’, ‘8S’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [[‘KC’, ‘KH’]])
True
>>> comp10001huxxy_valid_play((0, 2, (‘KS’, 1, 0)), [(0, 1, (‘KC’, 0)), (0, 1, (‘KH’, 0))], 0, [‘3S’, ‘8C’, ‘3S’, ‘8S’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [[‘KC’, ‘KH’]])
False # group/card don’t exist
>>> comp10001huxxy_valid_play((0, 3, None), [(0, 1, (‘KC’, 0)), (0, 1, (‘KH’, 0)), (0, 1, (‘KD’, 0))], 0, [‘3S’, ‘8C’, ‘3S’, ‘8S’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’], [[‘KC’, ‘KH’, ‘KD’]])
True
>>> comp10001huxxy_valid_play((0, 3, None), [], 0, [‘3S’, ‘KC’, ‘8C’, ‘3S’, ‘8S’, ‘KH’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [])
False # attempt to end turn without any plays to table
>>> comp10001huxxy_valid_play((0, 3, None), [(0, 1, (‘KC’, 0)), (0, 1, (‘KH’, 0))], 0, [‘3S’, ‘8C’, ‘3S’, ‘8S’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [[‘KC’, ‘KH’]])
False # table state not valid
>>> comp10001huxxy_valid_play((0, 3, None), [(0, 1, (‘AC’, 0)), (0, 1, (‘AH’, 0)), (0, 1, (‘AD’, 0))], 0, [‘3S’, ‘8C’, ‘3S’, ‘8S’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’], [[‘AC’, ‘AH’, ‘AD’]])
False # insufficient points for opening turn
>>> comp10001huxxy_valid_play((0, 1, (‘KS’, 0)), [(0, 1, (‘KC’, 0)), (0, 1, (‘KH’, 0)), (0, 1, (‘KD’, 0)), (0, 3, None), (1, 0, None), (2, 0, None), (3, 0, None), (0, 0, None), (1, 0, None), (2, 0, None), (3, 0, None)], 0, [‘3S’, ‘8C’, ‘3S’, ‘8S’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KS’], [[‘KC’, ‘KH’, ‘KD’]])
True
>>> comp10001huxxy_valid_play((0, 3, None), [(0, 1, (‘KC’, 0)), (0, 1, (‘KH’, 0)), (0, 1, (‘KD’, 0)), (0, 3, None), (1, 0, None), (2, 0, None), (3, 0, None), (0, 0, None), (1, 0, None), (2, 0, None), (3, 0, None), (0, 1, (‘KS’, 0))], 0, [‘3S’, ‘8C’, ‘3S’, ‘8S’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’], [[‘KC’, ‘KH’, ‘KD’, ‘KS’]])
True
>>> comp10001huxxy_valid_play((1, 0, None), [], 0, [‘3S’, ‘KC’, ‘8C’, ‘3S’, ‘8S’, ‘KH’, ‘4H’, ‘2C’, ‘6S’, ‘5H’, ‘8C’, ‘KD’], [])
False # wrong player

find the cost of your paper

The post Write a function comp10001huxxy_valid_play() which takes five arguments. appeared first on Best Custom Essay Writing Services | EssayBureau.com.

[Button id=”1″]

[ad_2]

Source link

"96% of our customers have reported a 90% and above score. You might want to place an order with us."

Essay Writing Service
Affordable prices

You might be focused on looking for a cheap essay writing service instead of searching for the perfect combination of quality and affordable rates. You need to be aware that a cheap essay does not mean a good essay, as qualified authors estimate their knowledge realistically. At the same time, it is all about balance. We are proud to offer rates among the best on the market and believe every student must have access to effective writing assistance for a cost that he or she finds affordable.

Caring support 24/7

If you need a cheap paper writing service, note that we combine affordable rates with excellent customer support. Our experienced support managers professionally resolve issues that might appear during your collaboration with our service. Apply to them with questions about orders, rates, payments, and more. Contact our managers via our website or email.

Non-plagiarized papers

“Please, write my paper, making it 100% unique.” We understand how vital it is for students to be sure their paper is original and written from scratch. To us, the reputation of a reliable service that offers non-plagiarized texts is vital. We stop collaborating with authors who get caught in plagiarism to avoid confusion. Besides, our customers’ satisfaction rate says it all.

© 2022 Homeworkcrew.com provides writing and research services for limited use only. All the materials from our website should be used with proper references and in accordance with Terms & Conditions.

Scroll to Top