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.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller



In reply to Re: Pseduo code planning by BrowserUk
in thread Pseduo code planning by sulfericacid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.