Código de C/Visual C - Problemas de Ajedrez.

<<>>

Requerimientos

Probado cor turboC++ 3.0 de Borland en la app de Android Idosbox.

1.0

Publicado el 24 de Octubre del 2024gráfica de visualizaciones de la versión: 1.0
186 visualizaciones desde el 24 de Octubre del 2024

1.1

Publicado el 28 de Octubre del 2024gráfica de visualizaciones de la versión: 1.1
148 visualizaciones desde el 28 de Octubre del 2024

1.2

Actualizado el 17 de Noviembre del 2024 (Publicado el 5 de Noviembre del 2024)gráfica de visualizaciones de la versión: 1.2
308 visualizaciones desde el 5 de Noviembre del 2024

1.3
estrellaestrellaestrellaestrellaestrella(1)

Actualizado el 22 de Noviembre del 2024 (Publicado el 20 de Noviembre del 2024)gráfica de visualizaciones de la versión: 1.3
284 visualizaciones desde el 20 de Noviembre del 2024

1.4

Actualizado el 7 de Diciembre del 2024 (Publicado el 23 de Noviembre del 2024)gráfica de visualizaciones de la versión: 1.4
828 visualizaciones desde el 23 de Noviembre del 2024
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

Mate en 3 de Samuel Loyd.
SamLoyd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
#include<dos.h>
#include<time.h>
#include<stdio.h>
#include<conio.h>
 
char pieza[][6][22]={
"                    ","         22         ","        2   2       ","                    ","                    ","      22    22      ",
"                    ","         22         ","        22 22       ","   222222222222     ","                    ","     2222  2222     ",
"        2222        ","       222222       ","        22222       ","    222222222222    ","   222  2222  222   "," 22  2222  2222  22 ",
"       222222       ","       222222       ","       2222222      ","     222111111222   ","   222  2222  222   ","2222  22    22  2222",
"       222222       "," 22222   22   22222 ","      222222122     ","       22222221222  ","   222  2222  222   ","2222   2    2   2222",
"       222222       ","2211122  22  2211122","     22222222122    ","      2222222221222 ","   22222222222222   "," 22    22  22    22 ",
"        2222        ","21222122211222122212","    2222112222122   ","    2 2222222221222 ","   22222222222222   ","  22   22  22   22  ",
"       222222       ","21222212211221222212","    2222122222122   ","   2212222222222122 ","     2111111112     ","   22  22  22  22   ",
"      22222222      ","22122221222212222122","   22222222222122   ","  22221211222222122 ","     2222222222     ","   222 222222 222   ",
"      22222222      "," 221222212212222122 ","  2222222222221222  "," 222122122122222122 ","     2222222222     ","   22222222222222   ",
"      22222222      ","  2212222222222122  "," 22222222222222122  ","2221222212122222122 ","     2222222222     ","   22222222222222   ",
"       222222       ","   22222222222222   ","221222222222222122  "," 222122122122222122 ","     2222222222     ","   22222222222222   ",
"      22222222      ","   21111111111112   ","211222222212222122  ","  22221211222222122 ","     2222222222     ","   21111111111112   ",
"     2222222222     ","  2222222222222222  "," 222222  122222122  ","   2212222222222222 ","     2222222222     ","  2222222222222222  ",
"     2222222222     "," 222222222222222222 ","   22   22222221222 ","    2 222222222  22 ","     2222222222     "," 222222222222222222 ",
"    222222222222    ","  2222222222222222  ","        22222222122 ","       2222222   22 ","     2222222222     ","  2222222222222222  ",
"    222222222222    ","   21111111111112   ","       222222222122 ","        22222     2 ","    211111111112    ","   21111111111112   ",
"    222222222222    ","   22222222222222   ","       222222222122 ","      222222222     ","   22222222222222   ","   22222222222222   ",
"    222222222222    ","  2222222222222222  ","      2222222222122 ","    2222222222222   ","  2222222222222222  ","  2222222222222222  ",
"                    ","  2222222222222222  ","      2222222222222 ","   222222    22222  ","  2222222222222222  ","  2222222222222222  ",
"                    ","                    ","                    ","  22222             ","                    ","                    "};
char icono[][5][13]={
"      '      ","      ' '    ","  ''''''''   "," ''' ''' ''' ","   ''' '''   ",
"     '''     ","     ''''    ","   '      '  "," ' ''' ''' ' ","'' ''' ''' ''",
" '''  '  ''' ","    '    '   ","    '''''  ' "," '         ' ","''  '   '  ''",
"'   ' ' '   '","   '    ' '  ","   '     '  '"," ''''''''''' "," '  '   '  ' ",
"' '  ' '  ' '","  '  '   ' ' ","  '       ' '","   '     '   "," '  '' ''  ' ",
"'  '  '  '  '","  '      ' ' "," ' ' '    ' '","   '     '   "," '' '' '' '' ",
"'   '   '   '"," '        ' '","'   ' '   ' '","   '     '   "," ' '  '  ' ' ",
" '   ' '   ' ","'    ''   ' '"," ' ' '    ' '","   '     '   "," '         ' ",
"  '       '  "," '''' '   ' '","  '       ' '","   '     '   ","  '       '  ",
"  '''''''''  ","     '    ' '","   '     ' ''","   '''''''   ","  '''''''''  ",
" '         ' ","    '     ' '","    '   '   '","  '       '  "," '         ' ",
"'           '","   '      ' '","   '   '''   "," '         ' ","'           '",
"'''''''''''''","   ''''''''''","  '''''      "," ''''''''''' ","'''''''''''''"};
char posicion[][6][8]={
"........","......T.","..R.....","........",".....C.r",".....dc.",
"..p.p...","..R.....","T.......",".......p",".....Ppp","t.cCa...",
"..T.CrP.","........","...Pr...","..A....D","........","pD.p.p..",
"..P.....","........","....p...",".P.p....","........","p..r....",
"...P....",".....p..","...PPA..",".....CC.","..D...p.","....T..C",
".p.A.P.C","......p.","...P.P..",".....r..","........","..p...P.",
".P..P...",".D...Cr.","........","........","........","..PP...p",
"RD......","........","........",".R......","a......R","R..A...."};
char far*Q,far*q=(char far*)0xA0000000;
char ii[]={".P.RCATD.prcatd"};
char e[7][8],p[8][576];
char H[512],h[4][512]; //Tipo,casilla+direccion=Alcance
char E,N[512][8]; //Origen+direccion,alcance=Destino
int ix[]={-1,0,1,1,1,0,-1,-1,1,2,2,1,-1,-2,-2,-1};
int iy[]={1,1,1,0,-1,-1,-1,0,2,1,-1,-2,-2,-1,1,2};
int d1[]={0,4,0,0,0,1,0};
int d2[]={2,6,7,7,6,7,7};
int d3[]={1,1,1,1,2,2,1};
int pc1[9],pc2[9],pc3[9]; //(0PB,1PN,2R,3C,4A,5T,6D)
int aa[9],dd[9],gg[9],hh[9]; //Rutina principal
int G[64][8],K[12][12],P[64],pr[2]; //Pieza del rey
int A[33]={7},C[33]={64},T[33]={2}; //Tipo,casilla,bando
int F[65]={1},X[]={1156,1188,1244}; //Tabulacion
int B[64],b[]={0,3,-1,4,4,-2,2,1}; //Promocion y al paso
int S[][3]={0,0,15,0,15,0,0,0,0}; //Fondo, perfil
int L[100][9],Y[9][9],l[100]; //Control de jugadas
int I1[]={1,33},I2[]={0,32}; //Blancas de 1 a I2[0]
int Z[9],M[100][9],m[9][9]; //Secuencia
int D[]={2,1,2,2,2,0,2,2}; //Peon al frente
int C1[9],C2[9],C3[9]; //Piezas
int V[9],W[9],i[576];
int g=14,y=57595,ply=4;
int a,c,d,j,n,t,v,w,x,c1,c2;
 
void asignar(f){
P[c]=x=a>6?--I1[y=1]:++I2[y=0];
if(f==2) pr[y]=x;
A[x]=f;
C[x]=c;
T[x]=y;
}
void borrar(f,f1){
for(g=f;g--;)
for(d=f1*!g;d<3-f1*!g;d++)
for(n=X[d]+5120*g+9920,v=15;v--;n-=320)
for(w=d==1?55:31;w--;*(q+n+w)=0);
}
void figura(f,f1,f2,f3){
S[f1][0]=f3;
Q=q+54720+f%8*24-f/8*7680;
for(w=576;w--;*(Q+i[w])=S[f1][p[f2][w]]);
}
void tablero(f){
if(f%8) F[f+1]=F[f]=4-F[f-1];
figura(f,T[P[f]],A[P[f]],F[f]);
}
void jugada(f,f1){
n=5120*f+f1/448*34+10792;
a=f1%448/64;
c2=f1%64;
for(v=a>1?13:0;v--;n-=320)
for(w=13;w--;*(q+n+w)=icono[v][a-2][w]-32);
gotoxy(32,4+2*f);
if(f1) printf("%c%u",97+c2%8,1+c2/8);
}
void total(f,f1,f2){
gotoxy(26+11*f1,4+2*g);
if(f>1) printf("%3u",f/2);
else printf(f?"1/2":t==f2%2?"0-1":"1-0");
}
void jaque(f){
c=C[pr[f]];
for(v=d=0;d<8;d++,v=0)
if(h[3][g=G[c][d]]&&A[w=P[N[g][0]]]==3&&T[w]!=f) d=8;
else while(H[g]>v++)
     if(w=P[N[g][v]])
     if(T[w]!=f&&v<e[A[w]][d]) d=v=8;
     else break;
}
int main(){
_AX=0x13;
geninterrupt(0x10);
time_t ti;
while(i[ii[g]]=g--);
for(v=20;v--;w=v%2,V[v]=w-!w,W[v]=448*!w);
 
printf("%c[2;26fBlancas Negras",27);
for(w=2,v=12;v--;w=2,y-=5000)
do{
   x=!v&&w?1219:X[w]+5120*v-1;
   for(n=16;n--;*(q+x+320*n)=*(q+y+320*n)=7);
   for(n=y+1-x,y=x;n--;*(q+x+n)=*(q+x+n+5120)=7);
  }while(w--);
for(a=7;a--;)
for(d=d1[a];d<=d2[a];d+=d3[a])
if(a>3) e[a][d]=8;
else if(a>1) e[2][d]=6-2*a;
     else if(D[d]>1) e[!a][d]=2;
 
for(c=63,v=0;v<8;v++)
for(w=8;w--;K[9-v][w+2]=c+1,B[c--]=b[v])
if(a=i[posicion[v][2][w]]) //posicion[v][?=0,1,...][w]
asignar(--a%7);
for(v=w=y=0;y<24;y++,w+=296)
for(x=0;x<24;x++,i[v++]=w++)
if(y>1&&y<22&&x>1&&x<22)
for(n=6;n--;)
if(a=pieza[y-2][n][x-2]-32)
p[n+1][v]=p[n+1-!n][v]=a-16;
 
for(d=7,c=0;c<64;tablero(c++),d=7)
do{
   G[c][d]=++g;
   x=c%8+2;
   y=c/8+2;
   if(j=K[y+iy[d+8]][x+ix[d+8]])
   N[g][h[3][g]--]=j-1;
   while(j=K[y+=iy[d]][x+=ix[d]])
   N[g][++H[g]]=j-1;
   for(a=H[g]?3:0;a--;h[a][g]++)
   h[a][g]=a<2&&B[c]==a+2&&d==4*a+1;
  }while(d--);
 
Inicio:
ti=time(NULL)-1;
for(j=v=0;v<ply;v++)
for(w=0;ply-v>w++;Y[w][v+w]=W[w]);
pc1[n=1]=I1[t]; //Primera pieza
 
Origen:
c=C1[n]=C[pc1[n]]; //Casilla de la pieza
if(c>63) goto Siguiente;
P[c]=0;
aa[n]=A[pc1[n]]; //Tipo de pieza
dd[n]=d1[aa[n]]; //Direccion inicial
 
Alcance:
gg[n]=G[C1[n]][dd[n]];
hh[n]=aa[n]<4?h[aa[n]][gg[n]]:H[gg[n]];
if(!hh[n]) goto Direccion;
Z[n]=aa[n]!=3;
 
Destino:
c=C2[n]=N[gg[n]][Z[n]]; //Casilla destino
if(pc2[n]=P[c])
if(T[P[c]]==t) goto Direccion;
if(aa[n]!=t) goto Simulacion;
if(D[dd[n]]!=T[P[c]]) A[pc1[n]]=B[c]==t?6:t; //Promocion
else{ // Al paso
     if(P[c]||B[c]+t+1||aa[x=n-1]>1) goto Direccion;
     if(Z[x]<2||c+c!=C1[x]+C2[x]) goto Direccion;
     c=C3[n]=C2[x];
     pc3[n]=P[c];
     C[P[c]]=64;
     P[c]=0;
    }
 
Simulacion:
if(pc2[n]) C[pc2[n]]=64;
C[pc1[n]]=C2[n]; //Pieza a destino
P[C2[n]]=pc1[n];
jaque(t);
if(d<9)
if(n<ply)
switch(n){
  case 5: jaque(1);
          if(d<9) break;
 default: pc1[++n]=I1[t=!t];
          goto Origen;
         }
else Y[1][n]+=2;
 
Restaurar:
P[C2[n]]=pc2[n];
if(pc2[n]) C[pc2[n]]=C2[n];
if(pc3[n]){
           C[pc3[n]]=C3[n];
           P[C3[n]]=pc3[n];
           pc3[n]=0;
          }
if(A[pc1[n]]>aa[n])
if(--A[pc1[n]]<3) A[pc1[n]]=t;
else goto Simulacion;
if(!pc2[n]&&hh[n]>Z[n]++) goto Destino;
 
Direccion:
dd[n]+=d3[aa[n]];
if(dd[n]<=d2[aa[n]]) goto Alcance;
C[pc1[n]]=C1[n]; //Restaura origen
P[C1[n]]=pc1[n];
 
Siguiente:
if(I2[t]>pc1[n]++) goto Origen; //Pieza siguiente
if(!Y[1][x=n--])
if(t){
      jaque(1);
      if(d<9) Y[1][x]=t=n<2;
      else if(Y[n-n%2][y=x])
           while(--y>1)
           a=A[pc1[y]],
           m[n][y-1]=C2[y]+64*a+W[a==aa[y]];
      if(!t) goto Restaurar;
     }
Y[1][n]+=2;
 
switch(n){
  case 0: goto Plasmar;
  case 1: for(x=1;ply>x++;x=v<2?ply:x)
          v=L[j][l[j]=y]=Y[y=x-1][x];
          L[j][y+1]=448-v;
          L[j][0]=y+(y+x)%2;
          while(--y) M[j][y+1]=!v?m[l[j]][y]:0;
          a=A[pc1[1]];
          M[j][1]=C2[1]+64*a+W[a==aa[1]];
          M[j++][0]=C1[1];
          break;
 default: for(y=0;ply-n>y++;x++)
          if(v=Y[y+1][x]-Y[y][x])
          if(V[y]==(v>0)-(v<0)) Y[y+1][x]-=v;
         }
for(v=n;v<ply;v++) //Reinicio de contadores
for(w=0;ply-v>w++;Y[w][v+w]=W[w]);
t=!t;
goto Restaurar;
 
Plasmar:
borrar(11,0);
total(j?j+j:Y[1][1],t,g=0);
gotoxy(26+11*t,4+2*ply);
printf("N=%u",g=ply);
gotoxy(30,4+2*g);
printf("%5.f%c",difftime(time(NULL),ti),34);
if(y=j)
do{ //Ordenar maximos o minimos
   for(c=x=j;x--;)
   if(l[x]>0)
   if(c==j) c=x;
   else if(v=L[c][L[c][0]]-L[x][L[x][0]])
        c=V[ply]==(v>0)-(v<0)?c:x;
   x=l[c]*=x;
   if(++g>10) continue;
   jugada(g,M[c][1]);
   total(L[c][-x],(!t+ply)%2,-x%2);
  }while(--y);
c1=4+56*t;
 
Teclado:
figura(c2=c1,T[x],A[x=P[c1]],7+t);
while(E=kbhit()) getch();
while(!E) E=getch();
if(E==27&&getch()==E) return 0;
if(E==75&&c1) c1--;
if(E==80&&c1>7) c1-=8;
if(E==77&&c1<63) c1++;
if(E==72&&c1<56) c1+=8;
if(c=E!=13) figura(c2,T[x],A[x],F[c2]);
ply+=d=(E=='+'&&ply<6-t)-(E=='-'&&ply>2);
if(d) goto Inicio;
if(c--) goto Teclado;
 
Eleccion:
c+=V[E!=75];
if(c==j||c<0)
if(c1==c2) goto Teclado;
else c=c<0?j-1:0;
if(M[c][0]!=c1) goto Eleccion;
for(g=1-l[c];--g;)
jugada(g-1,M[c][g]),
total(L[c][g],(g+t)%2,g%2);
figura(c2,t,a,8-t);
do E=getch();
   while(!E);
borrar(ply,1);
figura(c2,T[y],A[y=P[c2]],F[c2]);
if(E==27) goto Teclado;
if(E!=13) goto Eleccion;
 
Z[0]=(c2-c1)/8*V[!t]; //Posibilitar al paso
if(a==t&&(c2-c1)%8) //Al paso
if(!y){
       figura(c,2,7,F[c=C2[0]]);
       C[P[c]]=64;
       P[c]=0;
      }
figura(c1,2,7,F[c1]);
figura(c2,t,a,F[c2]);
aa[0]=A[x]=a; //Promocion
C1[0]=c1;
C2[0]=c2;
C[x]=c2;
C[y]=64;
P[c1]=0;
P[c2]=x;
t=!t;
ply-=ply>2;
goto Inicio;
}



Comentarios sobre la versión: 1.4 (0)


No hay comentarios
 

Comentar la versión: 1.4

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s7539