From 5679bdc49a7b70bf2d404ce51e9ca287e37eae02 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Sun, 10 May 2020 14:52:30 +0200 Subject: Leeren optimiert --- raetsel.lps | 99 ++++++++++++++++++++++++++++----------------------------- raetselunit.inc | 20 ++++++++++++ raetselunit.pas | 44 ++++++++++++++++++++++--- 3 files changed, 107 insertions(+), 56 deletions(-) diff --git a/raetsel.lps b/raetsel.lps index 44c4c43..24d557b 100644 --- a/raetsel.lps +++ b/raetsel.lps @@ -9,7 +9,7 @@ - + @@ -19,7 +19,7 @@ - + @@ -32,25 +32,24 @@ - + - - - + + + - - - + + @@ -113,7 +112,7 @@ - + @@ -128,7 +127,7 @@ - + @@ -152,7 +151,7 @@ - + @@ -162,123 +161,121 @@ - + - + - + - + - + - - + - + - + - - + + - + - + - - + + - - + - - + + - + - + - + - + - - + + - - + + - + - + - + - + - + - + - - + + - - + + - - + + diff --git a/raetselunit.inc b/raetselunit.inc index 025d68a..6f9dbcf 100644 --- a/raetselunit.inc +++ b/raetselunit.inc @@ -9,6 +9,7 @@ type {$ENDIF} private procedure relativeInhaltsAenderung(diff: longint); override; + function naechsterWert(pos: longint): boolean; override; function absoluteInhaltsAenderung(key: word): boolean; override; function passtZumZeichnen(spalte,zeile: integer): boolean; override; function passt(spalte,zeile: integer): boolean; override; @@ -682,6 +683,25 @@ begin end; {$ENDIF} +{$IFDEF naechsterWert} +// function tBuchstabenRaetsel.naechsterWert(pos: longint): boolean; +begin + result:=false; + if (pos<0) or (pos>=dim*dim) then + exit; + inhalt[pos]:=inhalt[pos]+1; + {$IFDEF hochhaus} + if inhalt[pos]=0 then + inhalt[pos]:=1; + {$ENDIF} + if inhalt[pos]>groeszen[0] then begin + inhalt[pos]:=groeszen[0]; + exit; + end; + result:=true; +end; +{$ENDIF} + {$IFDEF absoluteInhaltsAenderung} // function tHochhausRaetsel.absoluteInhaltsAenderung(key: word): boolean; begin diff --git a/raetselunit.pas b/raetselunit.pas index 34bfef6..4ea8d77 100644 --- a/raetselunit.pas +++ b/raetselunit.pas @@ -104,6 +104,7 @@ type function besitzerBreite: longint; override; procedure schreibeZentriert(x,y,i: longint); procedure relativeInhaltsAenderung(diff: longint); dynamic; abstract; + function naechsterWert(pos: longint): boolean; dynamic; abstract; function absoluteInhaltsAenderung(key: word): boolean; dynamic; abstract; procedure gesamtRaenderErzeugen; dynamic; abstract; procedure startFelderFestlegen; override; @@ -612,8 +613,9 @@ end; procedure tFelderRaetsel.leeren; var - p: tLongintArray; - i,w: longint; + p: tLongintArray; + i,w: longint; + funktioniert: boolean; begin p:=permutation(dim*dim); progressBar1.step:=1; @@ -628,7 +630,17 @@ begin continue; w:=inhalt[p[i]]; inhalt[p[i]]:=-1; - if anzLoesungen(-1)<>1 then + funktioniert:=true; + while funktioniert and naechsterWert(p[i]) do begin + if inhalt[p[i]]=w then + continue; + if passt(p[i] mod dim,p[i] div dim) and (anzLoesungen(-1)>0) then + funktioniert:=false; + end; + writeln; + if funktioniert then + inhalt[p[i]]:=-1 + else inhalt[p[i]]:=w; end; @@ -638,8 +650,19 @@ begin application.processMessages; if rand[p[i]]<0 then continue; w:=rand[p[i]]; - rand[p[i]]:=-1; - if anzLoesungen(-1)<>1 then + rand[p[i]]:=0; + funktioniert:=true; + while funktioniert and (rand[p[i]]0 then + funktioniert:=false; + end; + writeln; + if funktioniert then + rand[p[i]]:=-1 + else rand[p[i]]:=w; end; progressBar1.visible:=false; @@ -1058,6 +1081,17 @@ procedure tBuchstabenRaetsel.relativeInhaltsAenderung(diff: integer); {$UNDEF buchstaben} {$UNDEF relativeInhaltsAenderung} +{$DEFINE naechsterWert} +function tHochhausRaetsel.naechsterWert(pos: longint): boolean; +{$DEFINE hochhaus} +{$I raetselunit.inc} +{$UNDEF hochhaus} +function tBuchstabenRaetsel.naechsterWert(pos: longint): boolean; +{$DEFINE buchstaben} +{$I raetselunit.inc} +{$UNDEF buchstaben} +{$UNDEF naechsterWert} + {$DEFINE absoluteInhaltsAenderung} function tHochhausRaetsel.absoluteInhaltsAenderung(key: word): boolean; {$DEFINE hochhaus} -- cgit v1.2.3-54-g00ecf