Earn Higher Grades With Instant Assignment Help.Ask Question!

Python Programming
(5/5)

This assignment focuses on the design, implementation and testing of a Python program which uses an instructor supplied module to play a card game

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Assignment Overview

This assignment focuses on the design, implementation and testing of a Python program which uses an instructor-supplied module to play a card game, as described below.

Assignment Deliverables

The deliverable for this assignment is the following file:

proj10.py – the source code for your Python program

Be sure to use thespecified file name and to submit it for grading via the Mimir system before the project deadline.

Assignment Background

 Aces Up is a popular solitaire card game which is played by one person with a standard 52-card deck of cards. The rules and a tutorial video are available at:

 

Click on “Choose Game” at the top of the screen and click on “Aces Up”.

Your program will allow the user to play a simplified version of Aces Up, with the program managing the game. The game rules are given below.

Game Rules

 Start: The game is played with one standard deck of 52 cards. The deck is shuffled and becomes the initial stock (pile of cards). The cards in the stock are placed face

Four cards are then dealt from the stock, left to right, one to each column of a four-column tableau. During play, additional cards will be added to the tableau, but it starts with just one card in each column. All tableau cards are visible.

The game also has a foundation, which is a single pile of cards. The foundation starts out empty and is filled during play.

 

  1. Goal: The game is won when the stock is empty and the only cards left in the tableau are the four

  2. Moves: A player can move only one card at a time and the moved card must be the bottom card of a tableau

The card at the bottom of a column can be moved to the foundation if a higher rank card of the same suit is at the bottom of another column. Note that aces are high in this game—that is, the rank of an ace is greater than the rank of any other card.

If a column of the tableau becomes empty, any card at the bottom of another column can be moved to the empty column.

No other moves are permitted.

  1. Deal: A player can choose to deal instead of moving a card. In this case, the top four cards are dealt from the stock, left to right, with one card placed at the bottom of each column of the tableau. (Because four cards are always dealt at the same time the stock will never have fewer than four cards in this )

 

Assignment Specifications

 You will develop a program that allows the user to play Aces Up according to the rules given above. The program will use the instructor-supplied cards.py module to model the cards and deck of cards. To help clarify the specifications, we provide a sample interaction with a program satisfying the specifications at the end of this document.

  1. The program will recognize the following commands (upper or lower case):

D          Deal four cards from the stock to the tableau

F x        Move card from Tableau column x to the Foundation.

T x y      Move card from Tableau column x to empty Tableau column y. R  Restart the game (after shuffling)

H          Display the menu of choices

Q          Quit

where x and y denote column numbers, and the columns are numbered from 1 to 4.

The program will repeatedly display the current state of the game and prompt the user to enter a command until the user wins the game or enters “Q” (or “q”), whichever comes first.

The program will detect, report and recover from invalid commands. None of the data structures representing the stock, tableau, or foundation will be altered by an invalid command.

  1. The program will use the following function to initialize a game:

init_game() à (stock, tableau, foundation)

 That function has no parameters. It creates and initializes the stock, tableau, and foundation, and then returns them as a tuple, in that order. This corresponds to rule 1 in the game rules:

  • stock is a deck class object,

  • foundation is an empty list, and

  • tableau is a list of lists, each containing one of the dealt cards. The first element of

tableau is the leftmost column when displayed

The deck is shuffled and becomes the initial stock (pile of cards). Four cards are then dealt from the stock, left to right, one to each column of a four-column tableau.

  1. The program will use the following function to deal cards to the tableau:

deal_to_tableau( stock, tableau ): à None

 

That function has two parameters: the data structure representing the stock and the data structure representing the tableau. It will deal a card from the stock to each column of the tableau. It will always deal four cards (why?).

  1. The program will use the following function to display the current state of the game:

display( stock, tableau, foundation ) à None Provided.

  1. The program will use the following function to prompt the user to enter an option and return a representation of the option designed to facilitate subsequent

get_option()à list

 That function takes no parameters. It prompts the user for an option and checks that the input supplied by the user is of the form requested in the menu. Valid inputs for options are described in item (bullet) 1 of the specifications. If the input is not of the required form, the function prints an error message and returns None.

Note that input with the incorrect number of arguments, e.g. D 2, or incorrect types, e.g. F D, will return None.

Also, note that in this function you do not check that ‘y’ of ‘T x y’ is empty (you do not have tableau as a parameter to check that).

The function returns a list as follows:

  • None, if the input is not of the required form

  • ['D'], for deal

  • ['F', x], where x is an int, for moving a card to the foundation

  • ['T', x, y], where x and y are int’s, for moving a card within the tableau from column x to column y

  • ['R'], for restart

  • ['H'], for displaying the menu

  • ['Q'], for quit

 

  1. The program will use the following function to determine if a requested move to the foundation is valid:

validate_move_to_foundation( tableau, from_col ) à bool

 That function has two parameters: the data structure representing the tableau and an int indicating the column whose bottom card should be moved. The function will return True, if the move is valid; and False, otherwise. In the latter case, it will also print an appropriate error message. There are two errors that can be caught: from_col is empty or move is invalid.

Remember: a card can be moved to the foundation only if a higher ranked card of the same suit

is at the bottom of a Tableau column.

Hint: consider tableau index and remember that Ace is high. Also, from_col must be a valid value (1 <= from_col <= 4).

  1. The program will use the following function to move a card from the tableau to the foundation:

move_to_foundation( tableau, foundation, from_col ) à None

 That function has three parameters: the data structure representing the tableau, the data structure representing the foundation, and an int indicating the column whose bottom card should be moved. If the move is valid, the function will update the tableau and foundation; otherwise, it will do nothing to them. Hint: the list pop() method is useful, if you desire a terse function. from_col must be a valid value (1 <= from_col <= 4).

 

  1. The program will use the following function to determine if a requested move to within the tableau is valid:

validate_move_within_tableau( tableau, from_col, to_col ) à bool

 That function has three parameters: the data structure representing the tableau, an int indicating the column whose bottom card should be moved, and an int indicating the column the card should be moved to. The function will return True, if the move is valid; and False, otherwise.

In the latter case, it will also print an appropriate error message. Remember: you can only move a card to an empty tableau slot. Also, from_col and to_col must be valid column values

(1 <= from_col <= 4 and 1 <= to_col <= 4).

  1. The program will use the following function to move a card from the tableau to the foundation:

move_within_tableau( tableau, from_col, to_col ) à None

 That function has three parameters: the data structure representing the tableau, an int indicating the column whose bottom card should be moved, and an int indicating the column the card should be moved to. If the move is valid, the function will update the tableau; otherwise, it will do nothing to it. Hint: the list pop() method is useful, if you desire a terse function.

from_col and to_col must be valid column values: (1 <= from_col <= 4 and 1 <= to_col <= 4).

  1. The program will use the following function to check if the game has been won:

check_for_win( stock, tableau ) à bool

 That function has two parameters: the data structure representing the stock and the data structure representing the tableau. If returns True, if the stock is empty and the tableau contains only the four aces; and False, otherwise.

  1. Once you write all your function, it is time to write your main function:

  2. Your program should start by initializing the board (the stock, the tableau and the foundation).

  3. Display the menu and the

  4. Ask to input an option and check the validity of the

  5. If ‘D’, deal four cards from the stock to the tableau

  6. If ‘F x’, move card from Tableau column x to the Foundation

  7. If ‘T x y’, move card from Tableau column x to empty Tableau column

  8. If ‘R’, restart the game by initializing the board (after shuffling). Display the rules and the

  9. If ‘H’, display the menu of choices

  10. If ‘Q’, quit the game

  11. If none of these options, the program should display an error

  12. The program should repeat until the user won or quit the game. Display a goodbye message.

 

Attachments:
(5/5)

Related Questions

CSI 1420 Introduction to C Programming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two majorconstructs of the C programming language – Fu

The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Assignment To Be Done By Our ExpertsGet A+ Grade Solution Guaranteed

expert
joyComputer science
(4/5)
12 Answers Hire Me
expert
Robert DLaw
(4.8/5)
973 Answers Hire Me
expert
Dr Samuel BarberaStatistics
(5/5)
596 Answers Hire Me
expert
Tutor For YouEconomics
(5/5)
998 Answers Hire Me