To Project Proj6
Pseudocode for Project Proj6
// Pseudocode for the Shuffleable constructor.
public ShuffleableDeck( )
{
Call the base class constructor.
Instantiate aux1.
Instantiate aux2.
}
// Pseudocode for cut method
// of the Shuffleable class.
public void cut( )
{
// Cut cards into aux1 and aux2.
Set n = (count of inherited deck) / 2
While count of inherited deck is
greater than or equal to n
Deal card to aux1 deck.
End While
While count of inherited deck is
greater than or equal to 1
Deal card to aux2 deck.
End While
}
// Pseudocode for shuffle method
// of the Shuffleable class.
public void shuffle( )
{
// Shuffle cards from aux1 and aux2
// back into inherited deck.
While count of aux1 and count of aux2
are both > 0
If Math.random( ) >= 0.5
Deal card from aux2 to inherited deck,
Else
Deal card from aux1 to inherited deck.
End if.
End while.
// Finish up if aux1 has cards left over.
While count of aux1 is > 0
Deal card from aux1 to inherited deck.
End while.
// Finish up if aux2 has cards left over.
While count of aux2 is > 0
Deal card from aux2 to inherited deck.
End while.
}
// Source code for constructor
// of the War class.
public War( )
{
Create a ShuffleableDeck object called startDeck.
Populate startDeck with the standard 52 playing cards.
Cut and shuffle startDeck ten times.
Deal all of the cards from startDeck into the playerA
and playerB decks.
Set gameOverFlag to false.
}
// Source code for play method
// of the War class.
public void play( )
{
Declare and instantiate limbo deck.
If the count for playerA deck equals 0
Set gameOverFlag to true.
Return from method.
End if
If the count for playerB deck equals 0
Set gameOverFlag to true.
Return from method.
End if
Draw a card from playerA deck. Call it cardA.
Draw a card from playerB deck. Call it cardB.
While cardA is equal in rank to cardB
If the count for playerA deck < 4
Set gameOverFlag to true.
Return from method.
End if
If the count for playerB deck < 4
Set gameOverFlag to true.
Return from method.
End if
// A war condition exists.
Add cardA to limbo deck.
Add cardB to limbo deck.
Deal 3 cards from playerA deck to limbo deck.
Deal 3 cards from playerB deck to limbo deck.
Draw a card from playerA deck. Call it cardA.
Draw a card from playerB deck. Call it cardB.
End while.
If rank of cardA > rank of cardB
Deal all of the cards in the limbo deck to playerA deck.
Add cardA to playerA deck.
Add cardB to playerA deck.
Else If rank of cardA < rank of cardB
Deal all of the cards in the limbo deck to playerB deck.
Add cardA playerB deck.
Add cardB to playerB deck.
End If
}