summaryrefslogtreecommitdiff
path: root/raetselunit.pas
diff options
context:
space:
mode:
Diffstat (limited to 'raetselunit.pas')
-rw-r--r--raetselunit.pas73
1 files changed, 63 insertions, 10 deletions
diff --git a/raetselunit.pas b/raetselunit.pas
index 2d60340..dc6741c 100644
--- a/raetselunit.pas
+++ b/raetselunit.pas
@@ -19,6 +19,7 @@ type
_perm: tLongintArray;
_mgl: tInt64Array;
_posi: longint;
+ _fr: tFelderRaetsel;
public
constructor create(ib: boolean; fr: tFelderRaetsel);
destructor destroy;
@@ -26,8 +27,8 @@ type
function fwd: boolean;
procedure rev;
property inhaltBehalten: boolean read _inh;
- procedure aktualisiereInhalt(p: longint);
- procedure aktualisiereRand(p: longint);
+ procedure aktualisiereInhalt(p,alt: longint);
+ procedure aktualisiereRand(p,alt: longint);
end;
tRaetsel = class
@@ -47,6 +48,7 @@ type
public
constructor create(aOwner: tForm);
destructor destroy; override;
+ function gleichzeitigMoeglich(num: longint): longint; dynamic; abstract;
function _loesen(lm: tFelderLoesMeta): longint; dynamic; abstract;
procedure zeichnen; dynamic; abstract;
end;
@@ -93,6 +95,7 @@ var
i: longint;
begin
inherited create;
+ _fr:=fr;
_inh:=ib;
_perm:=permutation(length(fr.inhalt));
setlength(_perm,length(_perm)+1);
@@ -127,14 +130,64 @@ begin
dec(_posi);
end;
-procedure tFelderLoesMeta.aktualisiereInhalt(p: longint);
+procedure tFelderLoesMeta.aktualisiereInhalt(p,alt: longint);
+var
+ i,j,x,y,cnt,neu: longint;
+ maske: int64;
begin
-
+ // hier sollte die Zeile und Spalte von _mgl[p] aktualisiert werden
+ x:=p mod _fr.dim;
+ y:=p div _fr.dim;
+ neu:=_fr.inhalt[p];
+ if neu<>-1 then begin
+ if alt<>-1 then begin
+ _fr.inhalt[p]:=-1;
+ aktualisiereInhalt(p,alt);
+ _fr.inhalt[p]:=neu;
+ alt:=-1;
+ end;
+ cnt:=_fr.gleichzeitigMoeglich(p);
+ maske:=1 shr _fr.inhalt[p];
+ _mgl[p]:=maske;
+ if cnt>1 then begin
+ j:=0;
+ for i:=0 to _fr.dim-1 do
+ j:=j+byte(_fr.inhalt[y*_fr.dim+i]=neu);
+ if j>=cnt then
+ for i:=0 to _fr.dim-2 do
+ _mgl[i*_fr.dim+i+byte(i>=x)]:=_mgl[i*_fr.dim+i+byte(i>=x)] and not maske;
+ j:=0;
+ for i:=0 to _fr.dim-1 do
+ j:=j+byte(_fr.inhalt[i*_fr.dim+x]=neu);
+ if j>=cnt then
+ for i:=0 to _fr.dim-2 do
+ _mgl[(i+byte(i>=y))*_fr.dim+x]:=_mgl[(i+byte(i>=y))*_fr.dim+x] and not maske;
+ // TODO: Diagonalen
+ end
+ else begin
+ for i:=0 to _fr.dim-2 do begin
+ _mgl[y*_fr.dim+i+byte(i>=x)]:=_mgl[y*_fr.dim+i+byte(i>=x)] and not maske;
+ _mgl[(i+byte(i>=y))*_fr.dim+x]:=_mgl[(i+byte(i>=y))*_fr.dim+x] and not maske;
+ end;
+ // TODO: Diagonalen
+ end;
+ end
+ else begin
+ if alt=-1 then
+ exit;
+ maske:=1 shr alt;
+ for i:=0 to _fr.dim-2 do begin
+ _mgl[(i+byte(i>=y))*_fr.dim+x]:=_mgl[(i+byte(i>=y))*_fr.dim+x] or maske;
+ _mgl[y*_fr.dim+x+byte(i>=x)]:=_mgl[y*_fr.dim+x+byte(i>=x)] or maske;
+ end;
+ // TODO: Diagonalen
+ // TODO: _mgl[p]
+ end;
end;
-procedure tFelderLoesMeta.aktualisiereRand(p: longint);
+procedure tFelderLoesMeta.aktualisiereRand(p,alt: longint);
begin
-
+ // hier sollte die Zeile bzw. Spalte von _rand[p] aktualisiert werden
end;
// tRaetsel ********************************************************************
@@ -345,10 +398,10 @@ begin
if inhalt[p[i]]<0 then continue;
w:=inhalt[p[i]];
inhalt[p[i]]:=-1;
- lm.aktualisiereInhalt(p[i]);
+ lm.aktualisiereInhalt(p[i],w);
if _loesen(lm)<>1 then begin
inhalt[p[i]]:=w;
- lm.aktualisiereInhalt(p[i]);
+ lm.aktualisiereInhalt(p[i],-1);
end;
end;
@@ -357,10 +410,10 @@ begin
if rand[p[i]]<0 then continue;
w:=rand[p[i]];
rand[p[i]]:=-1;
- lm.aktualisiereRand(p[i]);
+ lm.aktualisiereRand(p[i],w);
if _loesen(lm)<>1 then begin
rand[p[i]]:=w;
- lm.aktualisiereRand(p[i]);
+ lm.aktualisiereRand(p[i],-1);
end;
end;
lm.free;