Question
Program Solitaire game using the following rules and functions Deck/Stock: A pile of cards, face down, which are left over after setting up the other
Program Solitaire game using the following rules and functions
Deck/Stock: A pile of cards, face down, which are left over after setting up the other layout areas. These are turned over one-at-a-time into the waste. this pile of cards MUST be stored in a STACK
Waste - The area where the cards from the deck/stock go when they are brought into play. Only cards from the stock can be played to the waste. Only the topmost card can be moved to either the foundation or to the tableau. this pile of cards MUST be stored in a STACK.
Foundations - The aim of the games is to clear the tableau and move all the cards to the foundation from Ace(1) to King(13). Assume at the start, the four ACEs are already placed on the foundation. this pile of cards MUST be stored in four separate STACKs (one for each suit). Recommended you use an ARRAY of stacks for this..
Tableaus - This consists of a number of piles where cards can be moved from one tableau to another or from tableau to a foundation. this pile of cards MUST be stored in 7 STACKs and 7 QUEUEs. Each tableau has both a stack and a queue. The stack holds the cards that have been turned over while the queue holds the cards that have not yet turned. At the start of the game Tableau 0 (T0 see picture) starts with a queue containing 1 card, T1 has two cards, T2 has 3 cards and so on. The game begins by DEQUEUING one card from each of these queues and placing it into the stack of the tableau. Hence, the T0 queue begins the game with 0 cards, T1 queue has 1 card and so forth while each of the tableau stacks have the one card to start with (the topmost card you can see). Recommended you use an ARRAY of 7 queues and another ARRAY of 7 stacks for this.
Creating a shuffled deck of 52 cards Your deck of cards should be represented by a number (1-13) followed by the first letter of the suit. Example: 1H, 5S, 12C, 13D would mean ace of hearts(1H), 5 of spades(5S), queen of clubs(12C), and king of diamonds(13D). The deck also needs to be shuffled.(the code for the shuffled deck is given below)
import java.util.ArrayList; import java.util.Collections; /** * * @author John */ public class Deck { public static void main(String[] args) { ArrayList shuffled_deck = shuffledDeck(); System.out.println( shuffled_deck ); } private static ArrayList shuffledDeck() { ArrayList deck = new ArrayList(); String[] suit = new String[] { "H","D","C","S" }; for(int i=1; iYou MUST put the elements of this ArrayList into your deck stack yourself. *** Assume for all stacks you can only move and see (peek) the top card of any stack.
Simple Game Rules to follow for the solitaire game
- You can only move the top card of any stack.
- To move a card to the foundation, the foundation must have the previous card already there. Example, you can't move 12D if 11D is not already in the foundation.
- To move a card onto a tableau, the card must be one less than the card currently showing on the target tableau AND the suit color must be opposite color than the card showing. Example, moving 7H on a tableau currently showing a 8S is allowed but you can't move 7H to a 8D (suit colors are both red). You can also move any card to the tableau if the tableau is empty (no cards in its stack or queue left).
Program uses Stacks and Queues for deck, waste, tableaus, and foundations.
program should run the following:
Draw a card from deck stack to waste stack. Move all cards from waste stack back to desk stack when deck stack is empty Move waste card to foundations correctly assuming move is allowed. Move waste card to a tableau assuming move is allowed Moving a tableau card from one tableau to another assuming move is allowed Dequeing a tableau queue and placing card on the tableau stack when stack is empty. Moving tableau card to foundations assuming move is allowed. Game robustness testing ( can't crash the program )
language being used: JAVA
Tableau (7 queues and 7 stacks) Deck/Stock (stack) Waste (stack) Foundation (4 stacks) T6 UNDO NEW Tableau (7 queues and 7 stacks) Deck/Stock (stack) Waste (stack) Foundation (4 stacks) T6 UNDO NEWStep 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