| Dealing a Hand of Cards Updated and Revised |
![]() |
| Looks pretty good, don't you think - for character based? I think so. |
The demonstration routine that I used to create the deal shown above, Poker.bat, is provided below. It uses the newer DealCard.bat, previously described. DealCard is called at least five times to select cards at random and NewCards.bat is called to display each card. The demo also shows the beginnings of a way to limit the deck size.
|
:: POKER.BAT - A demonstration of the rudiments of displaying a two player :: card game, such as Poker. :: (Rev Sep 99) :: Requires DOS version 6.xx or later (for ERRORLEVEL testing), :: Full.bat to paint background, :: DealCard.bat to randomly select cards and :: NewCards.bat to display them (ANSI.SYS must be loaded). |
I have tried to comment it sufficiently to make it self documented. One thing to remember is that the DealCard procedure just makes up a card value and suit without regard for whether it has been picked before. This is generally not acceptable, such as dealing two aces of spades while playing poker. Poker.bat fixes that problem by saving a record of the selected cards into a temporary file, ~TmpC.txt, and checking each new pick against the record. If the card is found, it ignores the pick and tries again. This is certainly one of the easiest ways to code the test and it is probably okay for selecting a few cards, but it would take too long to deal a whole deck. By the time the procedure got around to the last few cards, it would be throwing away many more picks than it would use. That's not a good idea. I have some thoughts on the subject, but not the time to pursue it.Another addition to the Poker procedure is the use of Full.bat to paint a green poker table like background. The use of the ASCII 177 character (B1 hex) and the combination of bright green foreground and blue background colors (1A hex) work together to present a fill color not generally available in the standard 16 color text palette. From my experimentation, it would appear that 256 distinct color shades are possible using this 'color aliasing' technique.
BTW, does anyone recognize the faint aroma of some elements of object oriented programming in the DealCard and Poker routines? Specifically, the use of a Name.Property construct for the playing cards (e.g. Dealer.Text, Dealer.Suit, Player.Text and Player.Suit) and the passing of 'object' names to subroutines.
The last bit needed to complete the picture is a routine to paint the cards to the screen. I developed such a procedure, NewCards.bat. It is a pretty hefty 104 working lines and relies heavily on ANSI display codes. To tell the truth, I don't have time to explain it's operation (and it's quite complicated). But, I don't want to leave anyone in the lurch, so I have provided a link to a downloadable version of all the batch files in this random number series of pages as RANDOM.EXE, which is a self extracting Zip archive file. Download it, run it and all of the example batch files (both old and new versions), including NewCards.bat and Full.bat will be unzipped out of it.