{ Game of NIM. Author: J. E. Steitz 2-14-82 BASE 1 P,IN( PILE( )2: ,<"*******************************************************************************"]F"*******************************************************************************"P"** **" Z"** **"bd"** **"n"** **"x"** If you ";: ,:"DO";: ,?" want instructions, just hit RETURN (";();();();") key. **""*******************************************************************************""*******************************************************************************" ,"Welcome to the game of NIM."'  ,a"If you do NOT want instructions, type N or NO: ",A$ A$ "N" A$ "n" A$"NO" A$"no" ^:" The Game of NIM -- By J. E. Steitz 2-16-82"1:"The game of NIM is an ancient game of skill and strategy. The game is played""with any number of piles of objects. The two players take turns removing any""number of objects from one of the piles. You can take one object or the whole""pile, but you can't take objects from two piles."d:"As agreed upon before the start of the game, the winner is the one who""takes (or doesn't take) the last object from the last pile.":"In this version of the game, you can elect to have up to 12 piles of objects,"+""with up to 15 objects in each pile.":u,"From here on out, just respond to the questions as they come up.":6"Oh, by the way, if you want to concede a game, just enter 0,0 when it's your" @"move. Your IBM Personal Computer gladly accepts forfeits."BJ::" GOOD LUCK!":::T"When you have finished reading this, just press the return key. ",A$^::"How many piles (1-12)";NPILESh NPILES  NPILES  |r:"Come, now - enter a number between 1 and 12": ^N|:"you may have from 1 to 15 items in each pile."e PCT  NPILES "How many in pile ##";PCT; PILE(PCT) PILE(PCT)  PILE(PCT)  :"You must enter a number between 1 and 15":  PCTH:"Does taking the last item Win (W) or Lose (L) the game";A$~ A$ "L" A$ "l" A$ "w" A$ "W" :"PLEASE answer with W or L. Now try again": WOPT$"take" A$ "L" A$ "l" WOPT$ "notake"!:"Do you want to move first (Y,N)";A$W A$ "y" A$ "Y" A$ "n" A$ "N" :"You MUST answer Y for yes, or N for no. Try again.": FIRST$"IBMPC" A$ "Y" A$ "y" FIRST$ "player"&WIN$ "no"0 : FIRST$ "IBMPC" bD L4N WIN$"no" >X vHb `l WIN$"no" Lvv WIN$"no" : WIN$"player" * WIN$"IBMPC" : :"Ho, hum --- I win again...":"Want to play another";A$" A$ "y" A$ "Y" A$ "n" A$"N" _ :"Please, just a simple Y or N. Try again.":  A$ "Y" A$ "y" ^ IBMPC MOVEPCTW PCT NPILES PILE(PCT)  PCTWIN$"IBMPC" WOPT$ "take" WIN$"player"  " 9 PILEWPILE(PFIRST)I*PCTWPFIRST\4 PNZ y> PILE(PFIRST)  pHPILE(PFIRST)RWIN$"player"\ WOPT$"take" WIN$"IBMPC"f p WOPT$"take" PILE(PFIRST):WIN$"IBMPC": zPILE(PFIRST) C PALLONE PILE(PFIRST): M &a PCTW tPCTWNPILES PCTW  PILE(PCTW) PILEWPILE(PCTW)TPILE!PILEWPILE(PCTW)(TPILE!)   0 PALLONE WOPT$"take" PILE(PCTW)D I : IN _$ PCTW . "I took ## from pile ";PILEWPILE(PCTW);8 PCTWBL Player's move V"Enter pile number and the number you want to remove, separated by a comma."8 `"Enter 0,0 if you want to concede the game."^ j"For example: 2,7 ==> ",PPN,PREMu t PPNPREM  ~ PPN PPNNPILES  :"That pile number doesn't exist. Try one we are playing with.": V! PREM PREMPILE(PPN) e! ::"You can't take zero items and you can't take more than the pile contains.": V!PILE(PPN)PILE(PPN)PREM! !!WIN$"IBMPC"! :! DISPLAY PILES ROUTINE!! PHT   " PCT  NPILES#" PILE(PCT) PHT " ";H"  PILE(PCT) PHT "O-O ";R" PCTX"b"( PHTy"2 PCT  NPILES"< "## ";PCT;"F PCT"P:"Z PCT  NPILES"d "(##) ";PILE(PCT);"n PCT"x"# RAZZBERRY ROUTINE# ,# I  +# Z,?# J : JJ# (,^# J : Jf# Iq# (,w## FANFARE ROUTINE#"t140mbo2c8f8a8o3c8c16c16c8o2a8a16a16a8f8a8f8c"#"mbo2c8f8a8o3c4o2a8o3c.."$=$ MAKE ALL BIT COLUMNS EVEN ROUTINE$" REQUIRES PCTW - THE 'WORKING' PILE NUMBER AND NPILES - PILE COUNT$,PILE(PCTW)$6MASK$@ I $JPBC$T PCT NPILES$^ PILE(PCT) MASK PBCPBC$h PCT(%r PBC  PILE(PCTW)PILE(PCTW) MASK8%|MASKMASK@% IF%% CHECK PILE STATUS ROUTINE% If all piles contain one, sets pallone = 1% If all piles are empty, pnz is set to zero, else it counts non-emptiesA& PFIRST is set to the pile number of the first non-empty pile.N&PNSAVEX&PNZf&PALLONE{& PCT NPILES& PILE(PCT) PALLONE& PILE(PCT) PNSAVE PNSAVEPCT& PILE(PCT) PNZPNZ& PCT&PFIRSTPNSAVE'C'& ANALYZE BIT COLUMNS ROUTINE'0 IF any bit column is odd, sets PCTW to the pile number of the biggest': pile having a bit in the odd column and sets PILEW to'D the number of items in that pile.:(N IF ALL BIT COLUMNS ARE EVEN, SETS BOTH THE ABOVE VALUES TO ZERO.G(XMASK V(b I  `(lPBCm(vPNSAVE|(PILESAVE( PCT NPILES(M PILE(PCT) MASK( M (PBCPBC) PILE(PCT) PILESAVE PILESAVEPILE(PCT):PNSAVEPCT ) PCT)MPBC () M  8)MASKMASK@) IL)PILEWW)PCTW])p) PILEWPILESAVE)PCTWPNSAVE) )* PLAYER WINS DISPLAY ROUTINE)4"mbt162o2c4e4e4g4g4o3c4c4e4e4c4c4o2g4g4e4e4")> I  *H ,*R#*\ I  ,d*f I  "mbt162o3e8e-8d4o2b4b4g4g4f4f4o3d8e8c4c4c4c4c4."*p"*******************************************************************************"+z"*******************************************************************************"i+"******** ********* ******* ********* ******** ******************"+"********** ***** ******* ****** ******* ******** ******************","************ * ******* ********** ***** ******** ******************"n,"************** ********* ********** ***** ******** ******************","************** ********* ********** ***** ******** ******************"-"************** *********** ****** ******** ****** *******************"s-"************** ************* ************ *********************"-"*******************************************************************************"- I ,4."********************************************************************** ******"."********* *************** *** ***** ********* *********** *******"."********** ************* ***** ****** ******* ********** ********"9/"*********** *********** ****** ****** * ***** ********* *********"/ "************ *** *** ******* ****** *** *** ******** **********"/ "************* * * ******** ****** ***** * ******* ***********">0 "************** * ********* ****** ******* *********************"0$ "*************** *** ********* ***** ********* ***** *************"0. "*******************************************************************************"C18 "*******************************************************************************"K1B IU1L ,[1V a1` *****"C18 "*******************************************************************************"K1B I