/* Plays Towers of Hanoi on Reqtools requesters... Just needed to do something silly for a change :-) Send comments to knikulai@utu.fi Rules: Move all disks from the leftmost pin to the rightmost pin. Only smaller disk may be put on a larger one. Game ends when all disks are in the rightmost pin If you can solve the game in less than 15 moves, you are pretty smart. */ options results call addlib('rexxreqtools.library',0,-30,0) /* Change the following line, if you want to change the screen or font. The font needs to be non-proportional. */ tags='rt_pubscrname=Default rt_font=topaz.font/9 rtez_defaultresponse=0' buts=' _1 | _2 | _3 |_Quit' title='Towers of Hanoi by Kai Nikulainen' /* Constants */ NL='0a'x pin.1='51234' pin.2='55555' pin.3='55555' pin.9='55555' disk.5=' | ' disk.1=' === ' disk.2=' ===== ' disk.3=' ======= ' disk.4='=========' Q1='Which disk should be moved next?' Q2='Where should I move disk' TheEnd='Congratulations! You have solved the puzzle of' || NL TheEnd=TheEnd || 'Towers of Hanoi! It only took you' movecount=0 do until pin.3='51234' movecount=movecount+1 txt='' do i=1 to 5 d1=substr(pin.1,i,1) d2=substr(pin.2,i,1) d3=substr(pin.3,i,1) txt=txt || disk.d1' 'disk.d2' 'disk.d3 ||NL end txt=txt || '--- 1 -------- 2 -------- 3 ---' from=9 do until topmost(from)<5 from=rtezrequest(Q1 NL NL || txt,buts,title,tags) if from=0 then exit end to=rtezrequest( Q2 from NL NL || txt,buts,title,tags) if topmost(from) < topmost(to) then call move(from,to) end call rtezrequest(TheEnd movecount 'moves!','_Exit game',title,tags) exit move: parse arg f,t a=topmost(f) pin.f=translate(pin.f,'5',a) p=lastpos('5',pin.t) tmp=pin.t pin.t=left(pin.t,p-1) || a if p<5 then pin.t=pin.t || substr(tmp,p+1) return topmost: parse arg p x=6 i=5 do while substr(pin.p,i,1)