home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Global Amiga Experience
/
globalamigaexperience.iso
/
text_dtp
/
editor
/
turbotext
/
rexx
/
hanoi.ttx
< prev
next >
Wrap
Text File
|
1995-07-10
|
3KB
|
196 lines
/** $VER: Hanoi.ttx 2.0 (14.3.94)
**
** Towers of Hanoi toy.
**
** Written by Mikael Karlsson
** Modified by Martin Taillefer
**/
OPTIONS RESULTS
PARSE ARG disks
ADDRESS TURBOTEXT
OpenDoc
IF RC = 0 THEN DO
ADDRESS VALUE RESULT
'SetStatusBar Towers of Hanoi'
SetCursor OFF
SetInputLock ON
SetDisplayLock ON
IF disks = "" THEN disks = 4
IF disks < 1 THEN disks = 1
IF disks > 9 THEN disks = 9
pegs.0 = "999"
pegs.1 = "999"
pegs.2 = "999"
clockwise.0 = 1
clockwise.1 = 2
clockwise.2 = 0
diskstr.1 = " XXXX "
diskstr.2 = " XXXXXX "
diskstr.3 = " XXXXXXXX "
diskstr.4 = " XXXXXXXXXX "
diskstr.5 = " XXXXXXXXXXXX "
diskstr.6 = " XXXXXXXXXXXXXX "
diskstr.7 = " XXXXXXXXXXXXXXXX "
diskstr.8 = " XXXXXXXXXXXXXXXXXX "
diskstr.9 = " XXXXXXXXXXXXXXXXXXXX "
pegstr = " || "
InsertLine
InsertLine
'Text " 'copies(' ',72)'"'
InsertLine
RecordMacro QUIET
'Text " 'pegstr' 'pegstr' 'pegstr'"'
InsertLine
EndMacro
PlayMacro 10
'Text " 'copies('T',72)'"'
InsertLine
UpdateView
DO i = disks TO 1 BY -1
CALL OnPeg(0,i)
pegs.0 = i pegs.0
END
pegwithsmallest = 0
DO FOREVER
CALL DoMove(pegwithsmallest,clockwise.pegwithsmallest)
pegwithsmallest = clockwise.pegwithsmallest
pegafter = clockwise.pegwithsmallest
pegbefore = clockwise.pegafter
IF pegs.pegbefore = "999" & pegs.pegafter = "999" THEN DO
LEAVE
END
IF Word(pegs.pegbefore,1) < Word(pegs.pegafter,1) THEN DO
CALL DoMove(pegbefore,pegafter)
END; ELSE DO
CALL DoMove(pegafter,pegbefore)
END
END
'SetStatusBar Temporary Done!'
MoveSOF
SetInputLock OFF
SetDisplayLock OFF
SetCursor ON
END
EXIT
DoMove:
ARG src,dest
disk = Word(pegs.src,1)
CALL OffPeg(src,disk)
CALL MoveOver(src,dest)
CALL OnPeg(dest,disk)
PARSE VALUE pegs.src WITH disk pegs.src
pegs.dest = disk pegs.dest
RETURN
MoveOver:
ARG src,dest
pos = src*25+2
destpos = dest*25+2
Move 3 1
IF pos < destpos THEN DO
RecordMacro QUIET
'Text " "'
UpdateView
EndMacro
PlayMacro destpos-pos
END; ELSE DO
RecordMacro QUIET
Delete
UpdateView
EndMacro
PlayMacro pos-destpos
END
RETURN
OnPeg:
ARG peg,disk
Move 3 peg*25+2
Delete 22
'Text "'copies(' ',22)'"'
MoveLeft 22
UpdateView
MoveDown
Delete 22
'Text "'diskstr.disk'"'
MoveLeft 22
destpos = 10 - Words(pegs.peg)
IF destpos > 0 THEN DO
RecordMacro QUIET
Delete 22
'Text "'pegstr'"'
MoveLeft 22
UpdateView
MoveDown
Delete 22
'Text "'diskstr.disk'"'
MoveLeft 22
UpdateView
EndMacro
PlayMacro destpos
END
RETURN
OffPeg:
ARG peg,disk
pos = 15 - Words(pegs.peg)
IF pos > 3 THEN DO
Move pos peg*25+2
RecordMacro QUIET
Delete 22
'Text "'pegstr'"'
MoveLeft 22
UpdateView
MoveUp
Delete 22
'Text "'diskstr.disk'"'
MoveLeft 22
UpdateView
EndMacro
PlayMacro pos-3
END
RETURN