, Game of NIM. Author: J. E. Steitz 2-14-829 BASE 1E P,INT PILE( )i ,,:: ,"*******************************************************************************"$"*******************************************************************************"n."** **"8"** **"B"** **"sL"** **"V "**";: :" If you ";: :"DO";:  `" want instructions, just hit RETURN (";();();();") key.";: : " **"hj :"*******************************************************************************"t"*******************************************************************************"~ , :"Welcome to the game of NIM."  ,8"If you do NOT want instructions, type N or NO: ",A$l A$ "N" A$ "n" A$"NO" A$"no" <:" The Game of NIM -- By J. E. Steitz 2-16-82":"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.";:"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.":L "From here on out, just respond to the questions as they come up.":"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."(::" GOOD LUCK!":::d2"When you have finished reading this, just press the return key. ",A$<::"How many piles (1-12)";NPILESF NPILES  NPILES  ZP:"Come, now - enter a number between 1 and 12": <%Z:"you may have from 1 to 15 items in each pile."<d PCT  NPILES^n "How many in pile ##";PCT;nx PILE(PCT) PILE(PCT)  PILE(PCT)  :"You must enter a number between 1 and 15": n PCT:"Does taking the last item Win (W) or Lose (L) the game";A$U 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$. A$ "y" A$ "Y" A$ "n" A$ "N" q:"You MUST answer Y for yes, or N for no. Try again.": FIRST$"IBMPC" A$ "Y" A$ "y" FIRST$ "player"WIN$ "no"  FIRST$ "IBMPC" @" * , WIN$"no" 6 T@ 7J WIN$"no" *MT WIN$"no" i^ WIN$"player"  h WIN$"IBMPC" :  :"Ho, hum --- I win again...":r"Want to play another";A$| A$ "y" A$ "Y" A$ "n" A$"N" 6  j :"Please, just a simple Y or N. Try again.": rV  A$ "Y" A$ "y" <c  "MENU"t  IBMPC MOVE PCTW  PCT NPILES  PILE(PCT)   PCT WIN$"IBMPC"  WOPT$ "take" WIN$"player"  ! x !PILEWPILE(PFIRST)'!PCTWPFIRST:! PNZ lW! PILE(PFIRST)  Nj!&PILE(PFIRST)|!0WIN$"player"!: WOPT$"take" WIN$"IBMPC"!D !N WOPT$"take" PILE(PFIRST):WIN$"IBMPC": !XPILE(PFIRST)!b !"l PALLONE PILE(PFIRST): +"v  ?" PCTW R"PCTWNPILESe" PCTW ~" PILE(PCTW) "PILEWPILE(PCTW)"TPILE!PILEW"PILE(PCTW)(TPILE!)" "  " x # PALLONE WOPT$"take" PILE(PCTW)"# I : I,# =# PCTW m#  "I took ## from pile ";PILEWPILE(PCTW);x# PCTW~# #* Player's move#4"Enter pile number and the number you want to remove, separated by a comma."$>"Enter 0,0 if you want to concede the game."<$H"For example: 2,7 ==> ",PPN,PREMS$R PPNPREM s$\ PPN PPNNPILES p$f:"That pile number doesn't exist. Try one we are playing with.": 4$p PREM PREMPILE(PPN) C%z j ::"You can't take zero items and you can't take more than the pile contains.": 4`%PILE(PPN)PILE(PPN)PREMj% p%%WIN$"IBMPC"% j :% DISPLAY PILES ROUTINE%% PHT   % PCT  NPILES& PILE(PCT) PHT " ";&& PILE(PCT) PHT "O-O ";0& PCT6&@& PHTW& PCT  NPILESm& "## ";PCT;w&$ PCT&. :&8 PCT  NPILES&B "(##) ";PILE(PCT);&L PCT&V &` &j RAZZBERRY ROUTINE&t ,&~ I   ' Z,' J : J(' (,<' J : JD' IO' (,U' o' FANFARE ROUTINE' "t140mbo2c8f8a8o3c8c16c16c8o2a8a16a16a8f8a8f8c"' "mbo2c8f8a8o3c4o2a8o3c.."' ' MAKE ALL BIT COLUMNS EVEN ROUTINE@( REQUIRES PCTW - THE 'WORKING' PILE NUMBER AND NPILES - PILE COUNTQ( PILE(PCTW)\( MASKj( I t(( PBC(2 PCT NPILES(< PILE(PCT) MASK PBCPBC(F PCT(P PBC  PILE(PCTW)PILE(PCTW) MASK(Z MASKMASK(d I)n %)x CHECK PILE STATUS ROUTINEV) If all piles contain one, sets pallone = 1) If all piles are empty, pnz is set to zero, else it counts non-empties) PFIRST is set to the pile number of the first non-empty pile.) PNSAVE) PNZ * PALLONE!* PCT NPILES?* PILE(PCT) PALLONEj* PILE(PCT) PNSAVE PNSAVEPCT* PILE(PCT) PNZPNZ* PCT* PFIRSTPNSAVE* * ANALYZE BIT COLUMNS ROUTINE + 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+" the number of items in that pile.+, IF ALL BIT COLUMNS ARE EVEN, SETS BOTH THE ABOVE VALUES TO ZERO.+6 MASK +@ I  +J PBC+T PNSAVE ,^ PILESAVE",h PCT NPILES:,r M PILE(PCT) MASKJ,| M  X, PBCPBC, PILE(PCT) PILESAVE PILESAVEPILE(PCT):PNSAVEPCT, PCT, MPBC , M  , MASKMASK, I, PILEW, PCTW, - PILEWPILESAVE- PCTWPNSAVE- A- PLAYER WINS DISPLAY ROUTINEt- "mbt162o2c4e4e4g4g4o3c4c4e4e4c4c4o2g4g4e4e4"- I -& ,-0 -: I  ,-D I  "mbt162o3e8e-8d4o2b4b4g4g4f4f4o3d8e8c4c4c4c4c4.">.N "*******************************************************************************".X "*******************************************************************************".b "******** ********* ******* ********* ******** ******************"C/l "********** ***** ******* ****** ******* ******** ******************"/v "************ * ******* ********** ***** ******** ******************"/ "************** ********* ********** ***** ******** ******************"H0 "************** ********* ********** ***** ******** ******************"0 "************** *********** ****** ******** ****** *******************"0 "************** ************* ************ *********************"M1 "*******************************************************************************"`1 I ,1 "********************************************************************** ******"2 "********* *************** *** ***** ********* *********** *******"e2 "********** ************* ***** ****** ******* ********** ********"2 "*********** *********** ****** ****** * ***** ********* *********"3 "************ *** *** ******* ****** *** *** ******** **********"j3 "************* * * ******** ****** ***** * ******* ***********"3 "************** * ********* ****** ******* *********************"4 "*************** *** ********* ***** ********* ***** *************"o4 "*******************************************************************************"4 "*******************************************************************************"4 I4* ,44 4>