/ :[ :*********************************** :* * :* TOWERS OF HANOI (Recursive) * :* @ *  :* @@@ *7 :* @@@@@ *c :* @@@@@@@ * :* @@@@@@@@@ | | * :* Modified for IBM PC by * :* Marty Smith SOURCE ST2259 * :* HOU.,TEX COMPUSERVE 72155,1214 *; :*********************************** BASIC recursive routine from COMPUTE, July 1982, p. 58. Article by Earl Wuchter. This program is best displayed on an 80-col RGB color monitor, although it will also work on the Monochrome Display. I have both boards and this program first shifts to Color and defines KEY 7 as a toggle between boards.7 The program first asks which board to use. If you are using one board in your system, you might want to delete line 31, which controls this function." I am using a SONY Profeel monitor in RGB mode, which displays 8 colors. --Lines 76 and 1010 draw disks in 7 colors. For 15 change MOD 7 to MOD 14. --Line 33 shifts display to the right. OUT 980,2:OUT 981,90 is standard. Line 40 defines the character to draw disks, which is CHR$(1). Try other values for different effects.v If you use the color board with an RF modulator or a composite monitor, you may get no color on your display. This is due to the 80-col mode, which is very demanding of TV's. Stick with the monochrome display or-- you might try using mode COLOR 1,0 and using LINE ,BF or DRAW type statements for the disks, but this would mean a lot of work.k Remove the ' in lines 130 and 250 to display the depth of recursion during the routine.Z Integers are used for speed. This limits the routine to 15 disks, or 32767 moves. Using single precision you could solve for 21 disks in 7 days, or 2,097,151 moves! Here disks are limited to 13 to fit the 80-col. display. I have coded this routine into MMS FORTH, which has just been released for IBM PC. I had to put a delay routine in because the display was TOO rapid! AZ ,"GOSUB 65000"( ): "Use Color or Monochrome board (C / M)";C$: (C$,)"c" (C$,)"C" TOG:  : (C$,)"m" (C$,)"M" TOG:  : ! ,: ,W: : 87 is for shifting horizontal screen position$ ,,G(Y$(,):EZ$(): : 1 is character used to make disks{- N(),F(),T(),D$(),HERE( ,),HEIGHT()2T$(,)():P$T$T$T$T$T$<Z:: ,: ,: "TOWERS OF HANOI": ,: : "Number of Disks (1 TO 13) ";N()F N()  N()  <YGPRINTER$"": "Print results on Printer? (Y to Print) ";HPRINTER$: PRINTER$"Y" PRINTER$"y" )"TOWERS OF HANOI FOR"N()"DISKS"I PRINTER$"" HJ ,:C: ,: (): X C: (P);:DK X N():D$(X)(, ):(D$(X),X,X)Y$:: TOG MLTOPN(): X N():HERE(X,)TOPX:HERE(X,): TOPX,: X  ,: D$(X);:: ,: ,: "TOWERS OF HANOI FOR"N()"DISKS": ,: ,: (P,);: ,: OMTOPN(): X N():HERE(X,)TOPX:HERE(X,): TOPX,: D$(X);:: ,: ,: "TOWERS OF HANOI FOR"N()"DISKS": ,: ,: (P,);: ,OHEIGHT()TOP:HEIGHT():HEIGHT()PF()ZT()d xn ,: "DONE IN"Z"MOVES"s "DO AGAIN? ( Y/N )";ftAGAIN$: AGAIN$"y" AGAIN$"Y" < : AGAIN$"n" AGAIN$"N" pu tzxGG} Remove ' in Line 130 and 250 to show depth of recursion :LOCATE 3,26+G:PRINT SPACE$(22):LOCATE 3,26:COLOR 1,0:PRINT LEFT$(P$,G):COLOR 7,0# N(G) 5 N(G)N(G)E F(G)F(G)\ T(G)F(G)T(G)f x ZZ: PRINTER$"y" P$"Y" );"## DISK No. # FROM # TO #";Z,N(G),F(G),T(G)  N(G)N(G) F(G)F(G)T(G)!T(G)T(G)! x!GGp!:LOCATE 3,26+G:PRINT SPACE$(22):LOCATE 3,26:COLOR 1,0:PRINT LEFT$(P$,G):COLOR 7,0v!! T(G) COL : T(G) COL : T(G) COL6! TOG N" HERE(N(G),),HERE(N(G),): ,: EZ$;:HEIGHT(F(G))HEIGHT(F(G)): HEIGHT(T(G)),COL: N(G)  ,: D$(N(G));: ,: " HERE(N(G),),HERE(N(G),): EZ$;:HEIGHT(F(G))HEIGHT(F(G)): HEIGHT(T(G)),COL: D$(N(G));"HERE(N(G),)HEIGHT(T(G)):HERE(N(G),)COL:HEIGHT(T(G))HEIGHT(T(G))#L# TOG TOG : TOG3# TOG 8, 9#U# toggle color graphics# P: SEG: A( ): ,(A ) #$ : : ,,,,: ,,,: P#.#8 toggle monochrome display#L SEG: A( ): ,A 0$V P: ,,, , : ,, $`,