Stacks & Queues( variation of the popular card game SOLITAIRE using stacks and queues)

    Program Code : Java
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. For your program 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. For your program 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. They are built up by suit from Ace(1) to King(13). Assume at the start of the game, the four ACEs are already placed on the foundation. For your program 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. For your program this pile of cards MUST be stored in 7 STACKs and 7 QUEUEs. Each tableau (ex. T4 see picture) 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.
Source code for 52 card and shuffled :
import java.util.ArrayList;
import java.util.Collections;

/**
*
* @author Faruk
*/
public class Deck {

public static void main(String[] args)
{
ArrayList<String> shuffled_deck = shuffledDeck();

System.out.println( shuffled_deck );
}

private static ArrayList<String> shuffledDeck()
{
ArrayList<String> deck = new ArrayList<String>();

String[] suit = new String[] { “H”,”D”,”C”,”S” };
for(int i=1; i<=13; i++)
for(int j=0; j<4; j++)
deck.add( i + suit[j] );

Collections.shuffle(deck);

return deck;
}
}
Stacks and Queues
You may use Java’s ArrayDeque class and Java’s Stack class or you may use your own StackBox / QueueBox code or any combination of these four BUT your solution must use stacks and queues as described above.

*** Assume for all stacks you can only move and see (peek) the top card of any stack.

Sample Program
( run runme.– Do not try to “decompile” this program. There are safeguards in place and detection of cheating will result in disciplinary action.) = Please don’t Do reverse Engineering!
I attach the file .

Simple Game Rules
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).

Marking & Grading
!! IMPORTANT!! Your program must use stacks and queues as described. If you don’t use (mostly) stacks and queues then maximum mark given will be 25% even if the program does work. !!

[10 marks]: Program uses Stacks and Queues for deck, waste, tableaus, and foundations.
[2 marks]: Draw a card from deck stack to waste stack.
[2 marks]: Move all cards from waste stack back to desk stack when deck stack is empty
[4 marks]: Move waste card to foundations correctly assuming move is allowed.
[4 marks]: Move waste card to a tableau assuming move is allowed
[6 marks]: Moving a tableau card from one tableau to another assuming move is allowed
[4 marks]: Dequeing a tableau queue and placing card on the tableau stack when stack is empty.
[4 marks]: Moving tableau card to foundations assuming move is allowed.
[4 marks]: Game robustness testing ( can’t crash the program )

Here i attatched 3 more picture with a sample output picture.
Assignment Due : In 25 Hours .
Please update me soon ! Thanks

No reverse coding or Don’t use the solo.class(just for ref)

Order Now

Top