Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

slove using python 3 when running the code it should give something like this https://www.youtube.com/watch?v=yLNJ98Avyrw&feature=youtu.be the code given to me : import random def shuffle_deck(deck):

image text in transcribed

slove using python 3

when running the code it should give something like this https://www.youtube.com/watch?v=yLNJ98Avyrw&feature=youtu.be

the code given to me :

import random def shuffle_deck(deck): '''(list of str)->None Shuffles the given list of strings representing the playing deck ''' random.shuffle(deck)

def create_board(size): '''int->list of str Precondition: size is even positive integer between 2 and 52 Returns a rigorous deck (i.e. board) of a given size. ''' board = [None]*size

letter='A' for i in range(len(board)//2): board[i]=letter board[i+len(board)//2 ]=board[i] letter=chr(ord(letter)+1) return board

def print_board(a): '''(list of str)->None Prints the current board in a nicely formated way ''' for i in range(len(a)): print('{0:4}'.format(a[i]), end=' ') print() for i in range(len(a)): print('{0:4}'.format(str(i+1)), end=' ')

def wait_for_player(): '''()->None Pauses the program/game until the player presses enter ''' input(" Press enter to continue. ") print()

def print_revealed(discovered, p1, p2, original_board): '''(list of str, int, int, list of str)->None Prints the current board with the two new positions (p1 & p2) revealed from the original board Preconditions: p1 & p2 must be integers ranging from 1 to the length of the board ''' # YOUR CODE GOES HERE

############################################################################# # FUNCTIONS FOR OPTION 1 (with the board being read from a given file) # #############################################################################

def read_raw_board(file): '''str->list of str Returns a list of strings represeniting a deck of cards that was stored in a file. The deck may not necessarifly be playable ''' raw_board = open(file).read().splitlines() for i in range(len(raw_board)): raw_board[i]=raw_board[i].strip() return raw_board

def clean_up_board(l): '''list of str->list of str

The functions takes as input a list of strings representing a deck of cards. It returns a new list containing the same cards as l except that one of each cards that appears odd number of times in l is removed and all the cards with a * on their face sides are removed ''' print(" Removing one of each cards that appears odd number of times and removing all stars ... ") playable_board=[]

# YOUR CODE GOES HERE return playable_board

def is_rigorous(l): '''list of str->True or None Returns True if every element in the list appears exactlly 2 times or the list is empty. Otherwise, it returns False.

Precondition: Every element in the list appears even number of times '''

# YOUR CODE GOES HERE

####################################################################3

def play_game(board): '''(list of str)->None Plays a concentration game using the given board Precondition: board a list representing a playable deck '''

print("Ready to play ... ")

# this is the funciton that plays the game # YOUR CODE GOES HERE

#main # YOUR CODE TO GET A CHOICE 1 or CHOCE 2 from a player GOES HERE

# YOUR CODE FOR OPTION 1 GOES HERE # In option 1 somewhere you need to and MUST have a call like this: # board=create_board(size)

# YOUR CODE FOR OPTION 2 GOES HERE # In option 2 somewhere you need to and MUST have the following 4 lines of code one after another # #print("You chose to load a deck of cards from a file") #file=input("Enter the name of the file: ") #file=file.strip() #board=read_raw_board(file) #board=clean_up_board(board)

The game is usually played with cards led down on a table. Your game will not use graphics libraries to display the board ie english alphabet or any special character (e.g those you can find on the upper row of your keyboard). A typical card deck has Concentration game, each character that appears in the deck needs to appear on an even number of cards. Furthermore, the faces. In addition, for each character that appears on an odd number of cards, we need to remove exactly one card with that character from the deck. After such a clean-up, the resulting deck can be used for playing Concentration game. We call such a deck, the one where each character appears on even number of cards and where no card has * on its face side, a playable deck. Finally we call a deck rigorous if it is playable and each character of the deck appears exactly two times. Your game must use a (one dimensional) list as the board, as implied by the provided code in a3_xxxxxx.py (1) if they wanted a (rigorous) deck, and thus board, automatically generated (2) or if they want to start with the deck given in a file. If option (1) is chosen, you need to first prompt the player for the size of the deck. You should only accept even integers, between 2 and 52 for Option1. As part of this assignment, I provided you with a fully coded function, called create_board that returns a rigorous deck of the given size. Thus option 1 only plays a game with rigorous decks. If option (2) is chosen, the deck wil be read from a file. The player will enter a name of that file when prompted. I provide you with a couple of practice files. (TAs will test your assignment with these and some other files.) To use them, you need to fully coded function, called read_raw_board, that reads the file and returns a list containing the deck of cards specified in the file. This deck however is not necessarily playable. Thus you first need to make it playable. For that you will code a function called clean_up_board. I provide a header and docstrings for that function. That function should return a playable deck and like to know if the resulting deck is not only playable but also rigorous. For that you will need to complete the function called is_rigorous for which I provide you with the header and docstrings. Finally you will notice that a3_xxxxxx.py has a function called play_game (board). That is where you should put your game paying code. The function play_game takes a playable deck as input parameter (i.e. a deck created by option 1 or option 2). Once the player completes the game, you should also print the number of guesses it took to solve it and how far it is from the optimal (although impossible without luck) len(board)/2 guesses. Outside of those functions, i.e. in the main you will do initial communication with the player, and whatever else is specified

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions