Unit spx_crd; {$X+,O+ } { SPX Library Version 2.0 Copyright 1993 Scott D. Ramsay } { SPX_CRD contains simple playing card handling routines for BlackJack 21 and Poker Cards and Decks are defined as follows: Tcard = record card,suite : byte; end; Tdeck = array[0..51] of Tcard; Tcard.card contains the card value where CARD=2 is the card 2, CARD=4 is the card 4, etc. Jack=11, Queen=12, etc. See constant declarations below: Tcard.suite contains the suit of each card. Where: diamond=0, heart=1, spade=2, club=3 Tdeck is an array the defines a standard deck of 52 cards. } Interface const { card value type } crd_jack = 11; crd_queen = 12; crd_king = 13; crd_ace = 14; { card suite type } crd_diamond = 0; crd_heart = 1; crd_spade = 2; crd_club = 3; { five card poker values } crd_nothing = 0; { nothing of value } crd_onepair = 1; { one of a kind } crd_twopair = 2; { two of a kind } crd_threekind = 3; { three of a kind } crd_fourkind = 4; { four of a kind } crd_fullhouse = 5; { full house } crd_straight = 6; { straight } crd_flush = 7; { flush } crd_straightf = 8; { straight flush } crd_rstraightf = 9; { royal straight flush } type { values returned by BJ_Dealer } BlackJackType = (BJnothing,BJhit,BJstay,BJsplit,BJdouble); { Card definitions } Tcard = record card,suite : byte; end; Tdeck = array[0..51] of Tcard; { contains the highest card in hand after call from PokerHand } var hicard : Tcard; {-----------------------------------------------------------} procedure SwapCard(var card1,card2:Tcard); Exchanges two cards: e.g. card1, card2 : Tcards to exchange {-----------------------------------------------------------} procedure CreateDeck(var adeck:Tdeck); Fills a deck with the standard card values. (sorted) adeck : The deck to be sorted {-----------------------------------------------------------} procedure ShuffleDeck(var adeck:Tdeck); Randomly shuffles a deck adeck : The deck to be shuffled {-----------------------------------------------------------} procedure SortDeck(var adeck;Lo,Hi:integer); Sorts a deck or a portion of a deck. adeck : The deck or a players hand to be sorted Lo : The low card to be sorted Hi : The high card to be sorted adeck is an untyped variable so one can pass in the players hand. eg. Var TheDeck : Tdeck; MyHand : array[0..4] of Tcard; . . . SortDeck(TheDeck,1,52); { Sort the entire deck } SortDeck(TheDeck,10,24); { Sort the cards starting at 10 to 24 } SortDeck(MyHand,1,5); { Sort MyHand (0..4) -> 1..5 } NOTE: Note that the first card passed in is always 1 not 0. {-----------------------------------------------------------} function PokerHand(var ahand):integer; Evaluates a five card poker hand and returns the hand value. ahand : array [0..4] of Tcard to evaluate Returns one of the following values crd_nothing crd_onepair crd_twopair crd_threekind crd_fourkind crd_fullhouse crd_straight crd_flush crd_straightf crd_rstraightf Also sets the variable HICARD to the highest value card in the hand. {-----------------------------------------------------------} function SuiteString(suite:byte):string; Returns a string of the suite name. example: writeln('The suit you picked is ',SuiteString(crd_heart)); {-----------------------------------------------------------} function PokerHandString(ehandvalue:integer):string; Returns a string of the poker hand name. ehandvalue : poker hand value example: var MyHand : array[0..4] of Tcard; writeln('You have: ',PokerHandString(PokerHand(MyHand))); {-----------------------------------------------------------} function BJ_Total(var ahand;cards:integer):integer; Evaluates the highest value a BlackJack hand can contain. Returns the hand value. automatically converts ACES to 11 or 1 depending which is better ahand : Cards to evaluate cards : Number of cards in ahand example: var MyHand : array[0..4] of Tcard; ncards := 3; value := BJ_Total(MyHand,ncards); if value>21 then writeln('You are busted') else if (value=21) and (ncards=2) then writeln('You got BlackJack!!!') else writeln('You got ',value); {-----------------------------------------------------------} function BJ_Dealer(var ahand;cards:integer):BlackJackType; Returns a value what the dealer would do for the next card. ahand : Cards to evaluate cards : Number of cards Returns one of the following values: BJnothing BJhit BJstay {-----------------------------------------------------------}