Thema: Sudoku

Einzelnen Beitrag anzeigen

Poempel

Registriert seit: 10. Jan 2006
Ort: Erftstadt
8 Beiträge
 
Delphi 7 Enterprise
 
#16

Re: Sudoku

  Alt 12. Jan 2006, 14:06
Delphi-Quellcode:

unit msudoku;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids;

type
  summentyp = record
    spalte, zeile, quadrant : byte;
  end;
  feldtyp = record
    data : array[1..9] of array[1..9] of byte;
  end;
  punkttyp = record
    x,y : byte;
  end;
  mengentyp = record
    data : array[1..9] of array[1..9] of array[1..9] of boolean;
  end;
  ausgabetyp = record
    summen : array[1..9] of summentyp;
    data : array[1..9] of array[1..9] of byte;
  end;
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit11: TEdit;
    Edit12: TEdit;
    Edit13: TEdit;
    Edit14: TEdit;
    Edit15: TEdit;
    Edit16: TEdit;
    Edit17: TEdit;
    Edit18: TEdit;
    Edit19: TEdit;
    Edit21: TEdit;
    Edit22: TEdit;
    Edit23: TEdit;
    Edit24: TEdit;
    Edit25: TEdit;
    Edit26: TEdit;
    Edit27: TEdit;
    Edit28: TEdit;
    Edit29: TEdit;
    Edit31: TEdit;
    Edit32: TEdit;
    Edit33: TEdit;
    Edit34: TEdit;
    Edit35: TEdit;
    Edit36: TEdit;
    Edit37: TEdit;
    Edit38: TEdit;
    Edit39: TEdit;
    Edit41: TEdit;
    Edit42: TEdit;
    Edit43: TEdit;
    Edit44: TEdit;
    Edit45: TEdit;
    Edit46: TEdit;
    Edit47: TEdit;
    Edit48: TEdit;
    Edit49: TEdit;
    Edit51: TEdit;
    Edit52: TEdit;
    Edit53: TEdit;
    Edit54: TEdit;
    Edit55: TEdit;
    Edit56: TEdit;
    Edit57: TEdit;
    Edit58: TEdit;
    Edit59: TEdit;
    Edit61: TEdit;
    Edit62: TEdit;
    Edit63: TEdit;
    Edit64: TEdit;
    Edit65: TEdit;
    Edit66: TEdit;
    Edit67: TEdit;
    Edit68: TEdit;
    Edit69: TEdit;
    Edit71: TEdit;
    Edit72: TEdit;
    Edit73: TEdit;
    Edit74: TEdit;
    Edit75: TEdit;
    Edit76: TEdit;
    Edit77: TEdit;
    Edit78: TEdit;
    Edit79: TEdit;
    Edit81: TEdit;
    Edit82: TEdit;
    Edit83: TEdit;
    Edit84: TEdit;
    Edit85: TEdit;
    Edit86: TEdit;
    Edit87: TEdit;
    Edit88: TEdit;
    Edit89: TEdit;
    Button1: TButton;
    Edit10: TEdit;
    Edit20: TEdit;
    Edit30: TEdit;
    Edit40: TEdit;
    Edit50: TEdit;
    Edit60: TEdit;
    Edit70: TEdit;
    Edit80: TEdit;
    Edit90: TEdit;
    Edit91: TEdit;
    Edit92: TEdit;
    Edit93: TEdit;
    Edit94: TEdit;
    Edit95: TEdit;
    Edit96: TEdit;
    Edit97: TEdit;
    Edit98: TEdit;
    Edit99: TEdit;
    Edit100: TEdit;
    Edit101: TEdit;
    Edit102: TEdit;
    Edit103: TEdit;
    Edit104: TEdit;
    Edit105: TEdit;
    Edit106: TEdit;
    Edit107: TEdit;
    Edit108: TEdit;
    procedure Button1Click(Sender: TObject);
    function loaddata: feldtyp;
    procedure savedata(tempfeld: ausgabetyp);
    function testmengen(tempfeld: feldtyp):mengentyp;
    function SucheLoesung(feld: feldtyp):feldtyp;
    function SucheMinimum(feld: feldtyp):punkttyp;
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.loaddata: feldtyp;
var tempfeld: feldtyp;
begin
  try
    tempfeld.data[1,1] := strtoint(edit1.Text);
    tempfeld.data[1,2] := strtoint(edit2.Text);
    tempfeld.data[1,3] := strtoint(edit3.Text);
    tempfeld.data[1,4] := strtoint(edit4.Text);
    tempfeld.data[1,5] := strtoint(edit5.Text);
    tempfeld.data[1,6] := strtoint(edit6.Text);
    tempfeld.data[1,7] := strtoint(edit7.Text);
    tempfeld.data[1,8] := strtoint(edit8.Text);
    tempfeld.data[1,9] := strtoint(edit9.Text);

    tempfeld.data[2,1] := strtoint(edit11.Text);
    tempfeld.data[2,2] := strtoint(edit12.Text);
    tempfeld.data[2,3] := strtoint(edit13.Text);
    tempfeld.data[2,4] := strtoint(edit14.Text);
    tempfeld.data[2,5] := strtoint(edit15.Text);
    tempfeld.data[2,6] := strtoint(edit16.Text);
    tempfeld.data[2,7] := strtoint(edit17.Text);
    tempfeld.data[2,8] := strtoint(edit18.Text);
    tempfeld.data[2,9] := strtoint(edit19.Text);

    tempfeld.data[3,1] := strtoint(edit21.Text);
    tempfeld.data[3,2] := strtoint(edit22.Text);
    tempfeld.data[3,3] := strtoint(edit23.Text);
    tempfeld.data[3,4] := strtoint(edit24.Text);
    tempfeld.data[3,5] := strtoint(edit25.Text);
    tempfeld.data[3,6] := strtoint(edit26.Text);
    tempfeld.data[3,7] := strtoint(edit27.Text);
    tempfeld.data[3,8] := strtoint(edit28.Text);
    tempfeld.data[3,9] := strtoint(edit29.Text);

    tempfeld.data[4,1] := strtoint(edit31.Text);
    tempfeld.data[4,2] := strtoint(edit32.Text);
    tempfeld.data[4,3] := strtoint(edit33.Text);
    tempfeld.data[4,4] := strtoint(edit34.Text);
    tempfeld.data[4,5] := strtoint(edit35.Text);
    tempfeld.data[4,6] := strtoint(edit36.Text);
    tempfeld.data[4,7] := strtoint(edit37.Text);
    tempfeld.data[4,8] := strtoint(edit38.Text);
    tempfeld.data[4,9] := strtoint(edit39.Text);

    tempfeld.data[5,1] := strtoint(edit41.Text);
    tempfeld.data[5,2] := strtoint(edit42.Text);
    tempfeld.data[5,3] := strtoint(edit43.Text);
    tempfeld.data[5,4] := strtoint(edit44.Text);
    tempfeld.data[5,5] := strtoint(edit45.Text);
    tempfeld.data[5,6] := strtoint(edit46.Text);
    tempfeld.data[5,7] := strtoint(edit47.Text);
    tempfeld.data[5,8] := strtoint(edit48.Text);
    tempfeld.data[5,9] := strtoint(edit49.Text);

    tempfeld.data[6,1] := strtoint(edit51.Text);
    tempfeld.data[6,2] := strtoint(edit52.Text);
    tempfeld.data[6,3] := strtoint(edit53.Text);
    tempfeld.data[6,4] := strtoint(edit54.Text);
    tempfeld.data[6,5] := strtoint(edit55.Text);
    tempfeld.data[6,6] := strtoint(edit56.Text);
    tempfeld.data[6,7] := strtoint(edit57.Text);
    tempfeld.data[6,8] := strtoint(edit58.Text);
    tempfeld.data[6,9] := strtoint(edit59.Text);

    tempfeld.data[7,1] := strtoint(edit61.Text);
    tempfeld.data[7,2] := strtoint(edit62.Text);
    tempfeld.data[7,3] := strtoint(edit63.Text);
    tempfeld.data[7,4] := strtoint(edit64.Text);
    tempfeld.data[7,5] := strtoint(edit65.Text);
    tempfeld.data[7,6] := strtoint(edit66.Text);
    tempfeld.data[7,7] := strtoint(edit67.Text);
    tempfeld.data[7,8] := strtoint(edit68.Text);
    tempfeld.data[7,9] := strtoint(edit69.Text);

    tempfeld.data[8,1] := strtoint(edit71.Text);
    tempfeld.data[8,2] := strtoint(edit72.Text);
    tempfeld.data[8,3] := strtoint(edit73.Text);
    tempfeld.data[8,4] := strtoint(edit74.Text);
    tempfeld.data[8,5] := strtoint(edit75.Text);
    tempfeld.data[8,6] := strtoint(edit76.Text);
    tempfeld.data[8,7] := strtoint(edit77.Text);
    tempfeld.data[8,8] := strtoint(edit78.Text);
    tempfeld.data[8,9] := strtoint(edit79.Text);

    tempfeld.data[9,1] := strtoint(edit81.Text);
    tempfeld.data[9,2] := strtoint(edit82.Text);
    tempfeld.data[9,3] := strtoint(edit83.Text);
    tempfeld.data[9,4] := strtoint(edit84.Text);
    tempfeld.data[9,5] := strtoint(edit85.Text);
    tempfeld.data[9,6] := strtoint(edit86.Text);
    tempfeld.data[9,7] := strtoint(edit87.Text);
    tempfeld.data[9,8] := strtoint(edit88.Text);
    tempfeld.data[9,9] := strtoint(edit89.Text);
  except
    showmessage('fehlerhafte Eingabe');
  end;
  result := tempfeld;
end;

procedure TForm1.savedata(tempfeld: ausgabetyp);
begin
  edit1.Text := inttostr(tempfeld.data[1,1]);
  edit2.Text := inttostr(tempfeld.data[1,2]);
  edit3.Text := inttostr(tempfeld.data[1,3]);
  edit4.Text := inttostr(tempfeld.data[1,4]);
  edit5.Text := inttostr(tempfeld.data[1,5]);
  edit6.Text := inttostr(tempfeld.data[1,6]);
  edit7.Text := inttostr(tempfeld.data[1,7]);
  edit8.Text := inttostr(tempfeld.data[1,8]);
  edit9.Text := inttostr(tempfeld.data[1,9]);

  edit11.Text := inttostr(tempfeld.data[2,1]);
  edit12.Text := inttostr(tempfeld.data[2,2]);
  edit13.Text := inttostr(tempfeld.data[2,3]);
  edit14.Text := inttostr(tempfeld.data[2,4]);
  edit15.Text := inttostr(tempfeld.data[2,5]);
  edit16.Text := inttostr(tempfeld.data[2,6]);
  edit17.Text := inttostr(tempfeld.data[2,7]);
  edit18.Text := inttostr(tempfeld.data[2,8]);
  edit19.Text := inttostr(tempfeld.data[2,9]);

  edit21.Text := inttostr(tempfeld.data[3,1]);
  edit22.Text := inttostr(tempfeld.data[3,2]);
  edit23.Text := inttostr(tempfeld.data[3,3]);
  edit24.Text := inttostr(tempfeld.data[3,4]);
  edit25.Text := inttostr(tempfeld.data[3,5]);
  edit26.Text := inttostr(tempfeld.data[3,6]);
  edit27.Text := inttostr(tempfeld.data[3,7]);
  edit28.Text := inttostr(tempfeld.data[3,8]);
  edit29.Text := inttostr(tempfeld.data[3,9]);

  edit31.Text := inttostr(tempfeld.data[4,1]);
  edit32.Text := inttostr(tempfeld.data[4,2]);
  edit33.Text := inttostr(tempfeld.data[4,3]);
  edit34.Text := inttostr(tempfeld.data[4,4]);
  edit35.Text := inttostr(tempfeld.data[4,5]);
  edit36.Text := inttostr(tempfeld.data[4,6]);
  edit37.Text := inttostr(tempfeld.data[4,7]);
  edit38.Text := inttostr(tempfeld.data[4,8]);
  edit39.Text := inttostr(tempfeld.data[4,9]);

  edit41.Text := inttostr(tempfeld.data[5,1]);
  edit42.Text := inttostr(tempfeld.data[5,2]);
  edit43.Text := inttostr(tempfeld.data[5,3]);
  edit44.Text := inttostr(tempfeld.data[5,4]);
  edit45.Text := inttostr(tempfeld.data[5,5]);
  edit46.Text := inttostr(tempfeld.data[5,6]);
  edit47.Text := inttostr(tempfeld.data[5,7]);
  edit48.Text := inttostr(tempfeld.data[5,8]);
  edit49.Text := inttostr(tempfeld.data[5,9]);

  edit51.Text := inttostr(tempfeld.data[6,1]);
  edit52.Text := inttostr(tempfeld.data[6,2]);
  edit53.Text := inttostr(tempfeld.data[6,3]);
  edit54.Text := inttostr(tempfeld.data[6,4]);
  edit55.Text := inttostr(tempfeld.data[6,5]);
  edit56.Text := inttostr(tempfeld.data[6,6]);
  edit57.Text := inttostr(tempfeld.data[6,7]);
  edit58.Text := inttostr(tempfeld.data[6,8]);
  edit59.Text := inttostr(tempfeld.data[6,9]);

  edit61.Text := inttostr(tempfeld.data[7,1]);
  edit62.Text := inttostr(tempfeld.data[7,2]);
  edit63.Text := inttostr(tempfeld.data[7,3]);
  edit64.Text := inttostr(tempfeld.data[7,4]);
  edit65.Text := inttostr(tempfeld.data[7,5]);
  edit66.Text := inttostr(tempfeld.data[7,6]);
  edit67.Text := inttostr(tempfeld.data[7,7]);
  edit68.Text := inttostr(tempfeld.data[7,8]);
  edit69.Text := inttostr(tempfeld.data[7,9]);

  edit71.Text := inttostr(tempfeld.data[8,1]);
  edit72.Text := inttostr(tempfeld.data[8,2]);
  edit73.Text := inttostr(tempfeld.data[8,3]);
  edit74.Text := inttostr(tempfeld.data[8,4]);
  edit75.Text := inttostr(tempfeld.data[8,5]);
  edit76.Text := inttostr(tempfeld.data[8,6]);
  edit77.Text := inttostr(tempfeld.data[8,7]);
  edit78.Text := inttostr(tempfeld.data[8,8]);
  edit79.Text := inttostr(tempfeld.data[8,9]);

  edit81.Text := inttostr(tempfeld.data[9,1]);
  edit82.Text := inttostr(tempfeld.data[9,2]);
  edit83.Text := inttostr(tempfeld.data[9,3]);
  edit84.Text := inttostr(tempfeld.data[9,4]);
  edit85.Text := inttostr(tempfeld.data[9,5]);
  edit86.Text := inttostr(tempfeld.data[9,6]);
  edit87.Text := inttostr(tempfeld.data[9,7]);
  edit88.Text := inttostr(tempfeld.data[9,8]);
  edit89.Text := inttostr(tempfeld.data[9,9]);

  edit10.Text := inttostr(tempfeld.summen[1].zeile);
  edit20.Text := inttostr(tempfeld.summen[2].zeile);
  edit30.Text := inttostr(tempfeld.summen[3].zeile);
  edit40.Text := inttostr(tempfeld.summen[4].zeile);
  edit50.Text := inttostr(tempfeld.summen[5].zeile);
  edit60.Text := inttostr(tempfeld.summen[6].zeile);
  edit70.Text := inttostr(tempfeld.summen[7].zeile);
  edit80.Text := inttostr(tempfeld.summen[8].zeile);
  edit90.Text := inttostr(tempfeld.summen[9].zeile);

  edit91.Text := inttostr(tempfeld.summen[1].spalte);
  edit92.Text := inttostr(tempfeld.summen[2].spalte);
  edit93.Text := inttostr(tempfeld.summen[3].spalte);
  edit94.Text := inttostr(tempfeld.summen[4].spalte);
  edit95.Text := inttostr(tempfeld.summen[5].spalte);
  edit96.Text := inttostr(tempfeld.summen[6].spalte);
  edit97.Text := inttostr(tempfeld.summen[7].spalte);
  edit98.Text := inttostr(tempfeld.summen[8].spalte);
  edit99.Text := inttostr(tempfeld.summen[9].spalte);

  edit100.Text := inttostr(tempfeld.summen[1].quadrant);
  edit101.Text := inttostr(tempfeld.summen[2].quadrant);
  edit102.Text := inttostr(tempfeld.summen[3].quadrant);
  edit103.Text := inttostr(tempfeld.summen[4].quadrant);
  edit104.Text := inttostr(tempfeld.summen[5].quadrant);
  edit105.Text := inttostr(tempfeld.summen[6].quadrant);
  edit106.Text := inttostr(tempfeld.summen[7].quadrant);
  edit107.Text := inttostr(tempfeld.summen[8].quadrant);
  edit108.Text := inttostr(tempfeld.summen[9].quadrant);
end;

function TForm1.testmengen(tempfeld: feldtyp):mengentyp;
var i, c, i2, c2, tempbyte : byte;
  mengen : mengentyp;
  summen : summentyp;
begin
  for i := 1 to 9 do for c := 1 to 9 do for tempbyte := 1 to 9 do mengen.data[i,c,tempbyte] := true;
  for i := 1 to 9 do for c := 1 to 9 do
  begin
    if tempfeld.data[i,c] > 0 then
    begin
      for tempbyte := 1 to 9 do mengen.data[i,tempbyte,tempfeld.data[i,c]] := false;
      for tempbyte := 1 to 9 do mengen.data[tempbyte,c,tempfeld.data[i,c]] := false;
      if i in[1..3] then
      begin
        if c in[1..3] then for i2 := 1 to 3 do for c2 := 1 to 3 do mengen.data[i2,c2,tempfeld.data[i,c]] := false
        else if c in[4..6] then for i2 := 1 to 3 do for c2 := 4 to 6 do mengen.data[i2,c2,tempfeld.data[i,c]] := false
        else if c in[7..9] then for i2 := 1 to 3 do for c2 := 7 to 9 do mengen.data[i2,c2,tempfeld.data[i,c]] := false;
      end else if i in[4..6] then
      begin
        if c in[1..3] then for i2 := 4 to 6 do for c2 := 1 to 3 do mengen.data[i2,c2,tempfeld.data[i,c]] := false
        else if c in[4..6] then for i2 := 4 to 6 do for c2 := 4 to 6 do mengen.data[i2,c2,tempfeld.data[i,c]] := false
        else if c in[7..9] then for i2 := 4 to 6 do for c2 := 7 to 9 do mengen.data[i2,c2,tempfeld.data[i,c]] := false;
      end else if i in[7..9] then
      begin
        if c in[1..3] then for i2 := 7 to 9 do for c2 := 1 to 3 do mengen.data[i2,c2,tempfeld.data[i,c]] := false
        else if c in[4..6] then for i2 := 7 to 9 do for c2 := 4 to 6 do mengen.data[i2,c2,tempfeld.data[i,c]] := false
        else if c in[7..9] then for i2 := 7 to 9 do for c2 := 7 to 9 do mengen.data[i2,c2,tempfeld.data[i,c]] := false;
      end;
    end;
  end;
  for i := 1 to 9 do
  begin
    tempbyte := 0;
    for c := 1 to 9 do
    begin
      tempbyte := tempbyte + tempfeld.data[i,c];
    end;
    summen[i].zeile := tempbyte;
  end;
  for i := 1 to 9 do
  begin
    tempbyte := 0;
    for c := 1 to 9 do
    begin
      tempbyte := tempbyte + tempfeld.data[c,i];
    end;
    summen[i].spalte := tempbyte;
  end;
  tempbyte := 0;
  for c := 1 to 3 do
  begin
    for i := 1 to 3 do
    begin
      tempbyte := tempbyte + tempfeld.data[c,i];
    end;
  end;
  summen[1].quadrant := tempbyte;
  tempbyte := 0;
  for c := 1 to 3 do
  begin
    for i := 1 to 3 do
    begin
      tempbyte := tempbyte + tempfeld.data[c,i+3];
    end;
  end;
  summen[2].quadrant := tempbyte;
  tempbyte := 0;
  for c := 1 to 3 do
  begin
    for i := 1 to 3 do
    begin
      tempbyte := tempbyte + tempfeld.data[c,i+6];
    end;
  end;
  summen[3].quadrant := tempbyte;
  tempbyte := 0;
  for c := 1 to 3 do
  begin
    for i := 1 to 3 do
    begin
      tempbyte := tempbyte + tempfeld.data[c+3,i];
    end;
  end;
  summen[4].quadrant := tempbyte;
  tempbyte := 0;
  for c := 1 to 3 do
  begin
    for i := 1 to 3 do
    begin
      tempbyte := tempbyte + tempfeld.data[c+3,i+3];
    end;
  end;
  summen[5].quadrant := tempbyte;
  tempbyte := 0;
  for c := 1 to 3 do
  begin
    for i := 1 to 3 do
    begin
      tempbyte := tempbyte + tempfeld.data[c+3,i+6];
    end;
  end;
  summen[6].quadrant := tempbyte;
  tempbyte := 0;
  for c := 1 to 3 do
  begin
    for i := 1 to 3 do
    begin
      tempbyte := tempbyte + tempfeld.data[c+6,i];
    end;
  end;
  summen[7].quadrant := tempbyte;
  tempbyte := 0;
  for c := 1 to 3 do
  begin
    for i := 1 to 3 do
    begin
      tempbyte := tempbyte + tempfeld.data[c+6,i+3];
    end;
  end;
  summen[8].quadrant := tempbyte;
  tempbyte := 0;
  for c := 1 to 3 do
  begin
    for i := 1 to 3 do
    begin
      tempbyte := tempbyte + tempfeld.data[c+6,i+6];
    end;
  end;
  summen[9].quadrant := tempbyte;
end;

function SucheMinimum(feld: feldtyp):punkttyp;
var i, c : Byte;
begin
  for i := 1 to 9 do for c := 1 to 9 do
  begin
  end;
end;

function TForm1.SucheLoesung(feld: feldtyp):feldtyp;
var i, c : Byte;
begin
  testmengen;
  for i := 1 to 9 do for c := 1 to 9 do
  begin

  end;
  result := feld;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  loaddata;
  originalfeld := SucheLoesung(originalfeld);
  savedata;
end;

end.


Ok so?
Auch wenn ich es euch reinprügeln muss: Gewalt ist keine Lösung!
  Mit Zitat antworten Zitat