Pascal/Turbo Pascal - Resolver programa tipo arreglos (ajedrez) en Pascal

 
Vista:
sin imagen de perfil

Resolver programa tipo arreglos (ajedrez) en Pascal

Publicado por Héctor (8 intervenciones) el 27/03/2013 21:25:29
buen dia a la comunidad de programadores, pido ayuda con el siguiente programa, tipo arreglos en Pascal:

En la partida hipotética que juremos sólo tienes un alfil (’A’) (y , claro, tu rey escondido por ahí) y restan tres piezas del contrario: su rey (’R’), una torre (’T’) y un peón (’P’). Se desea saber qué piezas amenaza tu alfil o si no hay alguna amenaza. Define un tablero de ajedrez declarando la variable tablero que será un arreglo bidimensional de tamaño 8  8 donde se sitúan las piezas A, R, T, P . El programa solicitará la posición de las piezas contrincantes por medio de la coordenadas r1 c1 y el tipo de pieza p1, las coordenadas r2, c2 y el tipo de pieza p2, las coordenadas r3, c3 y el tipo de pieza p3, finalmente las coordenadas de tu alfil ra y ca. Si tu alfil amenaza una o más piezas contrincantes devolverá un Amenaza a [tipo de pieza]) de lo contrario devolverá No hay amenaza. Pinta el tablero con las piezas.
-------------------------------------------------------------------------------------------------------------------------------------
1. No te preocupes por errores del usuario cuando escriba las coordenadas. Es decir, no se escribirán coordenadas fuera del tablero, ni se encimarán piezas.
2. El alfil sólo puede moverse de manera diagonal cuantas posiciones se desee, se desplaza libremente.
3. El jugador de ajedrez tiene una visión completa del tablero y el jugador experimentado identifica las amenazas actuales y las que posiblemente se puedan dar. La computadora no tiene esta visión total y tiene que hacer la revisión casilla por casilla.
4. Una pieza estará amenazada por tu alfil si se encuentra dentro del recorrido diagonal.
5. Para este juego ’hipotético’, si dos piezas están en el recorrido del alfil, entonces son amenazadas ambas. No se interpone una para salvar a la otra (sic).

Ejemplo
-------------------------------------------------------------------------------------------------------------------------------------
Entrada
-------------------------------------------------------------------------------------------------------------------------------------
8
1
R
4
7
P
8
6
T
4
2
-------------------------------------------------------------------------------------------------------------------------------------
Salida
-------------------------------------------------------------------------------------------------------------------------------------
Amenaza: Torre
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
. . . . A. . .. . .. .P . .
. . . . . . . .. . . . . . . .
. . . . . . . .. . . . . . . .
. . . . . . . .. . . . . . . .
R. . . . . . T. .. . . . .

De antemano les agradesco mucho, cualquier opinion o ejemplo es bien recibido.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Resolver programa tipo arreglos (ajedrez) en Pascal

Publicado por ramon (2158 intervenciones) el 02/04/2013 21:04:59
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
{A ver si esto ayuda}
 
 program lineatexto;
 uses
    crt;
 type
   cordenadas = record
            xp : integer;
            yp : integer;
          end;
 
   tablero = record
           cord : cordenadas;
           pieza : char;
         end;
 
 var
   x, y, xx, yy : integer;
   ajedrez : array[1..8,1..8] of tablero;
   alfin : array[1..2] of integer;
   alx, aly : integer;
 
  procedure limpia;
  var
    li, ti : integer;
  begin
     for li := 1 to 8 do
       for ti := 1 to 8 do
       ajedrez[li,ti].pieza := '0';
  end;
 
  procedure cuadriculatablero(xt, yt : integer);
  var
     i, px, py : integer;
     tex : string[11];
  begin
      gotoxy(xt,yt + 3);write('ÚÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄÂÄÄÄ¿');
      gotoxy(xt,yt + 4);write('³   ³   ³   ³   ³   ³   ³   ³   ³');
      gotoxy(xt,yt + 5);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
      gotoxy(xt,yt + 6);write('³   ³   ³   ³   ³   ³   ³   ³   ³');
      gotoxy(xt,yt + 7);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
      gotoxy(xt,yt + 8);write('³   ³   ³   ³   ³   ³   ³   ³   ³');
      gotoxy(xt,yt + 9);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
     gotoxy(xt,yt + 10);write('³   ³   ³   ³   ³   ³   ³   ³   ³');
     gotoxy(xt,yt + 11);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
     gotoxy(xt,yt + 12);write('³   ³   ³   ³   ³   ³   ³   ³   ³');
     gotoxy(xt,yt + 13);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
     gotoxy(xt,yt + 14);write('³   ³   ³   ³   ³   ³   ³   ³   ³');
     gotoxy(xt,yt + 15);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
     gotoxy(xt,yt + 16);write('³   ³   ³   ³   ³   ³   ³   ³   ³');
     gotoxy(xt,yt + 17);write('ÃÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄÅÄÄÄ´');
     gotoxy(xt,yt + 18);write('³   ³   ³   ³   ³   ³   ³   ³   ³');
     gotoxy(xt,yt + 19);write('ÀÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÁÄÄÄÙ');
     px := 29;
     py := 5;
     i := 1;
    repeat
      gotoxy((px  - 4) + (i * 4),py - 2);write((px - 4) + (i * 4));
      gotoxy(px - 4,(py - 2) + (i * 2));write((py - 2) + (i * 2));
      i := i + 1;
    until i > 8;
     px := 1;
     py := yt + 2;
     gotoxy(xt + 10,yt + 1);write('Cordenada X');
     tex := 'Cordenada Y';
     for i := 1 to 11 do
     begin
        gotoxy(xt - 4,(yt + 5) + i);write(tex[i]);
     end;
  end;
 
  procedure ponpiezas;
  var
     posx, posy, k, xz, yz : integer;
     piz : char;
  begin
    for k := 1 to 3 do
    begin
  case k of
 1 : piz := 'P';
 2 : piz := 'T';
 3 : piz := 'R';
    end;
     gotoxy(1,1);write(piz,' = Cordenada X : ');
     readln(xz);
     gotoxy(1,2);write(piz,' = Cordenada Y : ');
     readln(yz);
     posx := xz - 28;
     posy := yz - 5;
     ajedrez[posx, posy].pieza := piz;
     ajedrez[posx, posy].cord.xp := xz;
     ajedrez[posx, posy].cord.yp := yz;
     gotoxy(1,1);write('                    ');
     gotoxy(1,2);write('                    ');
     gotoxy(xz,yz);write(piz);
   end;
     gotoxy(1,1);write('A = Cordenada X : ');
     readln(alx);
     gotoxy(1,2);write('A = Cordenada Y : ');
     readln(aly);
     alfin[1] := alx;
     alfin[2] := aly;
     gotoxy(alfin[1],alfin[2]);write('A');
     gotoxy(1,1);write('                    ');
     gotoxy(1,2);write('                    ');
  end;
 
  procedure linea(xl, yl : integer);
  var
    xx, yy : integer;
  begin
    xx := xl;
    yy := yl;
    repeat
    if ajedrez[xx - 28,yy - 5].pieza in['p','P','t','T','r','R'] then
    begin
      gotoxy(2,21);write('Pieza Atacada Por Alfin = ',
                                  ajedrez[xx - 28,yy - 5].pieza);
    end;
    xx := xx - 4;
    yy := yy - 2;
    until (xx < 29) or (yy < 5);
    xx := xl;
    yy := yl;
    repeat
    if ajedrez[xx - 28,yy - 5].pieza in['p','P','t','T','r','R'] then
    begin
      gotoxy(2,22);write('Pieza Atacada Por Alfin = ',
                                   ajedrez[xx - 28,yy - 5].pieza);
    end;
    xx := xx + 4;
    yy := yy - 2;
    until (xx > 58) or (yy < 5);
    xx := xl;
    yy := yl;
    repeat
    if ajedrez[xx - 28,yy - 5].pieza in['p','P','t','T','r','R'] then
    begin
      gotoxy(2,23);write('Pieza Atacada Por Alfin = ',
                                     ajedrez[xx - 28,yy - 5].pieza);
    end;
    xx := xx + 4;
    yy := yy + 2;
    until (xx > 57) or (yy > 19);
    xx := xl;
    yy := yl;
    repeat
    if ajedrez[xx - 28,yy - 5].pieza in['p','P','t','T','r','R'] then
    begin
      gotoxy(2,24);write('Pieza Atacada Por Alfin = ',
                                     ajedrez[xx - 28,yy - 5].pieza);
    end;
    xx := xx - 4;
    yy := yy + 2;
    until (xx < 29) or (yy > 19);
    gotoxy(2,25);write('Pulse Espacio');
  end;
 
 begin
     clrscr;
     cuadriculatablero(27,1);
     limpia;
     ponpiezas;
     linea(alx,aly);
     readkey;
 end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar