home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Disc 45
/
Commodore_Disc_45_19xx_-_de.d64
/
kalah
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
7KB
|
295 lines
10 rem kalah ===================c64
20 rem (p) commodore disc
30 rem ============================
40 rem (c) r. rudert
50 rem
60 rem
70 rem basic 2.0
80 rem c64
90 rem ============================
100 rem version 2.1.87
110 dim fr(13,2),f(5,2,7)
120 sg=0:cl$=chr$(147)
130 rf=15:bf=13:poke 53280,rf:poke 53281,bf:c=0:poke 646,c
140 gosub 2090:rem menue
150 gosub 1540:rem initialisierung
160 rem ***************************
170 if s1=1 and r=-1 or s2=1 and r=1 then gosub 1400:rem zugeingabe
180 if s1=-1 and r=-1 or s2=-1 and r=1 then gosub 870:rem computerzug
190 if sg=1 then gosub 2570:goto 120
200 r=-r:goto 170
210 end
220 rem**************************
230 rem proc:kopieren spielfeld
240 rem auf hoehere ebene +
250 rem zuguntersuchung
260 t1=t-1:for i=1 to 7:f(t,0,i)=f(t1,0,i):f(t,2,i)=f(t1,2,i):next
270 rem**************************
280 z2=0:rp=1+r:rm=1-r
290 fd=f(t,rp,z):f(t,rp,z)=0
300 ie=7:if fd<7-z then ie=z+fd:fd=0:goto 320
310 fd=fd-7+z
320 for z=z+1 to ie
330 f(t,rp,z)=f(t,rp,z)+1:next
340 if f(t,rp,7)>=z6 then d(t)=999:return
350 if fd<1 and z<>8 then 460
360 z2=1:ie=6:if fd<6 then ie=fd:fd=0:goto 380
370 fd=fd-6
380 for z=1 to ie
390 f(t,rm,z)=f(t,rm,z)+1:next
400 if fd>0 then z=0:goto 300
410 if f(t,rm,z-1)<>2 and f(t,rm,z-1)<>3 then 470
420 f(t,rp,7)=f(t,rp,7)+f(t,rm,z-1):f(t,rm,z-1)=0
430 if f(t,rp,7)>=z6 then d(t)=999:return
440 z=z-1:if z>0 goto 410
450 goto 470
460 if z2=1 and f(t,rp,z-1)>0 then z=z-1:z2=0:goto 290
470 su=0:for i=1 to 6:su=su+f(t,rp,i):if su<>0 then 520
480 next
490 su=0:for i=1 to 6:su=su+f(t,rm,i):f(t,rm,i)=0
500 next
510 f(t,rp,7)=f(t,rp,7)+su:if f(t,rp,7)>=z6 then d(t)=999:return
520 d(t)=f(t,rp,7)-f(t,rm,7):return
530 rem***************************
540 rem proc:zugdurchfuehrung
550 z2=0:rp=1+r:rm=1-r
560 fd=f(0,rp,z):f(0,rp,z)=0:o=r:gosub 2360
570 ie=7:if fd<7-z then ie=z+fd:fd=0:goto 590
580 fd=fd-7+z
590 for z=z+1 to ie
600 f(0,rp,z)=f(0,rp,z)+1:o=r:gosub 2360:next
610 if f(0,rp,7)>=z6 then sg=1
620 if fd<1 and z<>8 then 750
630 if fd<1 then 760
640 z2=1:ie=6:if fd<6 then ie=fd:fd=0:goto 660
650 fd=fd-6
660 for z=1 to ie
670 f(0,rm,z)=f(0,rm,z)+1:o=-r:gosub 2360:next
680 if fd>0 then z=0:goto 570
690 if f(0,rm,z-1)<>2 and f(0,rm,z-1)<>3 then 760
700 f(0,rp,7)=f(0,rp,7)+f(0,rm,z-1):i=z:z=7:o=r:gosub 2360:z=i
710 if f(0,rp,7)>=z6 then sg=1
720 z=z-1:f(0,rm,z)=0:o=-r:gosub 2360:z=z+1
730 z=z-1:if z>0 goto 690
740 return
750 if z2=1 and f(0,rp,z-1)>0 then z=z-1:z2=0:goto 560
760 su=0:for i=1 to 6:su=su+f(0,rp,i):if su<>0 goto 800
770 next
780 su=0:for z=1 to 6:su=su+f(0,rm,z):f(0,rm,z)=0:o=-r:gosub 2360:next
790 goto 830
800 su=0:for i=1 to 6:su=su+f(0,rm,i):if su<>0 goto 840
810 next
820 sg=1:return
830 f(0,rp,7)=f(0,rp,7)+su:z=7:o=r:gosub 2360:sg=1
840 return
850 rem**************************
860 rem proc:computerzug
870 if sd>0 goto 910
880 z=int(rnd(1)*6+1)
890 if f(t,1+r,z)=0 goto 880
900 zm=z:goto 1340
910 t=1:d(0)=-999
920 for i1=1 to 6
930 :if f(0,1+r,i1)=0 goto 1330
940 :z=i1:gosub 260
950 :if sd=1 goto 1310
960 :t=2:r=-r:d(1)=-999
970 for i2=1 to 6
980 :if f(1,1+r,i2)=0 goto 1290
990 :z=i2:gosub 260
1000 :if sd=2 goto 1270
1010 :t=3:r=-r:d(2)=-999
1020 for i3=1 to 6
1030 :if f(2,1+r,i3)=0 goto 1250
1040 :z=i3:gosub 260
1050 :if sd=3 goto 1230
1060 :t=4:r=-r:d(3)=-999
1070 for i4=1 to 6
1080 :if f(3,1+r,i4)=0 goto 1210
1090 :z=i4:gosub 260
1100 :if sd=4 goto 1190
1110 :t=5:r=-r:d(4)=-999
1120 for i5=1 to 6
1130 :if f(4,1+r,i5)=0 goto 1170
1140 :z=i5:gosub 260
1150 :if -d(5)>d(4) then d(4)=d(5)
1160 :if d(5)>-d(3) then i5=6
1170 next
1180 :t=4:r=-r:d(4)=-d(4)
1190 :if d(4)>d(3) then d(3)=d(4)
1200 :if d(4)>-d(2) then i4=6
1210 next
1220 :t=3:r=-r:d(3)=-d(3)
1230 :if d(3)>d(2) then d(2)=d(3)
1240 :if d(3)>-d(1) then i3=6
1250 next
1260 :t=2:r=-r:d(2)=-d(2)
1270 :if d(2)>d(1) then d(1)=d(2)
1280 :if d(2)>-d(0) then i2=6
1290 next
1300 :t=1:r=-r:d(1)=-d(1)
1310 :if d(1)>d(0) then d(0)=d(1):zm=i1
1320 :if d(1)=d(0) and int(i1*rnd(1))>3 then d(0)=d(1):zm=i1
1330 next:t=0
1340 x=1968+r*15:poke x,zm+3+r*3:for i=x-9tox-2:pokei,peek(i)-128:next
1350 z=zm:gosub 550
1360 x=x-r*30:poke x,32:for i=x-9tox-2:pokei,peek(i)+128:next:get k$
1370 return
1380 rem**************************
1390 rem proc:zugeingabe
1400 ih=1:gosub 2700
1410 get iz$:if len(iz$)=0 goto 1410
1420 z=asc(iz$)-64
1430 if z<4+3*r goto 1400
1440 if z>68 and z<73 then gosub 2790:goto 1400
1450 if z>9+3*r goto 1400
1460 if r>0 then z=z-6
1470 if f(0,1+r,z)=0 goto 1400
1480 x=1968+r*15:poke x,asc(iz$)-64:for i=x-9tox-2:pokei,peek(i)-128:next
1490 gosub 550
1500 x=x-r*30:poke x,32:for i=x-9tox-2:pokei,peek(i)+128:next
1510 return
1520 rem**************************
1530 rem proc:initialisierung
1540 a=53281:b=peek(646):c=peek(a):pokea,b:printcl$;:pokea,c
1550 for i=0 to 2 step 2:for j=1 to 6
1560 f(0,i,j)=z
1570 next:next
1580 z6=z*6:r=-1
1590 rem maschinenprogramm fuer farbwechsel
1600 for i=1 to 25:read x:poke 49151+i,x:next
1610 data 169,0,133,250,168,169,216,133
1620 data 251,162,4,173,134,2,145,250
1630 data 200,208,251,230,251,202,208
1640 data 246,96
1650 f(0,0,7)=0:f(0,2,7)=0
1660 for i=0 to 35 step 5
1670 poke 1064+i,236:poke 1068+i,116
1680 poke 1824+i,119:poke 1828+i,96
1690 for j=0 to 680 step 40
1700 poke 1104+i+j,97:poke 1108+i+j,116
1710 next
1720 for j=0 to 2
1730 poke 1065+j+i,226
1740 if i=0 or i=35 goto 1800
1750 poke 1425+j+i,119
1760 poke 1465+j+i,226
1770 poke 1464+i,236:poke 1468+i,116
1780 poke 1424+i,119:poke 1428+i,96
1790 poke 1866+i,i/5:poke 1026+i,13-i/5
1800 poke 1825+j+i,119
1810 next:next
1820 poke 1963,148
1830 poke 211,20:poke 214,23:sys 58640
1840 print right$(str$(sd),1)
1850 si=54272:fl=si:fh=si+1:w=si+4:a=si+5:h=si+6
1860 poke si+24,15:poke si+3,7
1870 rem frequenzen einlesen
1880 for i=1 to 13:read fr(i,1),fr(i,2):next
1890 data 8,180,9,196,10,247,11,158
1900 data 13,10,14,162,16,109,17,103
1910 data 19,137,21,237,23,59,26,20
1920 data 52,39
1930 for i=1 to 6
1940 :z=i
1950 :o=-1:gosub 2360
1960 :o=+1:gosub 2360
1970 next
1980 poke 211,0:poke 214,23:sys 58640
1990 printchr$(18);"spieler1";chr$(146);":"
2000 poke 211,30:poke 214,23:sys 58640
2010 print"spieler2:";
2020 if s1=-1 then poke 1988,131:goto 2040
2030 poke 1988,141
2040 if s2=-1 then poke 2018,131:goto 2060
2050 poke 2018,141
2060 return
2070 rem**************************
2080 rem proc:menue
2090 print cl$;spc(13);"k a h l a h"
2100 print:print:print
2110 print "zahl der steine pro feld (1..9)";
2120 get z$:if len(z$)=0 goto 2120
2130 z=asc(z$)-48
2140 if z<1 or z>9 goto 2120
2150 print z
2160 print:print "erster spieler (m.ensch/c.omputer) ";
2170 get s1$:if len(s1$)=0 goto 2170
2180 if s1$="m" then s1=1
2190 if s1$="c" then s1=-1
2200 if s1$<>"m" and s1$<>"c" goto 2170
2210 print s1$
2220 print:print "zweiter spieler (m.ensch/c.omputer) ";
2230 get s2$:if len(s2$)=0 goto 2230
2240 if s2$="m" then s2=1
2250 if s2$="c" then s2=-1
2260 if s2$<>"m" and s2$<>"c" goto 2230
2270 print s2$
2280 print:print"spielstaerke (0..5) ";
2290 get sd$:if len(sd$)=0 goto 2290
2300 if sd$<"0" or sd$>"5" goto 2290
2310 print sd$
2320 sd=asc(sd$)-48
2330 return
2340 rem**************************
2350 rem proc:neue stellung
2360 ih=z+3*(1+o)
2370 fz=int(f(0,1+o,z)/10)
2380 fe=f(0,1+o,z)-fz*10
2390 if o<0 then ia=z*5+1:ib=480:iu=800
2400 if o>0 then ia=36-z*5:ib=80:iu=400
2410 if z=7 then ib=80:iu=800:ih=13
2420 for j=1 to 24
2430 if fz=0 goto 2470
2440 poke 1024+ib+ia,81:fz=fz-1:ib=ib+40:ifib=iu thenib=280-o*200:ia=ia+1
2450 next
2460 for j=1 to 24
2470 if fe=0 goto 2500
2480 poke 1024+ib+ia,87:fe=fe-1:ib=ib+40:ifib=iu thenib=280-o*200:ia=ia+1
2490 next
2500 if ia=z*5+4 and o=-1 then gosub 2700:return
2510 if ia=39-z*5 and o=1 then gosub 2700:return
2520 sc=1024+ib+ia:if peek(sc)=32 then gosub 2700:return
2530 poke sc,32:ib=ib+40:if ib=iu then ib=280-o*200:ia=ia+1
2540 goto 2500
2550 rem**************************
2560 rem proc:gewinnnanzeige
2570 poke 211,15:poke 214,24:sys 58640
2580 print "spielende";chr$(145);
2590 ih=6:poke 53280,3:poke 53280,4
2600 get k$:if len(k$)=0 goto 2590
2610 x$="2":if f(0,0,7)>f(0,2,7) then x$="1"
2620 print cl$;"gewonnen hat spieler ";x$
2630 print:print "noch ein spiel? (j/n)";
2640 get k$:if k$="" then 2640
2650 if k$="n" then end
2660 if k$="j" then print k$:restore:return
2670 goto 2640
2680 rem*************************
2690 rem proc:signal
2700 poke a,16+5
2710 poke h,8*16
2720 poke fh,fr(ih,1):poke fl,fr(ih,2)
2730 poke w,33
2740 for j=1 to 100:next
2750 poke w,0:poke a,0:poke h,0
2760 return
2770 rem**************************
2780 rem proc:screenfarbe aendern
2790 on z-68 goto 2800,2820,2840,2850
2800 rf=rf+1:if rf>15 then rf=0
2810 poke 53280,rf:return
2820 bf=bf+1:if bf>15 then bf=0
2830 poke 53281,bf:return
2840 c=c+1:poke 646,c:sys 49152:return
2850 sd=sd+1:if sd=6 then sd=0
2860 poke 1964,sd+48
2870 return
2880 rem kalah ==================64
2890 rem 38911 bytes memory ==
2900 rem 07601 bytes program ==
2910 rem 01340 bytes variables ==
2920 rem 00000 bytes strings ==
2930 rem 29970 bytes free ==
2940 rem ==========================