Go Fish/Perl 6

constant BOOKSIZE =4;constant HANDSIZE =9;constant Str @pips=<two three four five six seven eight nine ten jack queen king ace>;# The elements of @pips are only names. Pips are represented internally# as indices of this array.constant Str @piparticles=<a a a a a a an a a a a a an>;constant Str @ppips=<deuces threes fours fives sixes sevens eights nines tens jacks queens kings aces>;constant Str @shortpips=<23456789 T J Q K A>;constant$foe_nominative_pronoun=pick1,<he she it e xe>;

class Knowledge {# The computer player has an instance of this class for each pip.# Each instance tracks whether the computer thinks the user has at# least one card of the corresponding pip.has Maybe $.maybe= Dunno;# Yes if the user definitely has this pip, No if they didn't# have it the last time we checked, Dunno if we haven't yet# checked.has Int $.n=0;# If $.maybe is No, $.n counts how many cards the user# has drawn since we last checked.

method set (Maybe $!maybe){$!n=0}

method incr {$.maybe== No and++$!n}}

class Player {has Int @.h;# @h[$n] is number of cards of pip $n in this player's hand.has$.deck;# A reference to whatever deck the player's playing with.has Int $.books=0;has Bool $.cpu;has Knowledge @.know;

method losecards (Int $pip){@.h[$pip]=0;whilenone@.hand$.deck.elems{say$.cpu??"The dealer's hand is empty, so $foe_nominative_pronoun draws a new card."!!"Your hand's empty, so you draw a new card."; self.draw;}}