Pascal/Turbo Pascal - [CONSULTA - JUEGO: '4 EN LÍNEA']

 
Vista:
Imágen de perfil de Alejandra
Val: 1
Ha disminuido su posición en 75 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

[CONSULTA - JUEGO: '4 EN LÍNEA']

Publicado por Alejandra (18 intervenciones) el 19/09/2015 19:23:03
BUENAS TARDES!!!

PROBLEMA 3: 4 EN LÍNEA

Un apasionante juego de mesa en donde los jugadores compiten para poder lograr el objetivo de poder poner 4 fichas en línea ya sea vertical u horizontal.
El tablero es de 7 de ancho por 8 de alto. Es un juego por turnos en donde cada uno de los jugadores "tira" una ficha en alguna de las 7 columnas y la misma queda arriba de otra ficha (si existe alguna) o sobre la base. El juego termina si alguno de los jugadores cumplió el objetivo principal o si el tablero se llena y no puede colocarse otra ficha más, en ese caso se considera un empate.

***Lo tengo que resolver en pseudocódigo y turbo pascal***

p/d: encontré acá en la página el código del juego LA VIEJA (que es mas o menos parecido al que me piden) pero no entendí bien el código y por eso al compilarlo no sabía que datos ingresar para verificar si funciona o no.


Desde ya gracias por la respuesta!!!!
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

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por ramon (2158 intervenciones) el 21/09/2015 00:14:16
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
{se tienen que entrar las posiciones de los cuadros a ver si esto te ayuda }
 
program lasvieja;
 uses
   crt;
 type
    tablero = array[1..3,1..3] of char;
 
 
  var
    juego : tablero;
    cont, px, py : integer;
    posx, posy : integer;
    jug : char;
    sal : boolean;
 
  procedure presentapantalla(x1, y1 : integer);
  begin
   clrscr;
   gotoxy(x1,y1 + 1);write('*Tablero*');
   gotoxy(x1,y1 + 3);write('ÚÄÂÄÂÄ¿');
   gotoxy(x1,y1 + 4);write('³ ³ ³ ³1');
   gotoxy(x1,y1 + 5);write('ÃÄÅÄÅÄ´');
   gotoxy(x1,y1 + 6);write('³ ³ ³ ³2');
   gotoxy(x1,y1 + 7);write('ÃÄÅÄÅÄ´');
   gotoxy(x1,y1 + 8);write('³ ³ ³ ³3');
   gotoxy(x1,y1 + 9);write('ÀÄÁÄÁÄÙ');
  gotoxy(x1,y1 + 10);write(' 1 2 3 ');
  end;
 
  procedure ponentablero(xp, yp : integer; cual : char);
  begin
    case xp of
  1 : px := 31;
  2 : px := 33;
  3 : px := 35;
    end;
    case yp of
  1 : py := 7;
  2 : py := 9;
  3 : py := 11;
    end;
  gotoxy(px,py);write(cual);
 end;
 
  procedure entasposiciones(c : char);
  var
    t : char;
    xx, yy : integer;
   begin
      gotoxy(20,14);write('Juega El Jugador = ',c);
      gotoxy(20,15);write('Posicion X : ');
      gotoxy(33,15);
      repeat
         t := readkey;
      until t in['1','2','3'];
      gotoxy(33,15);write(t);
      xx := ord(t) - 48;
      t := '0';
      gotoxy(20,16);write('Posicion Y : ');
      gotoxy(33,16);
      repeat
          t := readkey;
      until t in['1','2','3'];
      gotoxy(33,16);write(t);
      yy := ord(t) - 48;
      ponentablero(xx,yy,c);
      juego[xx,yy] := c;
      gotoxy(20,15);clreol;
      gotoxy(20,16);clreol;
      gotoxy(20,14);clreol;
   end;
 
   function completo(j : char) : boolean;
   begin
      completo := false;
      if (juego[1,1] = j) and (juego[2,1] = j) and (juego[3,1] = j) then
      completo := true
   else
      if (juego[1,2] = j) and (juego[2,2] = j) and (juego[3,2] = j) then
      completo := true
   else
      if (juego[1,3] = j) and (juego[2,3] = j) and (juego[3,3] = j) then
      completo := true
   else
      if (juego[1,1] = j) and (juego[1,2] = j) and (juego[1,3] = j) then
      completo := true
   else
      if (juego[2,1] = j) and (juego[2,2] = j) and (juego[2,3] = j) then
      completo := true
   else
      if (juego[3,1] = j) and (juego[3,2] = j) and (juego[3,3] = j) then
      completo := true
   else
      if (juego[1,1] = j) and (juego[2,2] = j) and (juego[3,3] = j) then
      completo := true
   else
      if (juego[3,1] = j) and (juego[2,2] = j) and (juego[1,3] = j) then
      completo := true;
   end;
 
  begin
      posx := 30;
      posy := 3;
      jug := 'X';
      presentapantalla(posx,posy);
      sal := false;
      cont := 1;
     repeat
      entasposiciones(jug);
      if completo(jug) then
      begin
         gotoxy(10,18);write('Gano El Jugador : ',jug);
         sal := true;
         break;
      end;
      if sal <> true then
      begin
         if jug = 'X' then
         jug := 'O'
       else
         jug := 'X';
         cont := cont + 1;
      end;
      until (sal = true) or (cont > 6);
      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
2
Comentar
Imágen de perfil de Alejandra
Val: 1
Ha disminuido su posición en 75 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por Alejandra (18 intervenciones) el 21/09/2015 17:41:50
Entendí muchas gracias ramon!!!!
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
Imágen de perfil de Alejandra
Val: 1
Ha disminuido su posición en 75 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por Alejandra (18 intervenciones) el 22/09/2015 17:55:46
ramon una consulta: en mi caso particular del ejercicio solo me piden el algoritmo (no que haga el gráfico) tengo que quitar el procedure ponentablero, presentapantalla no más?.-
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

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por ramon (2158 intervenciones) el 22/09/2015 20:58:54
Fija te bien en el ejemplo lo que realiza es una comprobación de las posiciones de la matriz según las normas del juego si
le quitas la presentación como sabrás si se entro las posiciones correctas visual mente,
Por quitar todo lo que consideres no servible para tu prueba pero tendrás que anular los accesos a esos puntos tan bien.
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
Imágen de perfil de Alejandra
Val: 1
Ha disminuido su posición en 75 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por Alejandra (18 intervenciones) el 24/09/2015 02:42:10
TPI-4-3-EN-RAYA

Hola ramon (te molesto de nuevo) con mi compañera encontramos otra forma de resolver el ejercicio en pascal (en la imagen está el juego de 3 en raya con una matriz de 3x3) y ahí verifica si las filas y columnas están vacías o son iguales, en la pantalla emite un mensaje de: EMPATE!. y cuando lo adaptamos a nuestra matriz de 8x7 no nos muestra el mensaje de EMPATE!

tpi-5

Porqué será?.-
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

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por ramon (2158 intervenciones) el 24/09/2015 22:52:23
Supongo que la verificación la realizáis como una matriz de 8x7 para comprobar toda la matriz y no como matriz de 3x3.
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

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por ramon (2158 intervenciones) el 25/09/2015 16:17:53
Disculpa mi mal entender la pregunta, me estas ablando de un juego de cuatro en linea en un tablero de 8x7 en realidad seria
7x6 pero de todas las formas el sistema de comprobación es total mente diferente al 3x3 en linea puesto que en tu caso por ejemplo
podrías tener ocupada las casillas 1x1 y 1x2 con otras fichas pero tener linea en 1x3 1x4 1x5 1x6 lo cual te daría ganador por tener
cuatro en linea no es asi.
Si esto es dímelo y intentare prepararte un ejemplo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Alejandra
Val: 1
Ha disminuido su posición en 75 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por Alejandra (18 intervenciones) el 25/09/2015 19:06:48
En el enunciado nos pide un tablero de 8x7. Si te agradecería el ejemplo ramon
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

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por ramon (2158 intervenciones) el 25/09/2015 19:36:20
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
{Mirar esto}
 
 program cuatroenrraya;
 uses
    crt;
 type
    matriz = array[1..7,1..6] of char;
  var
    mat : matriz;
    x, y : integer;
 
 
   procedure iniciamatriz;
   begin
      fillchar(mat,sizeof(matriz),' ');
   end;
 
   procedure entradadatos(var q : boolean; cual : char);
   begin
      q := false;
      write('  Entra Posicion X : ');readln(x);
      if x <> 0 then
      begin
      write('  Entra Posicion Y : ');readln(y);
      if y <> 0 then
      begin
      if (x < 8) and (x > 0) then
        if (y < 7) and (y > 0) then
        mat[x,y] := cual;
        q := true;
      end;
    end;
   end;
 
   procedure muestramatriz;
   var
     h, k : integer;
    begin
 
        for h := 1 to 6 do
        begin
          for k := 1 to 7 do
          begin
          write(' | ',mat[k,h]);
          end;
          write(' | ');
          writeln;
          writeln(' -----------------------------');
        end;
    end;
 
   function comprueva_echa(ch : char) : boolean;
   var
     c, v, i : integer;
     sies : boolean;
   begin
      comprueva_echa := false;
      sies := false;
    for i := 1 to 6 do
    begin
      for c := 1 to 7 do
       if mat[c,i] = ch then
       begin
   if (mat[c + 1,i] = ch) and (mat[c + 2,i] = ch) and (mat[c + 3,i] = ch) then
   sies := true;
       end;
    end;
      if sies = false then
      begin
        for c := 1 to 7 do
          for i := 1 to 6 do
          if mat[c,i] = ch then
          begin
   if (mat[c,i + 1] = ch) and (mat[c,i + 2] = ch) and (mat[c,i + 3] = ch) then
   sies := true;
          end;
      end;
   if sies = false then
   begin
       c := 1;
       for i := 1 to 6 do
       begin
          if mat[c,i] = ch then
          begin
 if (mat[c + 1,i + 1] = ch) and (mat[c + 2,i + 2] = ch) and (mat[c + 3,i + 3] = ch) then
 sies := true;
          end;
          c := c + 1;
          if c > 7 then
          c := 7;
       end;
     end;
 if sies = false then
   begin
       c := 7;
       for i := 6 downto 1 do
       begin
          if mat[c,i] = ch then
          begin
 if (mat[c - 1,i - 1] = ch) and (mat[c - 2,i - 2] = ch) and (mat[c - 3,i - 3] = ch) then
 sies := true;
          end;
          c := c - 1;
          if c < 1 then
          c := 1;
        end;
      end;
     comprueva_echa := sies;
   end;
 
   procedure jugando;
   var
     tec : char;
     cu : char;
     l : boolean;
   begin
      cu := 'X';
      repeat
           clrscr;
           writeln('Juega El Jugador De ',cu,'          Twrmina Entrando 0');
           muestramatriz;
           entradadatos(l, cu);
           if l = false then
           tec := #27
         else
           tec := #0;
           clrscr;
           muestramatriz;
           if comprueva_echa(cu) = true then
           begin
           writeln;
           writeln('   Gano El Simbolo ',cu);
           tec := #27;
           end;
           if cu = 'X' then
           cu := 'O'
         else
           cu := 'X';
      until tec = #27;
   end;
 
 
 
   begin
      jugando;
      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
1
Comentar
Imágen de perfil de Alejandra
Val: 1
Ha disminuido su posición en 75 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por Alejandra (18 intervenciones) el 15/10/2015 01:21:04
Hola ramon mirá con una compañera pasamos el juego '3 en raya' y lo readaptamos para nuestro trabajo que es '4 en línea'. El problema que tenemos es que en la parte donde se verifica si alguna de las filas o columnas son iguales para detectar 'si hay empate' a la hora de compilar no nos muestra el mensaje por pantalla de que 'hay empate' (es por eso que te había adjuntado la imagen anterior y era de este algoritmo). Vos podrías indicarme cuál es el error de porque no me muestra el mensaje de cuando hay empate?.-

Gracias.-


p/d: adjunto algoritmo en dev pascal.
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

[CONSULTA - JUEGO: "4 EN LÍNEA"]

Publicado por ramon (2158 intervenciones) el 29/10/2015 14:12:23
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
{Mira como podrás apreciar tienes una matriz de 8 x 7 lo cual una busque da entre 56 posiciones no 4 espero esto te sirva   }
 
 program CuatroEnRaya1;
   uses
      crt;
   const
    (* Simbolos del tablero: blanco, jug.1, jug.2*)
    simbolo : array [0..2] of char  = (' ', 'O', 'X');
 
 
   var
    tablero : array[1..8,1..7] of char; (* Tablero de juego*)
    terminado: boolean;
    sal : char;
 
 
   procedure PreguntarPosicion(jugador: integer);  (* 1 := Jug.1, 2= Jug.2*)
   var
        fila, columna: integer;
    begin
      repeat
        WriteLn;
 
        (* Pido fila*)
        repeat
            Write('En que fila (1 a 8) Jugador ',jugador,' : ');
          {Aseguramos la entrada numerica}
          {$I-}  ReadLn(fila); {$I+}
          if ioresult <> 0 then
          begin
            write('Error De Entrada Numerica Repita Dato');
            fila := 0;
            writeln;
            end;
        until fila in [1..8];
 
        (* Pido columna*)
        repeat
            Write('En que columna (1 a 7) Jugador ',jugador,' : ');
          {Aseguramos la entrada numerica}
          {$I-}  ReadLn(columna); {$I+}
          if ioresult <> 0 then
          begin
            write('Error De Entrada Numerica Repita Dato');
            fila := 0;
            writeln;
            end;
        until columna in [1..7];
 
        if (tablero[fila,columna] <> ' ') then
            WriteLn('Casilla ocupada!');
 
    until (tablero[fila,columna] = ' ');
 
    (* Si todo es correcto, se la asigno*)
    tablero[fila,columna] := simbolo[jugador];
   end;
 
   {Presentamos el tablero}
   procedure DibujarTablero;
   var
     columna : integer;
   begin
      clrscr;
     writeln;
     writeln('     **** Cuatro En Raya ****');
     writeln;
     for columna := 1 to 7 do
     begin
      writeln('        -----------------');
      writeln('        |',tablero[1,columna],'|',tablero[2,columna],'|',tablero[3,columna],'|',
      tablero[4,columna],'|',tablero[5,columna],'|',tablero[6,columna],'|',tablero[7,columna],'|',
      tablero[8,columna],'|');
      end;
      writeln('        -----------------');
      writeln;
   end;
 
   {Esto para recorrer la matriz y verificar el 4 en raya
    en todos las posiciones posibles}
 
   function enlinea(juga : char) : boolean;
   var
     eslinea : boolean;
     cont, linea, colum : integer;
   begin
       eslinea := false;
       cont := 0;
       colum := 1;
 
    {lineas}
     if eslinea = false then
     begin
    repeat
       for linea := 1 to 7 do
       begin
          if tablero[linea,colum] = juga then
          begin
             cont := cont + 1;
             if cont = 4 then
             eslinea := true;
          end
       else
          begin
             cont := 0;
          end;
       end;
        colum := colum + 1;
     until colum > 7;
   end;
 
   {columnas}
   if eslinea = false then
     begin
        linea := 1;
    repeat
       for colum := 1 to 6 do
       begin
          if tablero[linea,colum] = juga then
          begin
             cont := cont + 1;
             if cont = 4 then
             eslinea := true;
          end
       else
          begin
             cont := 0;
          end;
       end;
        linea := linea + 1;
     until linea > 8;
   end;
   {Diagonales izquierdas \ son 8}
   {diagonal 1}
   if eslinea = false then
   begin
      colum := 1;
      for linea := 1 to 7 do
      begin
         if tablero[linea,colum] = juga then
         begin
            cont := cont + 1;
            if cont = 4 then
            eslinea := true;
         end
      else
         cont := 0;
         colum := colum + 1;
      end;
   end;
    {diagonal 2}
    if eslinea = false then
    begin
       colum := 2;
       for linea := 1 to 6 do
       begin
          if tablero[linea,colum] = juga then
          begin
            cont := cont + 1;
            if cont = 4 then
            eslinea := true;
          end
       else
          cont := 0;
          colum := colum + 1;
       end;
    end;
 
   {Diagonal 3}
   if eslinea = false then
    begin
       colum := 3;
       for linea := 1 to 5 do
       begin
          if tablero[linea,colum] = juga then
          begin
            cont := cont + 1;
            if cont = 4 then
            eslinea := true;
          end
       else
          cont := 0;
          colum := colum + 1;
       end;
    end;
   {Diagonal 4}
     if eslinea = false then
    begin
       colum := 4;
       for linea := 1 to 4 do
       begin
          if tablero[linea,colum] = juga then
          begin
            cont := cont + 1;
            if cont = 4 then
            eslinea := true;
          end
       else
          cont := 0;
          colum := colum + 1;
       end;
    end;
 
   {diagonal 5}
    if eslinea = false then
    begin
        colum := 1;
        for linea := 2 to 8 do
        begin
           if tablero[linea,colum] = juga then
           begin
             cont := cont + 1;
             if cont = 4 then
             eslinea := true;
           end
        else
           cont := 0;
           colum := colum + 1;
        end;
    end;
 
  {diagonal 6}
    if eslinea = false then
    begin
        colum := 1;
        for linea := 3 to 8 do
        begin
           if tablero[linea,colum] = juga then
           begin
             cont := cont + 1;
             if cont = 4 then
             eslinea := true;
           end
        else
           cont := 0;
           colum := colum + 1;
        end;
    end;
 
    {diagonal 7}
    if eslinea = false then
    begin
        colum := 1;
        for linea := 4 to 8 do
        begin
           if tablero[linea,colum] = juga then
           begin
             cont := cont + 1;
             if cont = 4 then
             eslinea := true;
           end
        else
           cont := 0;
           colum := colum + 1;
        end;
    end;
 
   {diagonal 8}
    if eslinea = false then
    begin
        colum := 1;
        for linea := 5 to 8 do
        begin
           if tablero[linea,colum] = juga then
           begin
             cont := cont + 1;
             if cont = 4 then
             eslinea := true;
           end
        else
           cont := 0;
           colum := colum + 1;
        end;
    end;
 
   {Diagonales Derechas / son 8}
   {Diagonal 1}
   if eslinea = false then
   begin
       linea := 8;
      for colum := 1 to 7 do
      begin
         if tablero[linea,colum] = juga then
         begin
           cont := cont + 1;
           if cont = 4 then
           eslinea := true;
         end
      else
         cont := 0;
         linea := linea - 1;
      end;
   end;
 
   {Diagonal 2}
   if eslinea = false then
   begin
       linea := 7;
      for colum := 1 to 7 do
      begin
         if tablero[linea,colum] = juga then
         begin
           cont := cont + 1;
           if cont = 4 then
           eslinea := true;
         end
      else
         cont := 0;
         linea := linea - 1;
      end;
   end;
 
   {Diagonal 3}
   if eslinea = false then
   begin
       linea := 6;
      for colum := 1 to 6 do
      begin
         if tablero[linea,colum] = juga then
         begin
           cont := cont + 1;
           if cont = 4 then
           eslinea := true;
         end
      else
         cont := 0;
         linea := linea - 1;
      end;
   end;
 
   {Diagonal 4}
   if eslinea = false then
   begin
       linea := 5;
      for colum := 1 to 5 do
      begin
         if tablero[linea,colum] = juga then
         begin
           cont := cont + 1;
           if cont = 4 then
           eslinea := true;
         end
      else
         cont := 0;
         linea := linea - 1;
      end;
   end;
 
   {Diagonal 5}
   if eslinea = false then
   begin
       linea := 4;
      for colum := 1 to 4 do
      begin
         if tablero[linea,colum] = juga then
         begin
           cont := cont + 1;
           if cont = 4 then
           eslinea := true;
         end
      else
         cont := 0;
         linea := linea - 1;
      end;
   end;
   {Diagonal 6}
   if eslinea = false then
   begin
      colum := 2;
      for linea := 8 downto 3 do
      begin
          if tablero[linea,colum] = juga then
          begin
            cont := cont + 1;
            if cont = 4 then
            eslinea := true;
          end
      else
          cont := 0;
          colum := colum + 1;
      end;
   end;
 
   {Diagonal 7}
   if eslinea = false then
   begin
      colum := 3;
      for linea := 8 downto 4 do
      begin
          if tablero[linea,colum] = juga then
          begin
            cont := cont + 1;
            if cont = 4 then
            eslinea := true;
          end
      else
          cont := 0;
          colum := colum + 1;
      end;
   end;
 
   {Diagonal 8}
   if eslinea = false then
   begin
      colum := 4;
      for linea := 8 downto 5 do
      begin
          if tablero[linea,colum] = juga then
          begin
            cont := cont + 1;
            if cont = 4 then
            eslinea := true;
          end
      else
          cont := 0;
          colum := colum + 1;
      end;
   end;
      enlinea := eslinea;
   end;
 
 
 
    begin
        terminado := false;
        fillchar(tablero,sizeof(tablero),' ');
        (* Dibujar el tablero inicial*)
        DibujarTablero;
             sal := 'N';
        repeat
            (* Pedir al jugador 1*)
           if enlinea(simbolo[2]) = false then
           begin
            PreguntarPosicion(1);
            (* Dibujar la casilla del jugador 1*)
            DibujarTablero;
            end;
            if enlinea(simbolo[1]) = false then
            begin
            (* Pedir al jugador 2*)
            PreguntarPosicion(2);
            (* Dibujar la casilla del jugador 2*)
            DibujarTablero;
            end;
            if (enlinea(simbolo[2]) = false) and (enlinea(simbolo[1]) = false) then
            begin
               writeln('   Se Queda En Tablas [S/N]');
             repeat
               sal := upcase(readkey);
             until sal in['S','N'];
            end;
        until (sal = 'S') or ((enlinea(simbolo[2]) = true) or (enlinea(simbolo[1]) = true));
        if enlinea(simbolo[2]) = true then
        begin
            writeln;
            writeln('   Partida Completada Por Jugador = ',simbolo[2]);
        end;
        if enlinea(simbolo[1]) = true then
        begin
            writeln;
            writeln('   Partida Completada Por Jugador = ',simbolo[1]);
        end;
        if sal = 'S' then
        begin
          writeln;
          writeln('  Juego En Tablas ');
        end;
           writeln('  Pulse Una Tecla');
           writeln;
           readkey;
 
        {repeat
            (* Pedir al jugador 1*)
            PreguntarPosicion( 1 );
            (* Dibujar la casilla del jugador 1*)
            DibujarTablero;
            (* Comprobar si ha terminado la partida*)
            terminado := ComprobarGanador;
            if terminado then
                WriteLn('Gana jugador 1')
            else
                begin
                    terminado := ComprobarEmpate;
                    if terminado then
                        WriteLn('Empate!')
                    else
                    begin
                        (* Pedir al jugador 2*)
                        PreguntarPosicion( 2 );
                        (* Dibujar la casilla del jugador 2*)
                        DibujarTablero;
                        (* Comprobar si ha terminado la partida*)
                        terminado := ComprobarGanador;
                        if terminado then
                            WriteLn('Gana jugador 2');
                    end
            end
        (* Repetir hasta 4 en raya o empate (tablero lleno)*)
        until terminado;
    end; }
 
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar