naz@hslrswi.hasler.ascom.ch (Norman H. Azadian) (04/21/91)
Here's a good version of the Klondike (solitaire) card game for which I posted a beta version some time ago. This is the result of an international joint effort between me in Switzerland and Richard Goerwitz in Chicago. Six parts are necessary to keep each one under 20KBytes. Note that the unix end-of-line convention (just a newline) is used, so you might need to take special measures with your editor under DOS. Note also that the tab interval is 4. NHA --- PAPER: Norman Azadian; Ascom AG; Belpstrasse 23; 3000 Berne 14; Switzerland INTERNET: naz%hslrswi.uucp@uunet.uu.net UUCP: ...{uunet,ukc,mcvax,...}!chx400!hslrswi!naz VOICE: +41 31 63 2178 BITNET: naz%hslrswi.UUCP@cernvax.BITNET #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # readme # klondike.man # makefile.dos # makefile.unx # klonstub.icn # This archive created: Sun Apr 21 15:03:00 1991 # By: Norman H. Azadian (Hasler AG) export PATH; PATH=/bin:$PATH echo shar: extracting "'readme'" '(4587 characters)' if test -f 'readme' then echo shar: will not over-write existing file "'readme'" else cat << \SHAR_EOF > 'readme' README 910330 NHA version 3.00 Just when you'd about given up hope, Klondike is finally being released in "final" form. It's bigger and slower than ever, and chock full of marginal features. It should, however, run on just about any PC or unix machine known to man. In case you didn't catch the initial beta release, Klondike is an Icon implementation of the single-player card game variously known under such names as Solitaire or Patience. When you get tired of playing, you can let the machine take over for you. INSTALLATION - DOS ================== For a fast start simply: icont -c iolib kloncon klonsub klonstr icont -u -Si1000 -Sn2000 klondike iconx klondike Later you might want to move IOLIB.ICN to your Icon library directory, and compile it there. If you have "make" on your machine, you can copy "makefile.dos" to "makefile", and use make to build klondike.icx for you. INSTALLATION - UNIX =================== For a fast start simply: icont -c iolib cp makefile.unx makefile make iconx klondike Later you might want to move IOLIB.ICN and GETCHLIB.ICN to your Icon library directory, and compile them there. NOTES ===== Richard Goerwitz provided the GETCHLIB library package to allow operation under unix. He also provided the IOLIB library package that is essential if your terminal isn't ANSI compatible. He assures me that it should be adequate for most terminals currently in use. If, however, you are stuck with an old slow terminal that requires padding, you will need his industrial-strength ITLIB package instead of IOLIB. You can get this direct from Richard at "goer%sophist@gargoyle.uchicago.edu". All suggestions, bug reports and compliments for these libraries should be directed to Richard. All of these libraries will probably become available in the Icon Program Library at some point in the future. On a PC the "A" and "C" commands can be interrupted by hitting (nearly) any key on the keyboard. Under unix, the natural way to do this would be to use SIGINT. Alas, for the sake of portability we had to forgo this feature. This is because the terminal needs to run in raw mode to implement the getch() function, and signals aren't available in raw mode. With BSD this could be handily solved by using cbreak mode instead of raw mode, but that isn't a possibility under SysV. The kbhit() that DOS uses doesn't port well to unix. If for some reason you can't/won't run an ANSI driver on your PC, it is possible to run with the termcap capabilities provided by IOLIB. To do this you will need a TERMCAP file. I have such a beast, as does Richard, but I have not included it in the distribution because probably no one will actually use it. If you are the exception, you can get it from one of us, or you could write it yourself. For terminals with only 24 lines, a kluge is necessary in order to display the maximal-length stack of 12 cards. The top card (at the bottom of the screen) is moved up one row so that it covers up the suit and rank of the card it rests upon. However, you know it must be a 3, and it can't be used anyway until the 2 on top of it is put onto its ace pile. One of the excuses for writing this was to have a means of evaluating various strategies for playing klondike solitaire. A strategy is easily coded in klonstr.icn, and then tested with a batch file that uses the -S, -B and -I options. On my AT clone, Klondike can pump out nearly 5 games per minute in batch mode, thus an overnight run can produce 3000-4000 games worth of statistics. And under unix you can run it in background with "nice" to soak up those excess machine cycles. On a PC, the size of the .ICX file is limited to 65KBytes. As long as you are running an ANSI driver, you don't actually need IOLIB, and you can save a bunch of space in KLONDIKE.ICX by stubbing it out. This will probably be essential if you want to add any play strategies to klonstr.icn. Assuming that your IOLIB is in a library directory distinct from where you keep your Klondike, you can accomplish this by simply doing the following in your Klondike directory: copy klonstub.icn iolib.icn icont -c iolib I am very interested in suggestions, ideas, speed ups, and above all, bug reports. I'd also like to hear about your experiences with alternate strategies. Enjoy! NHA --- PAPER: Norman Azadian; Ascom AG; Belpstrasse 23; 3000 Berne 14; Switzerland INTERNET: naz%hslrswi.uucp@uunet.uu.net UUCP: ...{uunet,ukc,mcvax,...}!chx400!hslrswi!naz VOICE: +41 31 63 2178 BITNET: naz%hslrswi.UUCP@cernvax.BITNET SHAR_EOF if test 4587 -ne "`wc -c < 'readme'`" then echo shar: error transmitting "'readme'" '(should have been 4587 characters)' fi fi # end of overwriting check echo shar: extracting "'klondike.man'" '(9788 characters)' if test -f 'klondike.man' then echo shar: will not over-write existing file "'klondike.man'" else cat << \SHAR_EOF > 'klondike.man' NAME klondike -- one of the many versions of solitaire SYNOPSIS klondike [-AQZ] [-B[gameCount]] [-D[directory]] [-I[reportInterval] [-P[phraseFile]] [-RrandomSeed] [-Sstrategy] [-T[termType]]") DESCRIPTION A popular variation on the Klondike version of Solitaire (or Patience) as described on page 181 of my 1963 version of "Hoyle's Rules of Games". The difference is that here we go through the deck (stock) 3 cards at a time instead of one-by-one, and we allow it any number of times. This program runs best on a PC with a color monitor. It will run on any system providing an ANSI-compatible screen by simply giving option -Tmono or -Tcolor as appropriate. Further, thanks largely to Richard L. Goerwitz's encouragement, help and excellent iolib package, it should run on just about any (non-magic-cookie) terminal supported by termcap. OPTIONS Except for strategy, options may be either upper or lower case. They may be given in any order. Parameters follow their options with no whitespace inbetween. Each option must be given as a separate argument. Except for toggling options, only the last occurence of an option is honored. -A By default uncovered Ace cards are automatically promoted to an Ace pile. This option toggles that behaviour. Note that, in any case, it is not allowed to put an Ace onto a stack, as this could lead to building stacks which are too big to display with a 25 line screen. Some computer-play strategies will unilaterally disable this option during programmed play. -B[count] Batch mode. The requested number of games is played and a line of ASCII is written to standard output with four tab-separated numbers: random seed, number of games played, number of games won, and number of cards promoted to the ace piles. Before exiting, the usual additional statistics are dumped (with explanatory text) to stderr. If the count is 0 or missing, games are played forever (or until interrupted). In batch mode play can always be terminated with an interrupt from the user, as defined by system- dependent routine userInterrupt() in kloncon.icn. Under DOS this consists of entering any character from the keyboard. No I/O is ever done other than that described above. In particular, the checkpoint file, klondike.sav, generated by a previous Boss command, is ignored in batch mode. -D[dir] gives the directory to be used for all file I/O. The dir string is simply pre-pended to all filenames, including the phrase file if given. If dir is not given, environment variables $HOME and then $ROOTDIR are tried. Failing these, the current directory is used. -I[reportInterval] enables intermediate reporting of results when running in Batch mode. Default is 1. -P[file] Normally an incorrect keystroke is greeted by one of a set of stock phrases. With this option phrases are instead taken from the indicated file, 1 per line, up to 16 printing characters each. For the hard of humor, funny phrases may be disabled altogether by giving the option without any file name. -Q toggle Quiet mode. Klondike is initially noisy, with clicks for card movement and bells for getting attention. With this option there are no clicks, and bells are visual if possible. -Rseed set the random seed to the designated value. -Sstrategy allows the user to determine which of the programmed strategy play possibilities will be used for all computer play (commands Automatic and Continuous). The default strategy is called "takeFirst", others may be discovered by reading file klonstr.icn. NOTE that case IS important in the strategy name. -T[termtype] use termcap instead of assuming that this is a PC with an ANSI screen. If termtype is given then that name is sought in /etc/termcap, otherwise environment variables TERMCAP and TERM are consulted in the usual manner. Termcap screens are always considered to be monochrome. Three special (case-independent) values for termtype are defined: PC, MONO, and COLOR. PC gives the default behaviour, i.e. an ANSI driver (ANSI.SYS or compatible) must be running, and the BIOS is consulted to see whether it is monochrome or color. This BIOS dependency is avoided with COLOR and MONO. -Z toggle debugging mode. In debugging mode the debug command (Z) is allowed. Debugging mode is initially disabled since it allows cheating. COMMANDS H or ? display a Help screen. Under DOS, F1 also works. ^L (control-L) redraws the screen A Automatic mode. Plays the game until nothing useful remains to be done, or until any key is struck. B Boss key. The screen is blanked and the current position is saved. When the game is started again in the usual way, this saved game will be automatically restored and the save file deleted. C Continuous mode. The computer plays games automatically until interrupted. Two statistics are displayed: the number of games already played, and the total number of aces which have been promoted to the ace piles. F Find next useful move, thumbing as necessary. If invoked immediately again, the move is performed and the next one is sought. Note that unless automatic ace mode is disabled with the -A option, ace promotion will be automatic, and not considered as a useful move. Note also that no strategy is used, i.e. the move found is not necessarily the best. M Move a card from the deck or a stack to a stack or an ace pile. Q Quit this game, with the opportunity to play another. S Suggest a possible move. Hitting this key multiple times results in multiple suggestions being displayed. When there is nothing interesting left to do, it will suggest "Thumb". Otherwise the possibilities are listed in no particular order. T Thumb. Remove the top 3 cards from the face-down deck and turn them over (as a group) onto the face-up deck. U Undo. This can be used all the way back to the start of the current game. Z Debug. This is only enabled when the -Z option has been given on the command line. There is a sub-menu of commands available, including a (very brief) Help summary. The Move command takes two parameters: source and destination. Possible sources are: D for the Deck of face-up cards; and a number from 1 to 7 inclusive, meaning the corresponding stack. Possible destinations are the stacks (1-7) and A for the appropriate ace pile. For instance, to move the visible card from the face-up deck to stack 4, one types the three characters: "MD4". Actually, the "M" character itself is optional, which explains why the "debug" command isn't invoked with a "D". ENVIRONMENT VARIABLES KLONDIKE the contents of this variable are pre-pended to the command line. HOME, ROOTDIR used for directory when -D given without arg. TERM, TERMCAP used for terminal type determination as usual. FILES klondike.sav Boss key checkpoints the position here. klondike.sv? State checkpointed here with the S debug command. "?" can be any (upper-case) character legal in your filesystem. BUGS On 24-line terminals you will have to guess at the suit of the next-to-top card in a maximal-length stack. "Continuous" command not (gracefully) stoppable under SYS V unix. Slow, particularly with non-ANSI terminals. The program's play is simplistic; no interesting strategic play has yet been programmed. The average time statistic is sometimes wrong for PCs, and is always wrong when the Boss command has been used. ACKNOWLEDGEMENTS The termcap capability was contributed by Richard L. Goerwitz. The inspiration, name, and some elements of the user interface were lifted wholesale from a computer game copyrighted in 1985 by Allyn Wade. VERSION 3.01 -- 30 March, 1991 AUTHOR Norman H. Azadian naz@hslrswi.com SHAR_EOF if test 9788 -ne "`wc -c < 'klondike.man'`" then echo shar: error transmitting "'klondike.man'" '(should have been 9788 characters)' fi fi # end of overwriting check echo shar: extracting "'makefile.dos'" '(506 characters)' if test -f 'makefile.dos' then echo shar: will not over-write existing file "'makefile.dos'" else cat << \SHAR_EOF > 'makefile.dos' #makefile.dos 910322 NHA #A DOS makefile for klondike # #Assumes that iolib.u? is already available somewhere along $IPATH. #If you don't want to use iolib (because you have an ANSI screen/terminal #and you are running out of memory) then you can do the following: # cp klonstub.icn iolib.icn # icont -c iolib.icn .SUFFIXES: .u1 .icn .icx .icn.u1: icont -c $? klondike.icx: klondike.icn kloncon.u1 klonstr.u1 klonsub.u1 icont -u -Si1000 -Sn2000 klondike clean: rm -f *.u? klondike.icx SHAR_EOF if test 506 -ne "`wc -c < 'makefile.dos'`" then echo shar: error transmitting "'makefile.dos'" '(should have been 506 characters)' fi fi # end of overwriting check echo shar: extracting "'makefile.unx'" '(444 characters)' if test -f 'makefile.unx' then echo shar: will not over-write existing file "'makefile.unx'" else cat << \SHAR_EOF > 'makefile.unx' #makefile.unx 910322 NHA #An unix makefile for klondike # #Assumes that iolib.u? and getchlib.u? are already available somewhere #along $IPATH. #Note that only getchlib is linked on the command line. Everything else #is linked in the program. .SUFFIXES: .u1 .icn .icn.u1: icont -c $? klondike: klondike.icn kloncon.u1 klonstr.u1 klonsub.u1 getchlib.u1 icont -u -Si1000 -Sn2000 klondike getchlib.u1 clean: rm -f *.u? klondike SHAR_EOF if test 444 -ne "`wc -c < 'makefile.unx'`" then echo shar: error transmitting "'makefile.unx'" '(should have been 444 characters)' fi fi # end of overwriting check echo shar: extracting "'klonstub.icn'" '(571 characters)' if test -f 'klonstub.icn' then echo shar: will not over-write existing file "'klonstub.icn'" else cat << \SHAR_EOF > 'klonstub.icn' #klonstub.icn 910310 NHA #Stubs for iolib.icn #Copy this file to iolib.icn to reduce runtime memory requirements. #Obviously this will only be effective if you have an ANSI screen/terminal. procedure setname (term) stop ("klondike: invoked stub version of setname(", image(name), ")") end procedure getval (id) stop ("klondike: invoked stub version of getval(", image(id), ")") end procedure igoto (cm, dstcol, dstline) stop ("klondike: invoked stub version of igoto()") end procedure iputs (cp, affcnt) stop ("klondike: invoked stub version of iputs()") end SHAR_EOF if test 571 -ne "`wc -c < 'klonstub.icn'`" then echo shar: error transmitting "'klonstub.icn'" '(should have been 571 characters)' fi fi # end of overwriting check # End of shell archive exit 0 -- PAPER: Norman Azadian; Ascom AG; Belpstrasse 23; 3000 Berne 14; Switzerland INTERNET: naz%hslrswi.uucp@uunet.uu.net UUCP: ...{uunet,ukc,mcvax,...}!chx400!hslrswi!naz VOICE: +41 31 63 2178 BITNET: naz%hslrswi.UUCP@cernvax.BITNET