Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON Its a single assignment and i have already written the whole code but whe

ID: 3586081 • Letter: P

Question

PYTHON
Its a single assignment and i have already written the whole code but where it says your code here you have fill that space. Please go over all the instructions as given in assignment and also go over the code i provided below.
Please dont tell me this question looks big because i have already done 90% of your work and asking for 10% of the help to complete it. Please go over the instructions given and complete this please.

I have already wrote the code but where it is commented out in red and says your code here you have to fill that space.
1. Introduction In this exercise, we will use a data structure known as a LinkedDeque (deque implemented using linked list) to implement the card game Snap! 2. Objectives The purpose of this assignment is to help you *Sharpen your knowledge on basic data structures through an application .Refine your ability to translate real-world scenarios into code Note: Before you start, if you are not familiar with LinkedLists or Deques you are recommended to review the sample codes we covered in lecture first. 3. Background 3.1. Snap Card Game forward. The basic flow of our version of Snap is as follows: Snap is an easy-to-learn card game. Our version of Snap makes the game even more straight Step 1: Divide the deck into 2 halves (1 half per player; deck does not include Jokers) Step 2: While neither player has an empty deck, the two players take turns throwing a card into a public deck (which starts off as an empty deck). If a card is thrown that has the same rank as a previous card in the public deck, the player who threw that card takes the cards in the public deck up until (and including) the card of the same rank. Note: the cards thrown by each player can be from either the top or the bottom of their deck. We will determine whether the top or bottom card is thrown using randomness. Consider this example: suppose player A has the cards A, 2, Q, J, K, 5, Q, player B has the cards 3,2, Q,7, 4, and the public deck has the card 7, 5, 4, 1, 8 (this example is not with 52 cards, it is simplified for the sake of explanation). Player A randomly decides to throw the card that's on the bottom of his/her deck a Queen, which has not appeared thus far in the public deck (so the new public deck is 7, 5,4, 1, 8, Q) Then player B throws a 4 which has appeared in the public deck (now the public deck is 7,5,4,1,8, Q 4), thus player B takes the public deck up until and including the 4 and adds it to the bottom of his/her deck (4, 1, 8, Q,4-in exactly that order). After this one cycle of turns, player A has the cards A, 2, Q, J K, 5, player B has the cards 3, 2,Q,7,4, 1,8,Q,4, and the public deck has 7, 5

Explanation / Answer

snap.py

import argparse
import operator
from cards import Deck


class Player(object):
def __init__(self, name, number_of_cards=0):
self.cards = number_of_cards
self.name = name

def add_pile(self, number_of_cards):
self.cards += number_of_cards

def __str__(self):
return '{p.name}: {p.cards} cards'.format(p=self)


def format_state(pile, deck, drawn, previously_drawn, is_match, players):
return '''
pile_size: {}, cards left: {}
card drawn: {}
card previously drawn: {}
They {} match
Players infos: {}'''.format(
pile, deck, drawn, previously_drawn,
'do' if is_match else "don't",
' / '.join(str(p) for p in players))


def game_of_snap(number_of_decks, compare_cards):
deck = Deck.merge(number_of_decks)
deck.shuffle()
players = [Player('player 1'), Player('player 2')]
previous = None
pile = 0

while deck:
card = deck.draw()
pile += 1

try:
match = compare_cards(card, previous)
except AttributeError:
# In case previous is None
match = False

if match:
random.choice(players).add_pile(pile)
pile = 0

print format_state(pile, len(deck), card, previous, match, players)

previous = card # or previous = card if not match else None ???

return max(players, key=operator.attrgetter('cards'))


def read_options():
parser = argparse.ArgumentParser(description="A snap game simulator. "
"Perform comparisons on suits and values of consecutively drawn "
"cards to know whether or not give previously drawn cards to a player")
parser.add_argument('number_of_decks', type=int)
group = parser.add_mutually_exclusive_group()
group.add_argument('--no-suits', action='store_true', help='Disable suits comparison')
group.add_argument('--no-values', action='store_true', help='Disable values comparison')

args = parser.parse_args()
if args.no_suits:
compare_cards = compare_cards_by_value
elif args.no_values:
compare_cards = compare_cards_by_suits
else:
compare_cards = compare_cards_by_suits_or_value

return args.number_of_decks, compare_cards


if __name__ == '__main__':
decks, compare = read_options()
print game_of_snap(decks, compare)