home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
64'er Special 21
/
64er_Magazin_Sonderheft_21_19xx_Markt__Technik_de_Side_B.d64
/
hanoi
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
2KB
|
106 lines
0 rem >>> tuerme von hanoi <<<
1 rem
2 rem demo zum rekursiv-basic von:
3 rem
4 rem ***** thomas kolbe *****
5 rem
6 rem demo programm von:
7 rem
8 rem *** zuheir urwani ***
9 rem
10 :
20 !clrscr:!color 0
30 !cursor 12,1:print"tuerme von hanoi"
40 !cursor 12,2:print"----------------"
50 !eingabe:for i=0 to 2
60 !cursor i*13,22:print "[196][196][196][196][196][196][196][196][196][196][196][196]"
70 !cursor i*13+3,23:print "turm ";i+1;
80 next i:print "[159]";
100 tu (1,0)=an
110 tu (2,0)=0
120 tu (3,0)=0
125 for i=1 to an
130 tu (1,i)=(an+1-i)*2
140 !scheibe 0,22-i,(an+1-i)*2:next i
145 zug=0:!cursor 0,4:print "zug:"zug
147 rek=1:!cursor 20,4
149 print "rekursionstiefe:"rek
150 !hanoi an,1,2,3,rek
160 !cursor 16,6:print "fertig !"
170 !waitkey:goto 20
180 :
190 :
10000 rem prozeduren zum programm
10010 :
10020 \proc clrscr
10030 print "[147][154]"
10040 \end
10050 :
10060 :
10070 \proc color farbe
10080 poke 53280,farbe:poke 53281,farbe
10090 \end
10100 :
10110 :
10120 \proc scheibe x,y,n
10130 \var j
10140 !cursor x,y
10145 if n=12 then 10160
10150 for j=1 to 6-n/2:print " ";:next
10160 for j=1 to n:print "[163][146]";:next
10170 \end
10180 :
10190 :
10200 \proc hanoi n,a,b,c,r
10205 \var d,e,f
10207 !cursor 36,4:print r
10210 if n<1 then:\end
10215 d=a:e=b:f=c
10220 !hanoi n-1,d,f,e,r+1
10240 !versetze a,b
10250 !hanoi n-1,f,e,d,r+1
10255 !cursor 36,4:print r
10260 \end
10270 :
10320 :
10330 \proc waitkey:\var a$
10340 get a$:if a$="" then 10340
10350 \end
10360 :
10370 :
10380 \proc versetze vo,na
10390 \var v,n,b
10395 zug=zug+1:!cursor 4,4:print zug
10400 v=tu (vo,0)
10410 n=tu (na,0)+1
10420 b=tu (vo,v)
10430 tu (na,n)=b
10440 !loesche (vo-1)*13,22-v
10450 !scheibe (na-1)*13,22-n,b
10460 tu (vo,0)=tu (vo,0)-1
10470 tu (na,0)=tu (na,0)+1
10480 \end
10490 :
10500 :
10510 \proc loesche x,y
10520 !cursor x,y:print " "
10530 \end
10540 :
10550 :
10560 \proc cursor x,y
10570 poke 781,y:poke 782,x
10580 poke 783,peek(783)and 254
10590 sys 65520
10600 \end
10610 :
10620 :
10630 \proc eingabe:\var a$
10635 a$=" "
10700 !cursor 0,4
10710 print"anzahl der scheiben (1-6)?"
10720 !cursor 9,6:input an
10730 if an>0 and an<7 then 10750
10740 !cursor 9,6:print a$:goto 10720
10750 !cursor 0,4:print a$;a$;a$;a$
10760 \end