POKER.BAS July 1997 by Marc Kummel aka Treebeard. Contact mkummel@rain.org, http://www.rain.org/~mkummel/ About POKER: -------------- POKER is a Basic program from the Vault (1993) that deals random poker games and keeps track of the statistics for different hands. It also allows you to play 5 card draw poker with up to 3 other imaginary players who have different poker personalities. POKER was inspired by a Dunn Middle School trip to the CIMI Environmental Education camp on Catalina Island in Fall 1993. In between snorkling and hiking, we had an ongoing poker game in the camping area, using wild cherry pits for chips. As the DMS science teacher and general math person, I felt it my duty to write this program to prove to the kids that a pair is not enough, and it's not worth drawing to an inside straight. (*After* winning more than my share, of course. That's definately a lesson in real world probability!) Then I started adding features in the usual way. The result is a pretty slick poker program that's not quite finished. My intent was to create a group of programmable personalities to play against. Curly, Larry, Moe, Fat Freddy and the rest do play *slightly* different games, but it's not what it could be. Each player should be defined by a TYPE that quantifies their poker behavior in many user-controllable ways. This kind of AI is not easy. I'd also like to add wild cards to see how that changes the odds. And other options come to mind. Someday I'll get back to this. Running POKER: ---------------- Unzip the archive into a directory, and type POKER to run. It works well in a Win3.1 window. (A PIF and generic icon are provided.) I was mostly interested in the stats, so the user interface is simple by design, and the program makes good use of text screens. The startup screen runs a Monte Carlo poker simulation between Curly, Larry, Moe, and Fat Freddy, and reports a wealth of statistics. You can change the number of players (up to 6) in the Options screen. This is real poker: 5 card draw, nothing wild, no limit on opening. Cards are dealt, the different players evaluate their hands and draw new cards, and the results are tabulated as percents and a graph. Press to begin automatic dealing and watch the stats pile up. Press to stop, and keep pressing to deal hand-by-hand. This gives an easy way to understand exactly what the statistics are reporting. Other options are shown on the bottom line. Just press the first letter, eg for New starts the count over, or press for Options. It's not on the menu, but will save a text screen dump as the file DUMPn.TXT in your directory, starting with n=1 for each session. The entire deck is shown, and you can retrace the play by studying it. In this hand, Curly was dealt the 2 and then Larry got the 2, etc. (The other players are shown in the program.) I captured this screen dump by pressing from the main screen. The deck 2 2 10 7 5 5 8 Q 3 9 4 J 9 J A 5 A 7 4 6 3 10 7 10 2 5 6 A 4 J K 8 3 2 3 7 Q Q J K K 8 9 4 10 6 A Q 8 K 6 9 Curly has won 69 games so far. He received {2 3 5 9 A} on the deal, kept the ace and drew 4, ending up with {3 7 10 10 A} for a pair of tens with an ace high. (He lost.) -------------------------- -------------------------- | Curly 69 | | Larry 70 | | 2 3 5 9 A | | 2 5 7 9 J | | 3 7 10 10 A | | 2 5 6 J A | | one pair | | high card | -------------------------- -------------------------- 1008 hands have been dealt since I froze the play by pressing . The bar graph changes scale dynamically as play continues. So far each * represents 32+ hands, and a dot means something less than 32. Wins are shown in red on the screen. hands * = 32 count %deal %draw %up %win %hi %lo high card .******* 278 50.20 27.58 46.8 0.4 0 100 one pair *************** 509 42.16 50.50 26.4 38.9 19 81 /------> two pair *** 118 4.27 11.71 11.6 27.0 58 42 | three of a kind ** 71 2.68 7.04 14.8 22.6 80 20 | straight . 7 0.50 0.69 0.0 2.4 86 14 | flush . 8 0.10 0.79 0.0 2.8 88 13 | full house . 13 0.00 1.29 - 4.4 85 15 | four of a kind . 4 0.10 0.40 0.0 1.6 100 0 | straight flush 0 0.00 0.00 - 0.0 - - | royal flush 0 0.00 0.00 - 0.0 - - | total count: 1008 | In this case, TWO PAIR has come up 118 times (after the draw). 4.27% of the deals were two pair. This was brought up to 11.71% after the draw. 11.6% of the hands that were dealt two pair improved after the draw. Two pair was the winning hand in 27% of the games. 58% of the time it was the highest hand, but 42% of the time it wasn't. So two pair is only slightly better than even money. Of course "slightly better" is all you need in the long run with proper betting! Select tat from the menu for more analysis, eg how many inside straights came in after the draw. There's lots of info! Playing a Game: ----------------- You can play poker against Curly, Larry, and Moe! Press for Game at the main screen. Your game name will be "Treebeard" unless you change it in the main ptions menu (10 letters max). You can also change the number of players in that menu. The action is mostly controlled with the , , and keys. Press <+-> to change your bet, and use the arrow keys and or just press <1-5> to toggle cards for the draw. Your choices are always shown on the bottom line, and they change at different points in each game, so keep an eye on them! You can't take back an action, but you can eplay a hand over again. ank gives everyone an extra wad of cash. tats and istory keep track of who's won what. ew starts over. Press to return to the main screen. File list: ------------ The files below the dotted line are source files that can be deleted if you like. POKER16.BAS will NOT run with the QBasic interpreter since it uses a library and user TYPEs. It should run fine with Quick Basic, but I haven't tried it. It was easiest to just load my whole TBLIB library, but it only uses 2 routines in ScreenGet() and ScreenPut() to save a copy of the text screen in an array. It should be easy to code an alternative. As it is, you must start Basic with "/L tblib" to load the library, or use the XQB.BAT batch file. There's some good code in here for shuffling, showing, and evaluating cards that could be useful for other games. Help yourself. POKER.EXE DOS executable for x286 or better POKER.ICO an icon for Win3.1 POKER.PIF Win3.1 pif file, works well in a window README.TXT this file TBVAULT.TXT about Treebeard's Basic Vault ------------ POKER17.BAS Basic source code TBLIB.LIB library for BC TBLIB.QLB quick library for PDS IDE TBLIB.TXT about the library MAKE.BAT batch file to compile and link from DOS prompt XQB.BAT batch file to start PDS with library and load code Conditions: ------------- This program and source code are yours to use and modify as you will, but they are offered as freeware with no warranty whatsoever. Give me credit, but do not distribute any changes under my name, or attribute such changes to me in any way. You're on your own! Send comments and fixes to: Marc Kummel aka Treebeard mkummel@rain.org http://www.rain.org/~mkummel/ For more interesting Basic software with source code, check out Treebeard's Basic Vault at http://www.rain.org/~mkummel/basic/