A few questions to ponder.
What happens when the pack runs out?
Do you want to re-shuffle the pack each time the user make a guess or shuffle once at the start and then just take the next card each time?
If the next card has the same value as the current card, does the user always win or always lose?
Your textual description is shuffle a deck of cards and take the top card, then prompt to the user if the next card will be higher or lower than this card, after they answer the next card in the deck is shown, if the user was right the program will loop and flip another first card over..ask them again... but if they get it wrong the program exits.
Breaking this up into steps you get
shuffle a deck of cards and take the top card, then prompt to the user if the next card will be higher or lower than +this card, after they answer the next card in the deck is shown, if the user was right the program will loop and flip another first car +d over..ask them again... but if they get it wrong the program exits.
Prodding this around a bit I get
Shuffle deck; pop top card while( cards_left ) { show card prompt Higher or Lower? Get answer next_card = pop cards last unless next_card > top_card and answer = Higher or next_card < top_card and answer = Lower top_card == next_card } Game over.
which is way short of complete, but might be a place to continue from?
Update:Since jeffa let the cat out of the bag below, here's one of my takes on the implementation.
s #! perl -slw use strict; use List::Util qw[shuffle]; sub card_value{ $_[0] % 13 || 13 } sub show_card{ my( $suit, $face ) = ( $_[0] / 13, $_[0] % 13 ); printf '[ %c %2s %c ] ', 3+$suit, substr( ' A 2 3 4 5 6 7 8 910 J Q K', $face * 2, 2 ), 3+$suit; } my @cards = shuffle 0 .. 51; my $top_card = pop @cards; while( @cards ) { show_card( $top_card ); my $answer = ''; $answer = do{ printf 'Will the next card be (H)igher or (L)ower? '; <stdin> } until $answer =~ m[^[H|L]]i; my $next_card = pop @cards; unless( card_value( $next_card ) >= card_value( $top_card ) and $answer =~ m[^H]i or card_value( $next_card ) <= card_value( $top_card ) and $answer =~ m[^L]i ) { show_card( $next_card ); print 'Bad luck! You lose.'; last; } $top_card = $next_card; } print 'Game over.'; print 'You beat the pack' unless @cards;
Caveat: The suit symbols will probably be wrong on *nix.
In reply to Re: Pseduo code planning
by BrowserUk
in thread Pseduo code planning
by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |