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:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, ActnList, CheckLst, ComCtrls;
type TForm1 = class(TForm) Button1: TButton; ProgressBar1: TProgressBar; Edit1: TEdit; Memo1: TMemo; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction);
private loesung: string; brett: array [1..5, 1..5] of tshape; beschr_x, beschr_y:array[1..5] of tlabel; springer : array[1..5, 1..5] of tshape; erfolg : boolean; procedure sprung(vonx,vony,richtung: integer; var nachx,nachy: integer); procedure machzug(zgnr: integer; vonx, vony: integer);
public end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); var i,j : integer; begin memo1.clear; for i:=1 to 5 do for j:=1 to 5 do begin brett [i,j]:=tshape.create(form1); with brett[i,j] do begin parent:= form1; width:=50; height:=50; left:=30+50*(i+1); top:=10+50*(j+2); if not odd(i+j) then brush.Color:=clwhite else brush.Color:=clblack end; springer[i,j]:=tshape.create(form1); with springer[i,j] do begin parent:=form1; shape:=stCircle; brush.Color:=clred; width:=15; height:=15; top:=27+50*(j+2); left:=47+50*(i+1); end; end;
for i:=1 to 5 do begin beschr_x[i]:=tlabel.create(form1); with beschr_x[i] do begin parent:=form1; left:= 50*(i+2); top:=420; caption:= chr(ord('A')+i-1); end; end; for j:=1 to 5 do begin beschr_y[j]:=tlabel.create(form1); with beschr_y[j] do begin parent:=form1; left:= 110; top:=430-50*j; caption:= inttostr(j); end; end; end;
procedure TForm1.sprung(vonx,vony,richtung:integer; var nachx,nachy: integer); begin case richtung of 1: begin nachx:=vonx+1; nachy:=vony-2; end; 2: begin nachx:=vonx+2; nachy:=vony-1; end; 3: begin nachx:=vonx+2; nachy:=vony+1; end; 4: begin nachx:=vonx+1; nachy:=vony+1; end; 5: begin nachx:=vonx-1; nachy:=vony+2; end; 6: begin nachx:=vonx-2; nachy:=vony+1; end; 7: begin nachx:=vonx-2; nachy:=vony-1; end; 8: begin nachx:=vonx-1; nachy:=vony-2; end; end; end;
procedure TForm1.machzug(zgnr, vonx, vony : integer); var richtung, nachx, nachy : integer; begin richtung:=1; repeat Progressbar1.Position:=zgnr; Application.ProcessMessages; sprung(vonx,vony,richtung,nachx,nachy);
if (nachx>0) and (nachx<6) and (nachy>0) and (nachy<6) then
if springer[nachx,nachy].Visible=true then begin
springer[nachx,nachy].Visible:=false;
if zgnr=24 then begin erfolg:=true; memo1.lines.add (loesung); end else begin
machzug(zgnr+1,nachx,nachy);
end; if not erfolg then begin
springer[nachx,nachy].Visible:=true; loesung:=loesung+ chr(ord('A')+nachx-1)+chr(ord('1')+nachy-1);
end end;
inc(richtung); until erfolg or (richtung=8);
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin erfolg:=true; end;
procedure TForm1.Button1Click(Sender: TObject); begin form1.springer[1,1].Visible:=false; erfolg:=false; Edit1.Text:='Suche läuft...'; Edit1.refresh; machzug(1,1,1); if erfolg then Edit1.Text:=' Lösung gefunden!'
end;
end. |