risorse | zx spectrum | minidama

Minidama (1988)

Come si deduce dal nome, si tratta di una versione semplificata del gioco della dama.

Il programma è in grado di affrontare una partita a dama con le seguenti varianti:

La stragegia di gioco è basata sulla selezione, tra le mosse possibili, di quella più remunerativa, privilegiando ad esempio le promozioni sulle catture, le catture sulle protezioni, le protezioni sugli avanzamenti… In questo modo si realizza un pruning implicito sull'albero delle mosse.

Istantanea

Nastro

Scarica il nastro virtuale minidama.tzx (14KB).

Listato

  10 REM ********
  20 REM * DAMA *
  30 REM ********
  40 REM
  50 REM
  60 REM A..CATTURA E PROMOZIONE
  70 REM B..CATTURA E ATTACCO
  80 REM C..CATTURA SICURA
  90 REM D..ALTRE CATTURE
 100 REM E..MOSSE DI PROTEZIONE
 110 REM F..MOSSE DI PROMOZIONE
 120 REM G..MOSSE SICURE
 130 REM H..MOSSE VALIDE
 140 REM
 150 REM
 160 BORDER 0: PAPER 0: INK 7: BRIGHT 1: CLS : POKE 23624,71
 170 LET A$="U": LET V$=" ": LET N$="C": FOR F=0 TO 15: READ A: POKE USR "{A}"+F,A: NEXT F
 180 DATA 255,231,231,129,129,231,231,255,255,231,195,129,129,195,231,255
 190 DIM A(12,3): DIM B(12,3): DIM C(12,3): DIM D(12,3): DIM E(12,3): DIM F(12,3): DIM G(12,3): DIM H(12,3): DIM S$(10,10)
 200 LET S$(10)="          "
 210 LET S$(09)=" C*C*C*C* "
 220 LET S$(08)=" *C*C*C*C "
 230 LET S$(07)=" C*C*C*C* "
 240 LET S$(06)=" * * * *  "
 250 LET S$(05)="  * * * * "
 260 LET S$(04)=" *U*U*U*U "
 270 LET S$(03)=" U*U*U*U* "
 280 LET S$(02)=" *U*U*U*U "
 290 LET S$(01)="          "
 300 LET MIEIPUNTI=0: LET TUOIPUNTI=0: LET MIEPEDINE=12: LET TUEPEDINE=12
 310 GO TO 1690
 320 REM
 330 REM *****************
 340 REM * CERCA CATTURA *
 350 REM *****************
 360 REM
 370 LET CSX=0: LET CDX=0: LET CSICSX=0: LET CSICDX=0
 380 IF RIGA<4 THEN RETURN
 390 IF COL<8 THEN IF S$(RIGA-1,COL+1)=A$ AND S$(RIGA-2,COL+2)=V$ THEN LET CDX=1
 400 IF COL>3 THEN IF S$(RIGA-1,COL-1)=A$ AND S$(RIGA-2,COL-2)=V$ THEN LET CSX=1
 410 IF NOT (CDX OR CSX) THEN RETURN
 420 LET CATTURA=1
 430 IF RIGA=4 THEN LET CA=CA+1: LET A(CA,1)=RIGA: LET A(CA,2)=COL: LET A(CA,3)=(CSX=1): RETURN
 440 IF CDX THEN LET CSICDX=(S$(RIGA-3,COL+1)<>A$ OR S$(RIGA-1,COL+3)<>V$) AND S$(RIGA-3,COL+3)<>A$
 450 IF CSX THEN LET CSICSX=(S$(RIGA-3,COL-1)<>A$ OR S$(RIGA-1,COL-3)<>V$) AND S$(RIGA-3,COL-3)<>A$
 460 IF (CSICSX OR CSICDX) AND S$(RIGA-4,COL)=V$ AND (S$(RIGA-3,COL+1)=A$ OR S$(RIGA-3,COL+1)=A$) THEN LET CB=CB+1: LET B(CB,1)=RIGA: LET B(CB,2)=COL: LET B(CB,3)=(CSICSX=1): RETURN
 470 IF (CSICSX OR CSICDX) THEN LET CC=CC+1: LET C(CC,1)=RIGA: LET C(CC,2)=COL: LET C(CC,3)=(CSICSX=1): RETURN
 480 LET CD=CD+1: LET D(CD,1)=RIGA: LET D(CD,2)=COL: LET D(CD,3)=(CSX=1): RETURN
 490 REM
 500 REM **************
 510 REM * PROTEZIONI *
 520 REM **************
 530 REM
 540 IF RIGA<5 THEN RETURN
 550 LET PROTEZIONE=1
 560 IF COL>5 THEN IF S$(RIGA-1,COL-1)=V$ AND S$(RIGA-2,COL-2)=N$ AND S$(RIGA-3,COL-3)=A$ AND (S$(RIGA-2,COL)<>A$ OR S$(RIGA,COL-2)<>V$) THEN LET CE=CE+1: LET E(CE,1)=RIGA: LET E(CE,2)=COL: LET E(CE,3)=1: RETURN
 570 IF COL>2 THEN IF COL<8  THEN IF S$(RIGA-1,COL-1)=V$ AND S$(RIGA-2,COL)=N$ AND S$(RIGA-3,COL+1)=A$ AND S$(RIGA-2,COL-2)<>A$ THEN LET CE=CE+1: LET E(CE,1)=RIGA: LET E(CE,2)=COL: LET E(CE,3)=1: RETURN
 580 IF COL<5 THEN IF S$(RIGA-1,COL+1)=V$ AND S$(RIGA-2,COL+2)=N$ AND S$(RIGA-3,COL+3)=A$ AND (S$(RIGA-2,COL)<>A$ OR S$(RIGA,COL+2)<>V$) THEN LET CE=CE+1: LET E(CE,1)=RIGA: LET E(CE,2)=COL: LET E(CE,3)=0: RETURN
 590 IF COL<8 THEN IF COL>2 THEN IF S$(RIGA-1,COL+1)=V$ AND S$(RIGA-2,COL)=N$ AND S$(RIGA-3,COL-1)=A$ AND S$(RIGA-2,COL+2)<>A$ THEN LET CE=CE+1: LET E(CE,1)=RIGA: LET E(CE,2)=COL: LET E(CE,3)=0: RETURN
 600 LET PROTEZIONE=0: RETURN
 610 REM
 620 REM **************
 630 REM * PROMOZIONI *
 640 REM **************
 650 REM
 660 IF RIGA<>3 THEN RETURN
 670 LET PROMOZIONE=1
 680 IF COL>2 AND S$(RIGA-1,COL-1)=V$ THEN LET CF=CF+1: LET F(CF,1)=RIGA: LET F(CF,2)=COL: LET F(CF,3)=1: RETURN
 690 IF COL<9 AND S$(RIGA-1,COL+1)=V$ THEN LET CF=CF+1: LET F(CF,1)=RIGA: LET F(CF,2)=COL: LET F(CF,3)=0: RETURN
 700 LET PROMOZIONE=0: RETURN
 710 REM
 720 REM ****************
 730 REM * MOSSE SICURE *
 740 REM ****************
 750 REM
 760 LET MOSSASICURA=1
 770 IF COL>2 THEN IF S$(RIGA-1,COL-1)=V$ AND S$(RIGA-2,COL-2)<>A$ AND (S$(RIGA-2,COL)<>A$ OR S$(RIGA,COL-2)<>V$) THEN LET CG=CG+1: LET G(CG,1)=RIGA: LET G(CG,2)=COL: LET G(CG,3)=1: RETURN
 780 IF COL<9 THEN IF S$(RIGA-1,COL+1)=V$ AND S$(RIGA-2,COL+2)<>A$ AND (S$(RIGA-2,COL)<>A$ OR S$(RIGA,COL+2)<>V$) THEN LET CG=CG+1: LET G(CG,1)=RIGA: LET G(CG,2)=COL: LET G(CG,3)=0: RETURN
 790 LET MOSSASICURA=0: RETURN
 800 REM
 810 REM ****************
 820 REM * MOSSE VALIDE *
 830 REM ****************
 840 REM
 850 LET MOSSA=1
 860 IF COL>2 AND S$(RIGA-1,COL-1)=V$ THEN LET CH=CH+1: LET H(CH,1)=RIGA: LET H(CH,2)=COL: LET H(CH,3)=1: RETURN
 870 IF COL<9 AND S$(RIGA-1,COL+1)=V$ THEN LET CH=CH+1: LET H(CH,1)=RIGA: LET H(CH,2)=COL: LET H(CH,3)=0: RETURN
 880 LET MOSSA=0: RETURN
 890 REM
 900 REM ***************
 910 REM * CERCA MOSSE *
 920 REM ***************
 930 REM
 940 FOR M=1 TO 12
 950 FOR N=1 TO 3
 960 LET A(M,N)=0
 970 LET B(M,N)=0
 980 LET C(M,N)=0
 990 LET D(M,N)=0
1000 LET E(M,N)=0
1010 LET F(M,N)=0
1020 LET G(M,N)=0
1030 LET H(M,N)=0
1040 NEXT N
1050 NEXT M
1060 LET CATTURA=0: LET PROMOZIONE=0: LET PROTEZIONE=0: LET MOSSASICURA=0: LET CA=0: LET CB=0: LET CC=0: LET CD=0: LET CE=0: LET CF=0: LET CG=0: LET CH=0
1070 REM
1080 REM
1090 REM
1100 LET PED=0
1110 LET RIGA=2
1120 LET COL=2
1130 IF S$(RIGA,COL)=N$ THEN LET PED=PED+1: GO TO 1170
1140 LET COL=COL+1: IF COL=10 THEN LET COL=2: LET RIGA=RIGA+1
1150 IF PED=MIEPEDINE THEN LET TROVATOMOSSA=(CA>0) OR (CB>0) OR (CC>0) OR (CD>0) OR (CE>0) OR (CF>0) OR (CG>0) OR (CH>0): RETURN
1160 GO TO 1130
1170 GO SUB 340
1180 IF CATTURA THEN GO TO 1140
1190 GO SUB 510
1200 IF PROTEZIONE THEN GO TO 1140
1210 GO SUB 630
1220 IF PROMOZIONE THEN GO TO 1140
1230 GO SUB 730
1240 IF MOSSASICURA THEN GO TO 1140
1250 GO SUB 820
1260 GO TO 1140
1270 REM
1280 REM *********************
1290 REM * STAMPA SCACCHIERA *
1300 REM *********************
1310 REM
1320 PRINT AT 0,0;"MINIDAMA"'"{(C)}1988 by ZULIANI"
1330 LET Z$="ABCDEFGH"
1340 FOR R=8 TO 1 STEP -1
1350 FOR C=1 TO 8
1360 PRINT AT 4,10;"12345678"
1370 PRINT AT 14-R,8;Z$(9-R)
1380 PRINT INVERSE 1;AT 14-R,9+C;(" " AND S$(R+1,C+1)="*")+("{A}" AND S$(R+1,C+1)=A$)+("{B}" AND S$(R+1,C+1)=N$)+("{+8}" AND S$(R+1,C+1)=V$)
1390 NEXT C
1400 NEXT R
1410 PLOT 78,62
1420 DRAW 67,0: DRAW 0,67: DRAW -67,0: DRAW 0,-67
1430 PLOT 76,60: DRAW 71,0: DRAW 0,71: DRAW -71,0: DRAW 0,-71
1440 PRINT AT 16,0; INVERSE 1;"{B}"; INVERSE 0;"  SINCLAIR      0         12"' INVERSE 1;"{A}"; INVERSE 0;"  ";G$;"    0         12"
1450 PRINT AT 15,15;"PUNTI     PEDINE"
1460 PRINT AT 5,22;"MOSSA";AT 6,22;"SCELTA";AT 8,22;"DA ->";AT 9,23;"A ->"
1470 RETURN
1480 REM
1490 REM ****************
1500 REM * SCEGLI MOSSA *
1510 REM ****************
1520 REM
1530 GO SUB 910
1540 IF NOT TROVATOMOSSA THEN RETURN
1550 IF NOT CATTURA THEN GO TO 1610
1560 LET TUEPEDINE=TUEPEDINE-1: LET MIEIPUNTI=MIEIPUNTI+1
1570 IF CA>0 THEN LET MIEPEDINE=MIEPEDINE-1: LET MIEIPUNTI=MIEIPUNTI+1: LET PUN=INT (RND*CA)+1: LET R=A(PUN,1): LET C=A(PUNT,2): LET S=A(PUN,3): LET S$(R,C)=V$: LET S$(R-1,C+1-2*S)=V$: PRINT INVERSE 1;AT 15-R,8+C;"{+8}";AT 16-R,9+C-2*S;"{+8}": RETURN
1580 IF CB>0 THEN LET PUN=INT (RND*CB)+1: LET R=B(PUN,1): LET C=B(PUN,2): LET S=B(PUN,3): LET S$(R,C)=V$: LET S$(R-1,C+1-2*S)=V$: LET S$(R-2,C+2-4*S)=N$: PRINT INVERSE 1;AT 15-R,8+C;"{+8}";AT 16-R,9+C-2*S;"{+8}";AT 17-R,10+C-4*S;"{B}": RETURN
1590 IF CC>0 THEN LET PUN=INT (RND*CC)+1: LET R=C(PUN,1): LET C=C(PUN,2): LET S=C(PUN,3): LET S$(R,C)=V$: LET S$(R-1,C+1-2*S)=V$: LET S$(R-2,C+2-4*S)=N$: PRINT INVERSE 1;AT 15-R,8+C;"{+8}";AT 16-R,9+C-2*S;"{+8}";AT 17-R,10+C-4*S;"{B}": RETURN
1600 IF CD>0 THEN LET PUN=INT (RND*CD)+1: LET R=D(PUN,1): LET C=D(PUN,2): LET S=D(PUN,3): LET S$(R,C)=V$: LET S$(R-1,C+1-2*S)=V$: LET S$(R-2,C+2-4*S)=N$: PRINT INVERSE 1;AT 15-R,8+C;"{+8}";AT 16-R,9+C-2*S;"{+8}";AT 17-R,10+C-4*S;"{B}": RETURN
1610 IF CE>0 THEN LET PUN=INT (RND*CE)+1: LET R=E(PUN,1): LET C=E(PUN,2): LET S=E(PUN,3): LET S$(R,C)=V$: LET S$(R-1,C+1-2*S)=N$: PRINT INVERSE 1;AT 15-R,8+C;"{+8}";AT 16-R,9+C-2*S;"{B}": RETURN
1620 IF CF>0 THEN LET MIEIPUNTI=MIEIPUNTI+1: LET MIEPEDINE=MIEPEDINE-1: LET PUN=INT (RND*CF)+1: LET R=F(PUN,1): LET C=F(PUN,2): LET S$(R,C)=V$: PRINT INVERSE 1;AT 15-R,8+C;"{+8}": RETURN
1630 IF CG>0 THEN LET PUN=INT (RND*CG)+1: LET R=G(PUN,1): LET C=G(PUN,2): LET S=G(PUN,3): LET S$(R,C)=V$: LET S$(R-1,C+1-2*S)=N$: PRINT INVERSE 1;AT 15-R,8+C;"{+8}";AT 16-R,9+C-2*S;"{B}": RETURN
1640 LET PUN=INT (RND*CH)+1: LET R=H(PUN,1): LET C=H(PUN,2): LET S=H(PUN,3): LET S$(R,C)=V$: LET S$(R-1,C+1-2*S)=N$: PRINT INVERSE 1;AT 15-R,8+C;"{+8}";AT 16-R,9+C-2*S;"{B}": RETURN
1650 REM
1660 REM ********************
1670 REM * CICLO PRINCIPALE *
1680 REM ********************
1690 REM
1700 CLS : PRINT "MINIDAMA"'"{(C)}1988 by ZULIANI"
1710 PRINT '''"SALVE, IO SONO LO SPECTRUM, E"'"TI SFIDO A VINCERMI A MINIDAMA!"
1720 PRINT '"SCOPO DEL GIOCO E' DI GUADAGNARE"'"SETTE PUNTI PRIMA DELL'AVERSARIO"'"SI OTTIENE UN PUNTO PER OGNI"'"PEDINA AVVERSARIA CATTURATA E"'"PER OGNI PEDINA PROPRIA PROMOSSA"'"(CIO' IMPLICA L'ASSENZA DI DAME)"
1730 PRINT "NON SONO PERMESSI IL ~SOFFIARE~,"'"NE' LE PRESE MULTIPLE.."
1740 DIM G$(10): INPUT AT 1,0;"A PROPOSITO, TU"'" COME TI CHIAMI ? ";LINE G$
1750 PRINT ''"CIAO, ";G$
1760 PRINT #0;"** PREMI UN TASTO **": PAUSE 0
1770 CLS : GO SUB 1290
1780 DIM R$(2): INPUT "VUOI GIOCARE PER PRIMO (S/N):";LINE R$
1790 IF R$(1)="S" OR R$(1)="s" THEN GO SUB 2050: GO TO 1810
1800 IF R$(1)<>"N" AND R$(1)<>"n" THEN GO TO 1780
1810 GO SUB 1490
1820 IF NOT TROVATOMOSSA THEN PRINT AT 20,0;"NON HO TROVATO ALCUNA MOSSA CHE"'"IO POSSA ESEGUIRE.. MI ARRENDO!": PRINT #0;AT 1,10; FLASH 1;" HAI VINTO ": PAUSE 0: RUN
1830 PRINT AT 8,28;CHR$ (CODE "J"-R);C-1
1840 PRINT AT 9,28;CHR$ (CODE "J"-R+1+1*CATTURA);C-1+(1-2*S)*(1+CATTURA)
1850 PRINT AT 19,0;"MOSSA DI: ";
1860 IF CA>0 THEN PRINT "CATTURA E PROMOZIONE  ": GO TO 1940
1870 IF CB>0 THEN PRINT "CATTURA E ATTACCO  ": GO TO 1940
1880 IF CC>0 THEN PRINT "CATTURA SICURA        ": GO TO 1940
1890 IF CD>0 THEN PRINT "CATTURA               ": GO TO 1940
1900 IF CE>0 THEN PRINT "PROTEZIONE PEDINA     ": GO TO 1940
1910 IF CF>0 THEN PRINT "PROMOZIONE            ": GO TO 1940
1920 IF CG>0 THEN PRINT "AVANZAMENTO SICURO    ": GO TO 1940
1930 PRINT "AVANZAMENTO           "
1940 PRINT AT 16,17;MIEIPUNTI;AT 16,27;MIEPEDINE,
1950 PRINT AT 17,17;TUOIPUNTI;AT 17,27;TUEPEDINE,
1960 GO SUB 2050
1970 PRINT AT 16,17;MIEIPUNTI;AT 16,27;MIEPEDINE,
1980 PRINT AT 17,17;TUOIPUNTI;AT 17,27;TUEPEDINE,
1990 IF MIEIPUNTI=7 AND TUOIPUNTI=7 THEN PRINT #0;AT 1,12; FLASH 1;" PATTA ": PAUSE 0: RUN
2000 IF MIEIPUNTI=7 THEN PRINT #0;AT 1,5; FLASH 1;" HA HA! HO VINTO IO! ": PAUSE 0: RUN
2010 IF TUOIPUNTI=7 THEN PRINT #0;AT 1,8; INVERSE 1;"HAI VINTO TU...": PAUSE 0: RUN
2020 GO TO 1810
2030 REM
2040 REM ******************
2050 REM * MOSSA ALL'UOMO *
2060 REM ******************
2070 REM
2080 INPUT "MUOVI DA ";LINE F$;" A ";LINE D$
2090 IF LEN F$<>2 OR LEN D$<>2 THEN GO TO 2080
2100 IF F$(1)<"A" OR F$(1)>"H" THEN GO TO 2080
2110 IF F$(2)<"1" OR F$(2)>"8" THEN GO TO 2080
2120 IF D$(1)<"A" OR D$(1)>"H" THEN GO TO 2080
2130 IF D$(2)<"1" OR D$(2)>"8" THEN GO TO 2080
2140 LET RF=CODE "J"-CODE F$(1)
2150 LET COF=CODE F$(2)-47
2160 IF S$(RF,COF)<>A$ THEN PRINT #0;"MOSSA NON VALIDA": PAUSE 30: GO TO 2080
2170 LET RD=CODE "J"-CODE D$(1)
2180 LET COD=CODE D$(2)-47
2190 IF S$(RD,COD)<>V$ THEN PRINT #0;"MOSSA NON VALIDA": PAUSE 30: GO TO 2080
2200 IF RD-RF>2 THEN PRINT #0;"MOSSA NON VALIDA": PAUSE 30: GO TO 2080
2210 IF ABS (COF-COD)>2 THEN PRINT #0;"MOSSA NON VALIDA": PAUSE 30: GO TO 2080
2220 IF RD-RF<>ABS (COF-COD) THEN PRINT #0;"MOSSA NON VALIDA": PAUSE 30: GO TO 2080
2230 IF RD-RF=2 AND S$((RD+RF)/2,(COF+COD)/2)<>N$ THEN PRINT #0;"CATTURA NON VALIDA": PAUSE 30: GO TO 2080
2240 LET S$(RF,COF)=V$: PRINT AT 15-RF,COF+8; INVERSE 1;"{+8}"
2250 IF RD<>9 THEN LET S$(RD,COD)=A$: PRINT AT 15-RD,8+COD; INVERSE 1;"{A}": GO TO 2270
2260 LET TUOIPUNTI=TUOIPUNTI+1: LET TUEPEDINE=TUEPEDINE-1
2270 IF RD-RF=2 THEN LET TUOIPUNTI=TUOIPUNTI+1: LET MIEPEDINE=MIEPEDINE-1: LET S$((RD+RF)/2,(COF+COD)/2)=V$: PRINT AT 15-(RD+RF)/2,8+(COF+COD)/2; INVERSE 1;"{+8}"
2280 RETURN

Curiosità

Appunti, studi grafici, frammenti di listato e scarabocchi:

Click sull'immagine per ingrandirla.

Pagina modificata l'8/11/2011