Question
Python 3.5 Information: Solitaire (is also known as Klondike) is a game which is played with a standard 52-card deck, without Jokers. After shuffling, seven
Python 3.5
Information: Solitaire (is also known as Klondike) is a game which is played with a standard 52-card deck, without Jokers. After shuffling, seven piles of cards are laid from left to right. Each pile begins with one upturned card. From left to right, each pile contains one more card than the last. The first and left-most pile contains a single upturned card, the second pile contains two cards (one downturned, one upturned), the third contains three (two downturned, one upturned), and so on, until the seventh pile which contains seven cards (six downturned, one upturned). The piles should look like the figure to the right at the beginning of every game.The four foundations are built up by suit from Ace (low in this game) to King, and the tableau piles can be built down by alternate colors, and partial or complete piles can be moved if they are built down by alternate colors also. Any empty piles can be filled with a King or a pile of cards with a King. The aim of the game is to build up a stack of cards starting with two and ending with King, all of the same suit. Once this is accomplished, the goal is to move this to a foundation, where the player has previously placed the Ace of that suit. Once the player has done this, they will have "finished" that suit, the goal being to finish all suits, at which time the player would have won.
Simplied Rules: After shuffling, n piles of cards are laid from top to bottom. The (0) first pile begins with one upturned card and n-1 downturned cards. The other piles (the tableau piles) are empty are empty at the beginning. An example is shown below.
0: 6 * * * * * * * * * 1: 2: 3:
The tableau piles can be built down according to the numbers of the cards. Partial or complete tableau piles can be moved if they are built down in order. An example is shown below.
0: 2 * * * * * * 1: 5 4 3 2: 6 3:
to
0: 2 * * * * * * 1: 2: 6 5 4 3 3:
The empty pile can be filled with any card. If the player do not want to /cannot move the card of the first pile (0) to any other tableau piles, the player can get a second card and put the original one to the back of the first pile (0). An example is shown below.
0: 6 * * * * * * * * * 1: 2: 3:
to
0: 7 * * * * * * * * * 1: 2: 3:
or
0: 7 * * * * * * * * 1: 6 2: 3:
The aim of the game is to build up a stack of cards starting from card n-1 to card 0. In order to become familiar with the template program supplied.
The class Deque The class Deque is used to implement a pile of cards. The summary of class methods are shown below:
class Deque: def __init__(self): def add_front(self, item): def add_rear(self, item): def remove_front(self): def remove_rear(self): def size(self): def peek(self): def peeklast(self): def printall(self, index):
def __init__(self): You should use a python List data structure to implement the deque. The lists name should be item
def add_front(self, item): This method adds a new item to the deque (at list[SIZE])
def add_rear(self, item): This method adds a new item to the deque (at list[0])
def remove_front(self): This method removes an item from the deque (at list[SIZE])
def size(self): This method returns the size of the deque
def peek(self): This method returns the front item of the deque (at list[SIZE])
def peeklast(self): This method returns the rear item of the deque (at list[0])
def printall(self, index): This method prints out all the items of the deque with the order beginning from the rear item. The items should be separated by . However, if index is 0, all the items besides the first one (the rear item at list[0]) should be hidden by *.
For example: if q.item is [4, 5, 6, 7, 8], the expected output for q.printall(1) should be 4 5 6 7 8 and the expected output for q.printall(0) should be 4 * * * *
Complete the implementation of this Deque class.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started