Tres en Raya
Basic
Actualizado el 11 de Octubre del 2024 por Adelino (27 códigos) (Publicado el 9 de Septiembre del 2024)
994 visualizaciones desde el 9 de Septiembre del 2024
Juego de tres raya para Gwbasic o Qbasic en pantalla de texto.
100 defint a-y
110 width 40
120 color 7,0: cls
140 dim A(9),B(9),T$(9)
150 dim N(250,7),Y(9,9)
160 dim H(9,3),I(1,7),F(9,9)
170 dim C(9,9),D(9),G(9)
180 dim X(9),V(9),W(9)
190 dim K(15),Q(15)
200 A$="123456789147258369159357"
210 ply=9
220 F(0,0)=2: F(0,1)=1
240 for v=0 to 9
250 G(v)=-1
260 W(v)=v mod 2
270 V(v)=1-2*W(v)
280 F(0,v)=3-F(0,v)
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 rem **** Tablero ****
370 for v=0 to 8
380 y=20: x=7+6*(v mod 3): A$=chr$(97+v mod 3)
390 gosub 9000
400 T$(9-v)=A$
410 y=16-5*(v\3): x=2: A$=chr$(49+v\3)
420 gosub 9000
430 T$(9-v)=T$(9-v)+A$
440 next
450 for v=0 to 3
460 y=4+5*v: x=5: A$="----- ----- -----"
470 gosub 9000
480 next
490 y=3: x=25: A$="Blancas Rojas"
500 gosub 9000
510 y=4: A$="------- -------"
520 gosub 9000
530 for v=0 to 15
540 y=6+2*(v\4): x=25+4*(v mod 4)-v mod 2
550 A$=mid$("---",2-v mod 2)
560 gosub 9000
570 K(v)=y-1: Q(v)=x
580 next
600 rem **** Teclado ****
610 v=(E$="M")-(E$="K")
620 c=c+v: if(c<1) then c=9: v=-1
630 if(c>9) then c=1: v=1
640 if(D(c)) goto 620
650 b=7-3*t: gosub 8000
660 a=a+(E$="-")-(E$="+")
670 if(a>B(c)) then a=A(c)+1
680 if(v<>0 or a<=A(c)) then a=B(c)
700 color 7,0
710 for v=0 to 15
720 y=K(v): x=Q(v): A$=mid$(" ",2-v mod 2)
730 gosub 9000
740 next
750 h=X(c): if(h=0) goto 820
760 y=K(2*(h+t)-1): x=Q(2*(h+t)-1): A$="1-0"
770 if(t=h mod 2) then A$="0-1"
780 gosub 9000
790 h=h-1: y=K(14): x=Q(14)
800 A$="N"+chr$(167)+str$(a-A(c))
810 gosub 9000
820 for v=0 to h
830 w=c: if(v) then w=N(a-1,v-1)
840 y=K(2*(v+t)): x=Q(2*(v+t)): A$=T$(w)
850 gosub 9000
860 next
870 E$=inkey$: if(E$<>"") goto 870
890 E$=inkey$: if(E$="") goto 890
900 E$=right$(E$,1)
910 if(E$<>chr$(13)) then b=0: gosub 8000: goto 600
920 if(ply=1 or X(c)=1) then end
930 for x=0 to G(c)
940 h=H(c,x): I(t,h)=I(t,h)+1
950 next
960 ply=ply-1
970 a=0: w=0: t=1-t
980 D(c)=1: C(0,0)=10
1000 rem **** Inicio ****
1100 v=ply-a
1200 for x=n+1 to v
1300 for y=0 to v-x
1400 Y(y,y+x)=W(y)
1500 next y,x
2000 y=C(a,n)-1: C(a,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(a,n)=10
2040 for x=0 to G(y)
2050 h=H(y,x): I(t,h)=I(t,h)+1
2060 if(I(t,h)>2) then C(a,n)=1
2070 next
2080 if(n=v and C(a,n)>1) then C(a,n)=1: Y(0,n)=1
2090 t=1-t
2100 goto 2000
3000 rem **** Rutina n=0 ****
3100 if(a=0) goto 600
3200 a=a-1
3300 goto 6000
4000 rem **** Rutina n=1 ****
4010 n=0: x=0
4020 for y=1 to v
4030 if(Y(y-1,y)=0) then x=y: y=v
4040 next
4100 if(a=0) then c=C(0,0): X(c)=x: A(c)=w: B(c)=w
4200 if(x<>X(c)-a) goto 6000
4300 x=a-1: if(a) then N(w,x)=C(a,0)
4400 for y=1 to x
4500 N(w+1,y-1)=N(w,y-1)
4600 next
4700 if(a=X(c)-1) then w=w+1: B(c)=w: goto 6000
4800 a=a+1: C(a,0)=10
4900 goto 1000
5000 rem **** Minimax ****
5100 y=0: n=n-1: Y(0,n)=1
5200 for x=n+1 to v
5300 y=y+1: h=Y(y,x)
5400 if(V(y)=Y(y-1,x)-h) then Y(y,x)=h+V(y)
5500 next
6000 rem **** Restaurar ****
6010 t=1-t
6020 y=C(a,n): D(y)=0
6030 for x=0 to G(y)
6040 h=H(y,x): I(t,h)=I(t,h)-1
6050 next
6060 goto 1000
8000 rem **** Figura ****
8010 color 0,b
8020 y=5+5*((c-1)\3): x=18-6*((c-1) mod 3)
8030 A$=" ": gosub 9000: y=y+3
8040 gosub 9000: y=y-1: x=x-1
8050 A$=" ": gosub 9000: y=y-1
9000 rem **** Plasmar ****
9010 locate y,x: print A$
9020 return
No hay comentarios