home *** CD-ROM | disk | FTP | other *** search
- 0 clr
- 50 rem copyright 1991 - compute publications intl ltd - all rights reserved
- 100 gosub1750:gosub1210
- 110 gosub1530:gosub300
- 120 print pl$(op,pl);"'s move":print
- 130 on (op*2)+pl gosub420,590,590,420,420,420,590,590,590,690
- 140 gm$(mv)=bd$+" "+chr$(r+64)+chr$(n+48)
- 150 mv=mv+1:pl=abs(pl-3)
- 160 gosub860:gosub300
- 170 if eg=0 then120
- 180 nm=mv-1
- 190 rem
- 200 rem announce winner
- 210 rem
- 220 print "and the winner is..."
- 230 print:print pl$(op,abs(pl-3))
- 240 gosub940
- 250 get k$:if op=4 and k$<>"_" then110
- 260 op=0
- 270 print " = press return to continue =";
- 280 get k$:if k$<>chr$(13) then280
- 290 goto110
- 300 rem
- 310 rem display board
- 320 rem
- 330 print chr$(147)
- 340 print:print
- 350 for i=1 to 4
- 360 n=val(mid$(bd$,i,1))
- 370 print chr$(i+64);") ";left$("[221][221][221][221][221][221][221]",n)
- 380 print
- 390 next i
- 400 print
- 410 return
- 420 rem
- 430 rem get human's move
- 440 rem
- 450 print "row: ";
- 460 get k$:if k$<"a" or k$>"d" then460
- 470 r=asc(k$)-64
- 480 x=val(mid$(bd$,r,1))
- 490 if val(bd$)=int(10^(4-r)*x) then x=x-1
- 500 if x=0 then460
- 510 print k$:r=asc(k$)-64
- 520 print "number to remove: ";
- 530 get k$:if k$<"1" or k$>chr$(x+48) then530
- 540 print k$:n=val(k$)
- 550 print " = press return to accept =";
- 560 get k$:if k$="" then560
- 570 if k$<>chr$(13) then gosub300:print pl$(op,pl);"'s move":print:goto420
- 580 return
- 590 rem
- 600 rem get computer's move
- 610 rem
- 620 bd=val(bd$):mv$=wm$(bd)
- 630 if mv$="" then690
- 640 r=asc(mid$(mv$,1,1))-64:n=val(mid$(mv$,2,1))
- 650 print "row:";chr$(64+r)
- 660 print "number to remove:";n
- 670 if op<>4 then for i=1 to 1000:next i
- 680 return
- 690 rem
- 700 rem get random move
- 710 rem
- 720 a$=""
- 730 for i=1 to 4
- 740 r$=mid$(bd$,i,1)
- 750 if r$<>"0" then a$=a$+chr$(i+48)
- 760 next i
- 770 if len(a$)=1 then r=val(a$):goto790
- 780 r=val(mid$(a$,int(rnd(1)*len(a$))+1,1))
- 790 x=val(mid$(bd$,r,1))
- 800 if val(bd$)=int(10^(4-r)*x) then x=x-1
- 810 n=int(rnd(1)*x)+1
- 820 print "row:";chr$(64+r)
- 830 print "number to remove:";n
- 840 if op<>4 then for i=1 to 1000:next i
- 850 return
- 860 rem
- 870 rem execute move and check for win
- 880 rem
- 890 cn=val(mid$(bd$,r,1))
- 900 cn=cn-n
- 910 bd$=mid$(bd$,1,r-1)+chr$(cn+48)+mid$(bd$,r+1,4)
- 920 if bd$="1000" or bd$="0100" or bd$="0010" or bd$="0001" then eg=1
- 930 return
- 940 rem
- 950 rem learn from game
- 960 rem
- 970 rem reward winning moves
- 980 mv=mv-1:if mv=0 then return
- 990 bd=val(left$(gm$(mv),4))
- 1000 mv$=right$(gm$(mv),2)
- 1010 f=0:a$=wm$(bd):if a$="" then a$=mv$:goto1080
- 1020 for i=1 to len(a$) step 2
- 1030 if mid$(a$,i,2)=mv$ then f=i
- 1040 next i
- 1050 if f=0 then a$=mv$+a$:goto1080
- 1060 if f=1 then1080
- 1070 a$=left$(a$,f-3)+mv$+mid$(a$,f-2,2)+mid$(a$,f+2)
- 1080 wm$(bd)=a$
- 1090 rem punish losing moves
- 1100 mv=mv-1:if mv=0 then return
- 1110 bd=val(left$(gm$(mv),4))
- 1120 mv$=right$(gm$(mv),2)
- 1130 f=0:a$=wm$(bd):if a$="" then970
- 1140 for i=1 to len(a$) step 2
- 1150 if mid$(a$,i,2)=mv$ then f=i
- 1160 next i
- 1170 if f=0 then970
- 1180 if f+1=len(a$) then wm$(bd)=left$(wm$(bd),f-1):goto970
- 1190 wm$(bd)=left$(a$,f-1)+mid$(a$,f+2,2)+mv$+mid$(a$,f+4)
- 1200 goto970
- 1210 rem
- 1220 rem load experince
- 1230 rem
- 1240 print chr$(147)
- 1250 print "load previous game experience? ";
- 1260 get k$:if k$<>"y" and k$<>"n" then1260
- 1270 if k$="n" then print "no":for i=1 to 500:next i:goto1350
- 1280 print "yes":print:input "filename";a$:if a$="" then1350
- 1290 open 15,8,15
- 1300 open 1,8,2,a$+".ai,s,r"
- 1310 input#15,e,e$
- 1320 if e thenprint"* ";e$;" *":for i=1to2500:next i:close1:close15:goto1210
- 1330 input#1,bd:input#1,mv$:wm$(bd)=mv$:if st=0 then1330
- 1340 close 1:close 15
- 1350 return
- 1360 rem
- 1370 rem save experience
- 1380 rem
- 1390 print chr$(147)
- 1400 print "save game experience? ";
- 1410 get k$:if k$<>"y" and k$<>"n" then1410
- 1420 if k$="n" then print "no":goto1520
- 1430 print "yes":print:input "filename";a$:if a$="" then1520
- 1440 open 15,8,15,"s0:"+a$+".ai"
- 1450 open 1,8,2,a$+".ai,s,w"
- 1460 input#15,e,e$
- 1470 if e thenprint"* ";e$;" *":for i=1to2500:next i:close1:close15:goto1360
- 1480 for i=1 to 1357
- 1490 if wm$(i)<>"" then print#1,i:print#1,wm$(i)
- 1500 next i
- 1510 close 1:close 15
- 1520 return
- 1530 rem
- 1540 rem prepare for new game
- 1550 rem
- 1560 bd$="1357"
- 1570 for i=1 to nm:gm$(i)="":next i
- 1580 mv=1
- 1590 eg=0
- 1600 if op=4 then wf=abs(wf-3):pl=wf:goto1740
- 1610 pl=1
- 1620 wf=1
- 1630 print chr$(147);" 1-3-5-7 "
- 1640 print
- 1650 print:print " 1) human moves first"
- 1660 print:print " 2) computer moves first"
- 1670 print:print " 3) human vs human"
- 1680 print:print " 4) computer vs computer"
- 1690 print:print " 5) auto-learn mode"
- 1700 print:print " 6) quit"
- 1710 get k$:if k$<"1" or k$>"6" then1710
- 1720 if k$="6" then gosub1360:print:print "thanks for playing":end
- 1730 op=val(k$)-1
- 1740 return
- 1750 rem
- 1760 rem initialize program
- 1770 rem
- 1780 x=rnd(-ti)
- 1790 dim wm$(1357)
- 1800 dim gm$(15)
- 1810 dim pl$(4,2)
- 1820 restore
- 1830 for op=0 to 4:for pl=1 to 2:read pl$(op,pl):next pl:next op
- 1840 return
- 1850 data the human,the computer
- 1860 data the computer,the human
- 1870 data human1,human2
- 1880 data computer1,computer2
- 1890 data the computer,mr. random
-