Pascal/Turbo Pascal - ayduaaaaaa con el juego de sudoku de 3x3

 
Vista:

ayduaaaaaa con el juego de sudoku de 3x3

Publicado por pedro (1 intervención) el 01/02/2016 03:10:22
buenas ando estudiando informatica me mandaron hacer un ejercicio es complicado ya que poco tiempo no se mucho del programa necesito ayuda turbo pascal

el juego es de sudoku de 3x3 la cual el profesor nos pide verificar las fila y columna luego mostrar esa matriz completa en pantalla depsues de esto el jugador va a jugar a traves utilizando con la finalidad que se vaya comparando con la matriz asi esta bien los numeros de la matriz b con la matriz b tendria que mostrar en panatlla la matriz a llena y la matriz b el numero correcto pintado .


no se mucho alguien que me ayude por favor lo necesito para esta semana
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

ayduaaaaaa con el juego de sudoku de 3x3

Publicado por ramon (2158 intervenciones) el 12/02/2016 13:24:47
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
{Mira esto}
 
 program asudoku3X3;
 uses
  crt, dos;
  const
     max = 3;
  type
     sudoku_reg = record
          matriz : array[1..3,1..3] of integer;
           guego :  array[1..3,1..3] of integer;
       end;
 
  var
     x, y, xx, yy : integer;
     tecla : char;
     regs : registers;
     raton : boolean;
     sudoku : sudoku_reg;
 
   function raton_presente : boolean;
   begin
      regs.ah := $00;
      regs.al := $00;
      intr($33,regs);
      if regs.ax <> 0 then
      raton_presente := true
    else
      raton_presente := false;
  end;
 
  procedure muestra_raton;
  begin
      raton := false;
      if raton_presente then
      begin
          regs.ah := $00;
          regs.al := $01;
          intr($33,regs);
          raton := true;
      end;
  end;
 
  procedure oculta_raton;
  begin
      if raton = true then
      begin
         regs.ah := $00;
         regs.al := $02;
         intr($33,regs);
         raton := false;
       end;
  end;
 
  function posx_raton : word;
  begin
      posx_raton := 0;
      regs.ah := $00;
      regs.al := $03;
      intr($33,regs);
      posx_raton := regs.cx div 8 + 1
  end;
 
  function posy_raton : word;
  begin
      posy_raton := 0;
      regs.ah := $00;
      regs.al := $03;
      intr($33,regs);
      posy_raton := regs.dx div 8 + 1
  end;
 
  function boton_raton : word;
  begin
      boton_raton := 0;
      regs.ah := $00;
      regs.al := $03;
      intr($33,regs);
      boton_raton := regs.bx
  end;
 
  procedure pon_posicion_raton(xp, yp : word);
  begin
      regs.ah := $00;
      regs.al := $04;
      regs.cx := xp div 8 + 1;
      regs.dx := yp div 8 + 1;
      intr($33,regs);
  end;
 
   procedure mascara(x1, y1 : integer);
   var
     i : integer;
   begin
   for x := 1 to 3 do
   begin
      gotoxy(x1 + (x * 3),y1);write('Ú');
      gotoxy(x1 + (x * 3),y1 + 2);write('À');
      for i := 1 to 1 do
      begin
      gotoxy(x1 + (x * 3 + i),y1);write('Ä');
      gotoxy(x1 + (x * 3 + i),y1 + 2);write('Ä');
      end;
      gotoxy(x1 + (x * 3),y1 + 1);write('³');
      gotoxy(x1 + ((x * 3) + 2),y1 + 1);write('³');
      gotoxy(x1 + ((x * 3) + 2),y1);write('¿');
      gotoxy(x1 + ((x * 3) + 2),y1 + 2);write('Ù');
   end;
 end;
 
   procedure tablero;
   begin
      gotoxy(23,8);write('Sudoku 3X3');
      mascara(20,10);
      mascara(20,13);
      mascara(20,16);
      textcolor(10);
      gotoxy(6,20);write('Use El Mouse Para Marcar Cuadro Y Boton IZQ');
      gotoxy(6,21);write('Y Pulse El Numero Que Desea Entrar ');
      gotoxy(6,22);write('Boton DER. Avandona Partida');
      textcolor(7);
   end;
 
   function existe_en_linea(col, n : integer) : boolean;
   var
     cc, linea : integer;
     exi : boolean;
   begin
       exi := false;
       cc := 1;
       for linea := 1 to max do
       begin
       if sudoku.matriz[col,linea] = n then
       cc := cc + 1;
       end;
         if cc > 1 then
         exi := true;
         existe_en_linea := exi;
   end;
 
   function exisre_en_columna(li, n : integer) : boolean;
   var
     cc1, col : integer;
     exi : boolean;
    begin
       exi := false;
       cc1 := 1;
       for col := 1 to max do
       begin
          if sudoku.matriz[col,li] = n then
          cc1 := cc1 + 1;
       end;
         if cc1 > 1 then
         exi := true;
         exisre_en_columna := exi;
    end;
 
    procedure ponguego;
    var
      ff, px, py, m1, m2 : integer;
    begin
    for ff := 1 to 3 do
    begin
        m1 := random(8) + 1;
     case m1 of
  1,4,7 : px := 1;
  2,5,8 : px := 2;
  3,6,9 : px := 3;
     end;
       m2 := random(8) + 1;
     case m2 of
  1,4,7 : py := 1;
  2,5,8 : py := 2;
  3,6,9 : py := 3;
     end;
        sudoku.guego[px,py] := sudoku.matriz[px,py];
    end;
  end;
 
  procedure muestraguego;
  var
    c, toma, bx, by, enx, eny : integer;
    linea1 : array[1..max] of integer;
    sa1, sa : boolean;
  begin
     toma := 0;
     ponguego;
     for y := 1 to 3 do
     begin
      for x := 1 to 3 do
      begin
      if sudoku.guego[x,y] > 0 then
      begin
      textcolor(7);
      gotoxy(21 + (x * 3),8 + (y * 3));write(sudoku.guego[x,y]);
      toma := toma + 1;
      end;
     end;
    end;
      gotoxy(1,1);
      if raton_presente then
      begin
         muestra_raton;
         xx := posx_raton;
         yy := posy_raton;
       repeat
          if (xx <> posx_raton) or (yy <> posy_raton) then
          begin
             xx := posx_raton;
             yy := posy_raton;
          end;
          if boton_raton = 1 then
          begin
           bx := xx;
           by := yy;
           oculta_raton;
           if (bx in[24,27,30]) and (by in[11,14,17]) then
           begin
       case bx of
    24 : case by of
       11 : begin enx := 1; eny := 1; end;
       14 : begin enx := 1; eny := 2; end;
       17 : begin enx := 1; eny := 3; end;
         end;
    27 : case by of
       11 : begin enx := 2; eny := 1; end;
       14 : begin enx := 2; eny := 2; end;
       17 : begin enx := 2; eny := 3; end;
         end;
    30 : case by of
       11 : begin enx := 3; eny := 1; end;
       14 : begin enx := 3; eny := 2; end;
       17 : begin enx := 3; eny := 3; end;
         end;
       end;
           if sudoku.guego[enx,eny] = 0 then
           begin
           textcolor(12);
           gotoxy(10,24);write('Pulse Numero');
           textcolor(7);
           repeat
              tecla := readkey;
           until tecla in['1','2','3'];
           gotoxy(10,24);clreol;
           textcolor(10);
           gotoxy(bx,by);write(tecla);
           sudoku.guego[enx,eny] := ord(tecla) - 48;
           toma := toma + 1;
           textcolor(7);
           end
        else
           begin
             textcolor(5);
             gotoxy(10,24);write('   Casilla Ocupada Pulse Una Tecla');
             readkey;
             textcolor(7);
             gotoxy(10,24);clreol;
           end;
           gotoxy(1,1);
           pon_posicion_raton(bx,by);
           muestra_raton;
           end
      else
         begin
           gotoxy(10,24);write('Posicion Erronea Pulse Una Tecla');
           readkey;
           gotoxy(10,24);clreol;
           gotoxy(1,1);
           pon_posicion_raton(bx,by);
           muestra_raton;
         end;
       end;
       until (boton_raton = 2) or (toma = (max * max));
       oculta_raton;
       c := 1;
       sa := false;
       fillchar(linea1,sizeof(linea1),0);
       for enx := 1 to max do
       begin
         for eny := 1 to max do
         begin
            linea1[c] := linea1[c] + sudoku.guego[eny,enx];
         end;
         if linea1[c] = 6 then
         begin
            c := c + 1;
         end
      else
         begin
            sa := true;
            break;
         end;
       end;
       if sa = false then
       begin
       fillchar(linea1,sizeof(linea1),0);
       c := 1;
       sa1 := false;
       for eny := 1 to max do
       begin
         for enx := 1 to max do
         begin
            linea1[c] := linea1[c] + sudoku.guego[eny,enx];
         end;
         if linea1[c] = 6 then
         begin
            c := c + 1;
         end
      else
         begin
            sa1 := true;
            break;
         end;
       end;
     end;
       if (sa1 = false) and (sa = false) then
       begin
       clrscr;
       writeln;
       writeln('   **** Sudoku Conseguido ****');
       writeln;
       writeln('   Pulse Una Tecla');
       readkey;
       end
     else
        begin
       clrscr;
       writeln;
       writeln('   **** Sudoku Incompleto ****');
       writeln;
       writeln('   Pulse Una Tecla');
       readkey;
        end;
      end
   else
      begin
         clrscr;
         writeln('   Se Necesita Mouse [Pulse Una Tecla]');
         readkey;
      end;
   end;
 
   procedure crea_sudoku(var s : sudoku_reg);
   var
     en, pp, num : integer;
     px, py : integer;
     si : boolean;
   begin
      px := 1;
      py := 1;
      pp := 0;
      fillchar(s,sizeof(s),0);
    repeat
       en := random(8) + 1;
     case en of
  1,9,7 : num := 1;
  2,5,8 : num := 2;
  3,6,4 : num := 3;
     end;
       if (existe_en_linea(px,num) = false) and
          (exisre_en_columna(py,num) = false) then
       begin
       s.matriz[px,py] := num;
       py := py + 1;
       end;
       if py > max then
       begin
          px := px + 1;
          py := 1;
       end;
       pp := pp + 1;
      until (px > max) or (pp > 600);
      if pp > 600 then
      crea_sudoku(sudoku);
   end;
 
 
   begin
      clrscr;
      randomize;
      tablero;
      crea_sudoku(sudoku);
      muestraguego;
   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