Tres en Raya
Basic
Actualizado el 11 de Octubre del 2024 por Adelino (27 códigos) (Publicado el 9 de Septiembre del 2024)
995 visualizaciones desde el 9 de Septiembre del 2024
Juego de tres raya para Gwbasic o Qbasic en pantalla de texto.
100 defint a-y: width 40
120 color 7,0: cls
140 dim T$(9),ply(9)
150 dim N(9,60,7),Y(9,9)
160 dim H(9,3),I(1,7),F(9,9)
170 dim A(9),C(9),D(9),G(9)
180 dim X(9),V(9),W(9)
190 dim B(1),K(15),Q(15)
200 A$="123456789147258369159357"
210 c=1: f=1: ply(0)=9
220 F(0,0)=1: F(0,1)=2
230 B(0)=7: B(1)=4
240 for v=0 to 9
250 W(v)=v mod 2
260 V(v)=1-2*W(v)
270 X(v)=-1: G(v)=-1
280 F(0,v)=F(0,v)+1
290 next
300 for v=0 to 23
320 w=asc(mid$(A$,v+1))-48
330 G(w)=G(w)+1
340 H(w,G(w))=v\3
350 next
360 goto 6000
500 rem **** Restaurar ****
510 t=1-t
520 y=C(n): D(y)=0
530 for x=0 to G(y)
540 a=H(y,x): I(t,a)=I(t,a)-1
550 next
1000 rem **** Inicio ****
1100 for x=n+1 to ply(d)
1200 for y=0 to ply(d)-x
1300 Y(y,y+x)=W(y)
1400 next y,x
2000 y=C(n)-1: C(n)=y
2010 if(D(y)) goto 2000
2020 on F(y,n) goto 3000,4000,5000
2030 n=n+1: D(y)=1: C(n)=10
2040 for x=0 to G(y)
2050 a=H(y,x): I(t,a)=I(t,a)+1
2060 if(I(t,a)>2) then C(n)=1
2070 next
2080 if(n=ply(d) and C(n)>1) then C(n)=1: Y(0,n)=1
2090 t=1-t
2100 goto 2000
3000 rem **** Minimax ****
3100 y=0: n=n-1: Y(0,n)=1
3200 for x=n+1 to ply(d)
3300 y=y+1: a=Y(y,x)
3400 if(V(y)=Y(y-1,x)-a) then Y(y,x)=a+V(y)
3500 next
3600 goto 500
4000 rem **** Rutina n=0 ****
4100 if(d=0) goto 7000
4200 x=X(c)-d
4300 if(x=0) then d=0: C(0)=c
4400 if(x) then d=d+1: C(0)=N(c,A(c),x-1)
4500 goto 500
5000 rem **** Rutina n=1 ****
5100 n=0: y=0
5200 for x=1 to ply(d)
5300 if(Y(x-1,x)=0) then y=x: x=ply(d)
5400 next
5500 if(y<d) goto 500
5600 on d+1 goto 5800,5900
5700 N(c,A(c),X(c)-d)=C(0)
5710 d=d-1: C(0)=10
5720 goto 1000
5800 gosub 9500
5810 c=C(0): A(c)=0: X(c)=y-1
5820 if(y<2) goto 500
5830 d=y-1: C(0)=10
5840 goto 1000
5900 y=A(c): A(c)=y+1
5910 N(c,y,X(c)-1)=C(0)
5920 for x=0 to X(c)-2
5930 N(c,y+1,x)=N(c,y,x)
5940 next
5950 goto 500
6000 rem **** Tablero ****
6010 for v=0 to 8
6020 w=9-v: ply(w)=w
6030 y=20: x=7+6*(v mod 3): A$=chr$(97+v mod 3)
6040 gosub 9000
6050 T$(w)=A$
6060 y=16-5*(v\3): x=2: A$=chr$(49+v\3)
6070 gosub 9000
6080 T$(w)=T$(w)+A$
6090 next
6100 for v=0 to 3
6110 y=4+5*v: x=5: A$="----- ----- -----"
6120 gosub 9000
6130 next
6140 y=3: x=25: A$="Blancas Rojas"
6150 gosub 9000
6160 y=4: A$="------- -------"
6170 gosub 9000
6180 for v=0 to 15
6190 y=6+2*(v\4): x=25+4*(v mod 4)-v mod 2
6200 A$=mid$("---",2-v mod 2)
6210 gosub 9000
6220 K(v)=y-1: Q(v)=x
6230 next
7000 rem **** Teclado ****
7010 b=0: gosub 8000
7020 s=(E$="M")-(E$="K")
7100 c=c+s: if(c<1) then c=9
7110 if(c>9) then c=1
7120 if(D(c)) goto 7100
7130 b=B(t): gosub 8000
7200 f=f+(E$="-")-(E$="+")
7210 a=A(c): if(f>a) then f=1
7220 if(s or f<1) then f=a-(a=0)
7300 color 7,0
7310 for v=0 to 15
7320 y=K(v): x=Q(v): A$=mid$(" ",2-v mod 2)
7330 gosub 9000
7340 next
7500 a=X(c): if(a<0) then a=0: goto 7600
7510 v=2*a+2*t+1
7520 y=K(v): x=Q(v): A$="0-1"
7530 if(t=a mod 2) then A$="1-0"
7540 gosub 9000
7550 y=K(14): x=Q(14)
7560 A$="N"+chr$(167)+str$(f)
7570 gosub 9000
7600 for v=0 to a
7610 w=c: if(v) then w=N(c,f-1,v-1)
7620 y=K(2*v+2*t): x=Q(2*v+2*t): A$=T$(w)
7630 gosub 9000
7640 next
7800 E$=inkey$: if(E$<>"") goto 7800
7810 E$=inkey$: if(E$="") goto 7810
7820 E$=right$(E$,1)
7830 if(E$<>chr$(13)) goto 7000
7840 for v=0 to G(c)
7850 a=H(c,v): I(t,a)=I(t,a)+1
7860 next
7900 ply(0)=ply(0)-1
7910 if(ply(0)*X(c)=0) then end
7920 f=0: t=1-t: z=timer
7930 D(c)=1: C(0)=10
7940 goto 1000
8000 rem **** Figura ****
8010 a=c-1: color 0,b
8020 y=5+5*(a\3): x=18-6*(a mod 3): A$=" "
8030 gosub 9000: y=y+3: gosub 9000
8040 y=y-1: x=x-1: A$=" "
8050 gosub 9000: y=y-1
9000 rem **** Plasmar ****
9010 locate y,x: print A$
9020 return
9500 rem *** Tiempo ****
9510 locate 1,11: a=int(timer-z)
9520 A$="0"+mid$(str$(a mod 60),2)
9530 print str$(a\60) ":" right$(A$,2)
9540 return
No hay comentarios