% Remember to use the lgrind style

\Head{}
\File{logic.pas}{2007}{4}{17}{18:45}{39521}
\L{\LB{\K{unit}_\V{logic};}}
\L{\LB{}}
\L{\LB{\C{}\{\$mode_objfpc\}\CE{}\C{}\{\$H+\}\CE{}}}
\L{\LB{\C{}//\{\$define_debug\}\CE{}}}
\L{\LB{\K{interface}}}
\L{\LB{}}
\L{\LB{\K{uses}}}
\L{\LB{}\Tab{2}{\V{Classes},_\V{SysUtils},\V{windows};}}
\L{\LB{\K{type}}}
\L{\LB{}\Tab{2}{\V{trilean}=(\V{triUnset},_\V{tri0},_\V{tri1});_\C{}//wie_boolean_für_ein_Feld\CE{}}}
\L{\LB{\K{const}}}
\L{\LB{}\Tab{2}{\V{TRI\_NOT}:\K{array}[\V{trilean}]_\K{of}_\V{trilean}=(\V{triUnset},\V{tri1},\V{tri0});_\C{}//not-Operator\CE{}}}
\L{\LB{\K{type}}}
\L{\LB{}\Tab{2}{\C{}\{_TBidoku_\}\CE{}}}
\L{\LB{}\Tab{2}{\C{}//Speichert_das_Ergebnis_einer_Lösungssuche\CE{}}}
\L{\LB{}\Tab{2}{\V{TSolveResult}=\K{record}}}
\L{\LB{}\Tab{4}{\V{solved}:_\V{boolean};}\Tab{27}{\C{}//Wurde_es_gelöst\CE{}}}
\L{\LB{}\Tab{4}{\V{solutioncount}:_\V{longint};\C{}//Zahl_der_Lösungen\CE{}}}
\L{\LB{}\Tab{4}{\V{solutions}:\V{TFPList};}\Tab{27}{\C{}//Alle_Lösungen,_nil,_wenn_nur_eine_gesucht_wurde\CE{}}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{\V{PSolveResult}=\5\V{tsolveResult};}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Ist_das_Bidoku_unvollständig,_gelöst_oder_fehlerhaft?\CE{}}}
\L{\LB{}\Tab{2}{\V{TSolveStatus}=(\V{ssPartly},\V{ssSolved},\V{ssWrong});}}
\L{\LB{}\Tab{2}{\C{}//Die_Art_wie_ein_Feld_belegt_wurde\CE{}}}
\L{\LB{}\Tab{2}{\V{TSolutionMethod}=(\V{smUnknown},\V{smUser},_\C{}//unbekannt;_vom_Benutzer;\CE{}}}
\L{\LB{}\Tab{19}{\V{smFixed},}\Tab{37}{\C{}//gar_nicht,_sondern_vorgegeben;\CE{}}}
\L{\LB{}\Tab{19}{\V{smBacktracking1},}\Tab{37}{\C{}//durch_Raten,_es_gibt_nur_eine_Möglichkeit\CE{}}}
\L{\LB{}\Tab{19}{\V{smBacktracking2},}\Tab{37}{\C{}//durch_Raten,_es_gibt_zwei_Möglichkeiten\CE{}}}
\L{\LB{}\Tab{19}{\V{smLogicTrivial},}\Tab{37}{\C{}//durch_vervollständigen_einer_Reihe/Quadrat\CE{}}}
\L{\LB{}\Tab{19}{\V{smLogicCombined});_\C{}//Durch_den_Schnitt_einer_Reihe_mit_Quadrat\CE{}}}
\L{\LB{}}
\L{\LB{\K{const}}}
\L{\LB{}\Tab{2}{\C{}//Lösungen_durch_Raten\CE{}}}
\L{\LB{}\Tab{2}{\V{BACKTRACKING\_SOLUTION}=[\V{smBacktracking1},\V{smBacktracking2}];}}
\L{\LB{}\Tab{2}{\C{}//Logische_Lösung\CE{}}}
\L{\LB{}\Tab{2}{\V{LOGICAL\_SOLUTION}=[\V{smLogicTrivial},\V{smLogicCombined}];}}
\L{\LB{}\Tab{2}{\C{}//Eindeutige_Lösung\CE{}}}
\L{\LB{}\Tab{2}{\V{UNIQUE\_SOLUTION}=[\V{smBacktracking1},\V{smLogicTrivial},\V{smLogicCombined}];}}
\L{\LB{}\Tab{2}{\C{}//Eindeutiges_Feld_(eindeutig_gelöst,_oder_vorgegeben)\CE{}}}
\L{\LB{}\Tab{2}{\V{UNIQUE\_FIELD}=\V{UNIQUE\_SOLUTION}_+_[\V{smFixed}];}}
\L{\LB{\K{type}}}
\L{\LB{}\Tab{2}{\V{TDifficulty}=(\V{dEasy},\V{dNormal},\V{dHard});_\C{}//Schwierigkeitsgrad\CE{}}}
\L{\LB{}\Tab{2}{}}
\L{\LB{}\Tab{2}{\C{}//Liste_von_Feldern,_die_eine_Gruppe_bilden\CE{}}}
\L{\LB{}\Tab{2}{\V{TPositionGroup}=\K{array}_\K{of}_\K{record}}}
\L{\LB{}\Tab{4}{\V{u},\V{v}:_\V{longint};}\Tab{21}{\C{}//Feldkoordinate\CE{}}}
\L{\LB{}\Tab{4}{\V{negate}:_\V{boolean};_\C{}//Feldwert_ist_der_umgekehrte_Basiswert\CE{}}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{\V{TPositionsArray}=\K{array}_\K{of}_\V{TPositionGroup};}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\V{TBidoku}=\K{class}}}
\L{\LB{}\Tab{2}{\K{private}}}
\L{\LB{}\Tab{4}{\V{changed}:_\V{boolean};}\Tab{23}{\C{}//wird_bei_Änderungen_auf_true_gesetzt\CE{}}}
\L{\LB{}\Tab{4}{\V{n},\V{maxcount}:\V{longint};\C{}//Größe_des_Bidokus_und_Anzahl_der_Felder_einer_Zahl\CE{}}}
\L{\LB{}\Tab{4}{\V{time}:\V{longint};}\Tab{23}{\C{}//Wird_bei_jedem_put-Aufruf_inkrementiert\CE{}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\C{}//Bidokufeld\CE{}}}
\L{\LB{}\Tab{4}{\V{data}:\K{array}_\K{of}_\K{array}_\K{of}_\V{trilean};}}
\L{\LB{}\Tab{4}{\C{}//Anzahl_der_gefüllten_Felder_pro_Reihe_und_Zahl\CE{}}}
\L{\LB{}\Tab{4}{\V{rows},\V{cols}:\K{array}_\K{of}_\K{array}[\V{trilean}]_\K{of}_\V{longint};}}
\L{\LB{}\Tab{4}{\C{}//Anzahl_der_gefüllten_Felder_pro_Quadrat_und_Zahl\CE{}}}
\L{\LB{}\Tab{4}{\V{quadrates}:_\K{array}_\K{of}_\K{array}_\K{of}_\K{array}[\V{trilean}]_\K{of}_\V{longint};}}
\L{\LB{}\Tab{4}{\C{}//Lösungsmethode_für_ein_Feld\CE{}}}
\L{\LB{}\Tab{4}{\V{solutionMethod}:_\K{array}_\K{of}_\K{array}_\K{of}_\V{TSolutionMethod};}}
\L{\LB{}\Tab{4}{\C{}//Zeiten,_wann_das_Feld_belegt_wurde\CE{}}}
\L{\LB{}\Tab{4}{\V{putTimes}:_\K{array}_\K{of}_\K{array}_\K{of}_\V{longint};}}
\L{\LB{}}
\L{\LB{}\Tab{4}{\C{}//Löst_das_Rätsel_und_gibt_die_Anzahl_der_gefundenen_Lösungen_zurück\CE{}}}
\L{\LB{}\Tab{4}{\C{}//allSolutions:_sollen_alle_Lösungen_gefunden_werden\CE{}}}
\L{\LB{}\Tab{4}{\C{}//deep:_Rekursionstiefe\CE{}}}
\L{\LB{}\Tab{4}{\C{}//solutions:_Speichert_die_Lösungen_(kann_nil_sein)\CE{}}}
\L{\LB{}\Tab{4}{\C{}//Ist_allSolutions=false,_wird_die_Lösung_im_Bidoku_selbst_gespeichert\CE{}}}
\index{\_solve}\Proc{\_solve}\L{\LB{}\Tab{4}{\K{function}_\V{\_solve}(\V{allSolutions}:_\V{boolean};\V{deep}:\V{longint};\V{solutions}:\V{TFPList}):\V{longint};}}
\L{\LB{}}
\L{\LB{}\Tab{4}{\C{}//Setzt_das_Feld_x,y_auf_den_Wert_c_und_speichert_dafür_die_Lösungsmethode\CE{}}}
\L{\LB{}\Tab{4}{\C{}//rows,cols_und_fields_werden_auch_entsprechend_angepasst\CE{}}}
\index{put}\Proc{put}\L{\LB{}\Tab{4}{\K{procedure}_\V{put}(\V{x},\V{y}:\V{longint};_\V{c}:_\V{trilean};_\V{method}:_\V{TSolutionMethod});}}
\L{\LB{}\Tab{4}{\C{}//Setzt_nur_leere_Felder\CE{}}}
\index{tryput}\Proc{tryput}\L{\LB{}\Tab{4}{\K{procedure}_\V{tryput}(\V{x},\V{y}:\V{longint};_\V{c}:_\V{trilean};_\V{method}:_\V{TSolutionMethod});\K{inline};}}
\L{\LB{}\Tab{2}{\K{public}}}
\L{\LB{}\Tab{4}{\C{}//Wie_oben,_nur_gilt_hier_immer_method=smUser\CE{}}}
\index{put}\Proc{put}\L{\LB{}\Tab{4}{\K{procedure}_\V{put}(\V{x},\V{y}:\V{longint};_\V{c}:_\V{trilean});\K{inline};}}
\index{tryput}\Proc{tryput}\L{\LB{}\Tab{4}{\K{procedure}_\V{tryput}(\V{x},\V{y}:\V{longint};_\V{c}:_\V{trilean});\K{inline};}}
\L{\LB{}\Tab{4}{\C{}//Übernimmt_ein_Feld_von_einem_anderen_Bidoku\CE{}}}
\index{copyField}\Proc{copyField}\L{\LB{}\Tab{4}{\K{procedure}_\V{copyField}(\V{x},\V{y}:\V{longint};_\V{bidoku}:_\V{TBidoku});}}
\L{\LB{}\Tab{4}{\C{}//Gibt_den_Wert_eines_Feldes_zurück\CE{}}}
\index{get}\Proc{get}\L{\LB{}\Tab{4}{\K{function}_\V{get}(\V{x},\V{y}:\V{longint}):_\V{trilean};\K{inline};}}
\L{\LB{}\Tab{4}{\C{}//Gibt_die_Lösungsmethode_für_ein_Feld_zurück\CE{}}}
\index{getSolutionMethod}\Proc{getSolutionMethod}\L{\LB{}\Tab{4}{\K{function}_\V{getSolutionMethod}(\V{x},\V{y}:\V{longint}):\V{TSolutionMethod};\K{inline};}}
\L{\LB{}\Tab{4}{\C{}//Gibt_den_Lösungszeitpunkt_für_ein_Feld_zurück\CE{}}}
\index{getSolutionTime}\Proc{getSolutionTime}\L{\LB{}\Tab{4}{\K{function}_\V{getSolutionTime}(\V{x},\V{y}:\V{longint}):\V{longint};\K{inline};}}
\L{\LB{}}
\L{\LB{}\Tab{4}{\C{}//Erzeugt_leers_ein_Bidoku._asize_ist_die_Zahl_der_Quadrate_pro_Reihe\CE{}}}
\L{\LB{}\Tab{4}{\C{}//und_die_Zahl_der_Felder_in_einer_Reihe_eines_Quadrates\CE{}}}
\index{create}\Proc{create}\L{\LB{}\Tab{4}{\K{constructor}_\V{create}(\V{asize}:\V{longint}=\N{4});}}
\index{updateSize}\Proc{updateSize}\L{\LB{}\Tab{4}{\K{procedure}_\V{updateSize}();}}
\index{destroy}\Proc{destroy}\L{\LB{}\Tab{4}{\K{destructor}_\V{destroy}();\K{override};_\C{}//Löscht_das_Bidoku\CE{}}}
\index{clone}\Proc{clone}\L{\LB{}\Tab{4}{\K{function}_\V{clone}():_\V{TBidoku};}\Tab{35}{\C{}//Kopiert_das_Bidoku\CE{}}}
\L{\LB{}\Tab{4}{\C{}//Berechnet_ein_Bidoku_mit_bestimmter_Schwierigkeit_und_Muster\CE{}}}
\index{generate}\Proc{generate}\L{\LB{}\Tab{4}{\K{procedure}_\V{generate}(\V{difficulty}:_\V{TDifficulty};}}
\L{\LB{}\Tab{23}{\V{positions}:_\V{TPositionsArray});}}
\L{\LB{}\Tab{4}{\C{}//Erzeugt_ein_Bidoku_das_einen_Text_repräsentiert\CE{}}}
\index{generateEncryption}\Proc{generateEncryption}\L{\LB{}\Tab{4}{\K{procedure}_\V{generateEncryption}(\V{s}:\V{string});}}
\L{\LB{}\Tab{4}{\C{}//Minimiert_das_Bidoku\CE{}}}
\index{minimize}\Proc{minimize}\L{\LB{}\Tab{4}{\K{procedure}_\V{minimize};}}
\L{\LB{}}
\L{\LB{}\Tab{4}{\C{}//Findet_den_Text_heraus,_der_in_dem_Bidoku_verborgen_ist\CE{}}}
\index{decode}\Proc{decode}\L{\LB{}\Tab{4}{\K{function}_\V{decode}():\V{string};}}
\L{\LB{}}
\L{\LB{}\Tab{4}{\C{}//Liefert_eine_Zahl,_die_die_Schwierigkeit_angibt,_zurück\CE{}}}
\index{rateDifficulty}\Proc{rateDifficulty}\L{\LB{}\Tab{4}{\K{function}_\V{rateDifficulty}:_\V{longint};}}
\L{\LB{}\Tab{4}{\C{}//Zählt_Symmetriefehler\CE{}}}
\index{symmetricErrors}\Proc{symmetricErrors}\L{\LB{}\Tab{4}{\K{function}_\V{symmetricErrors}(\K{const}_\V{pos}:\V{TPositionsArray}):\V{longint};}}
\L{\LB{}}
\L{\LB{}\Tab{4}{\C{}//Lösung_mittels_einfacher_logischer_Regeln\CE{}}}
\index{logicalSolve}\Proc{logicalSolve}\L{\LB{}\Tab{4}{\K{procedure}_\V{logicalSolve}();}}
\L{\LB{}\Tab{4}{\C{}//Löst_das_Bidoku_vollständig\CE{}}}
\index{solve}\Proc{solve}\L{\LB{}\Tab{4}{\K{function}_\V{solve}(\V{allSolutions},\V{list}:_\V{boolean}):\V{TSolveResult};}}
\L{\LB{}\Tab{4}{\C{}//Überprüft,_ob_es_eine_Lösung_gibt,_indem_das_Rätsel_geklont_und_gelöst_wird\CE{}}}
\index{isSolvable}\Proc{isSolvable}\L{\LB{}\Tab{4}{\K{function}_\V{isSolvable}():\V{boolean};}}
\L{\LB{}\Tab{4}{\C{}//Gibt_den_Lösungsstatus_(noch_nicht,_gelöst,_fehlerhaft)_zurück\CE{}}}
\index{solved}\Proc{solved}\L{\LB{}\Tab{4}{\K{function}_\V{solved}():_\V{TSolveStatus};}}
\L{\LB{}}
\index{toString}\Proc{toString}\L{\LB{}\Tab{4}{\K{function}_\V{toString}():\V{string};}\Tab{40}{\C{}//Wandelt_das_Bidoku_in_einen_String_um\CE{}}}
\index{saveToFile}\Proc{saveToFile}\L{\LB{}\Tab{4}{\K{procedure}_\V{saveToFile}(\V{fn}:_\V{string});}\Tab{40}{\C{}//Speichert_es\CE{}}}
\index{loadFromFile}\Proc{loadFromFile}\L{\LB{}\Tab{4}{\K{procedure}_\V{loadFromFile}(\V{fn}:_\V{string});_\C{}//Lädt_es\CE{}}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\C{}//Erzeugt_eine_horizontale/vertikale_Spiegelung_um_die_Bidokumitte\CE{}}}
\index{makeMirrorSymmetryH}\Proc{makeMirrorSymmetryH}\L{\LB{}\Tab{4}{\K{function}_\V{makeMirrorSymmetryH}(\V{invert}:_\V{boolean}):\V{TPositionsArray};}}
\index{makeMirrorSymmetryV}\Proc{makeMirrorSymmetryV}\L{\LB{}\Tab{4}{\K{function}_\V{makeMirrorSymmetryV}(\V{invert}:_\V{boolean}):\V{TPositionsArray};}}
\L{\LB{}\Tab{4}{\C{}//Erzeugt_eine_horizontale/vertikale_Spiegelung_um_die_Mitte_der_einen_und\CE{}}}
\L{\LB{}\Tab{4}{\C{}//der_anderen_Hälft_des_Bidokus\CE{}}}
\index{makeMirrorSymmetrySubH}\Proc{makeMirrorSymmetrySubH}\L{\LB{}\Tab{4}{\K{function}_\V{makeMirrorSymmetrySubH}(\V{invert}:_\V{boolean}):\V{TPositionsArray};}}
\index{makeMirrorSymmetrySubV}\Proc{makeMirrorSymmetrySubV}\L{\LB{}\Tab{4}{\K{function}_\V{makeMirrorSymmetrySubV}(\V{invert}:_\V{boolean}):\V{TPositionsArray};}}
\L{\LB{}\Tab{4}{\C{}//Verbindet_zwei_Symmetrien\CE{}}}
\index{mergeSymmetry}\Proc{mergeSymmetry}\L{\LB{}\Tab{4}{\K{function}_\V{mergeSymmetry}(\V{a},\V{b}:\V{TPositionsArray}):\V{TPositionsArray};}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\K{property}_\V{size}:_\V{longint}_\V{read}_\V{n};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}\{_TBidoku_\}\CE{}}}
\L{\LB{\K{const}_\V{MAX\_SOLUTIONS}=\N{10000};_\C{}//Maximale_Anzahl_von_Lösungen\CE{}}}
\L{\LB{\K{implementation}}}
\L{\LB{}}
\L{\LB{\C{}\{_TBidoku_\}\CE{}}}
\L{\LB{}}
\L{\LB{\C{}//Liefert_eine_Zahl,_die_die_Schwierigkeit_angibt,_zurück\CE{}}}
\index{TBidoku.rateDifficulty}\Proc{TBidoku.rateDifficulty}\L{\LB{\K{function}_\V{TBidoku.rateDifficulty}:_\V{longint};}}
\L{\LB{\K{var}_\V{i},\V{j}:\V{longint};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{result}:=\N{0};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{6}{\K{case}_\V{solutionMethod}[\V{i},\V{j}]_\K{of}}}
\L{\LB{}\Tab{8}{\V{smUnknown},\V{smUser}:_\V{raise}_\V{exception.create}(\S{}{'}Fehler{'}\SE{});}}
\L{\LB{}\Tab{8}{\V{smBacktracking1}:_\V{result}+=\N{50};}}
\L{\LB{}\Tab{8}{\V{smLogicCombined}:_\V{result}+=\N{5};}}
\L{\LB{}\Tab{8}{\V{smLogicTrivial}:_\V{result}+=\N{1};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Zählt_Symmetriefehler\CE{}}}
\index{TBidoku.symmetricErrors}\Proc{TBidoku.symmetricErrors}\L{\LB{\K{function}_\V{TBidoku.symmetricErrors}(\K{const}_\V{pos}:\V{TPositionsArray}):\V{longint};}}
\L{\LB{\K{var}_\V{i},\V{j},\V{k}:\V{longint};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\K{if}_\K{not}_\V{assigned}(\V{pos})_\K{then}_\V{result}:=\N{0};}}
\L{\LB{}\Tab{2}{\V{result}:=\N{0};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{pos})_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{pos}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{6}{\K{for}_\V{k}:=\N{0}_\K{to}_\V{high}(\V{pos}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_(\V{data}[\V{pos}[\V{i},\V{j}]\V{.u},\V{pos}[\V{i},\V{j}]\V{.v}]\<\>\V{data}[\V{pos}[\V{i},\V{k}]\V{.u},\V{pos}[\V{i},\V{k}]\V{.v}])_\K{xor}}}
\L{\LB{}\Tab{11}{(\V{pos}[\V{i},\V{j}]\V{.negate}_\K{xor}_\V{pos}[\V{i},\V{k}]\V{.negate})_\K{then}}}
\L{\LB{}\Tab{12}{\V{result}+=\N{1};}}
\L{\LB{}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Löst_das_Rätsel_und_gibt_die_Anzahl_der_gefundenen_Lösungen_zurück\CE{}}}
\L{\LB{\C{}//allSolutions:_sollen_alle_Lösungen_gefunden_werden\CE{}}}
\L{\LB{\C{}//deep:_Rekursionstiefe\CE{}}}
\L{\LB{\C{}//solutions:_Speichert_die_Lösungen_(kann_nil_sein)\CE{}}}
\L{\LB{\C{}//Ist_allSolutions=false,_wird_die_Lösung_im_Bidoku_selbst_gespeichert\CE{}}}
\index{TBidoku.\_solve}\Proc{TBidoku.\_solve}\L{\LB{\K{function}_\V{TBidoku.\_solve}(\V{allSolutions}:_\V{boolean};\V{deep}:\V{longint};}}
\L{\LB{}\Tab{24}{\V{solutions}:_\V{TFPList}):\V{longint};}}
\L{\LB{\K{var}_\V{i},\V{k},\V{l},\V{maxR},\V{maxC}:_\V{longint};}}
\L{\LB{}\Tab{4}{\V{temp}:\V{TBidoku};}}
\L{\LB{}\Tab{4}{\V{newSolutions},\V{oldCount}:_\V{longint};}}
\L{\LB{}\Tab{4}{\V{tri},\V{triUsed}:_\V{trilean};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{result}:=\N{0};}}
\L{\LB{}\Tab{2}{\C{}//OutputDebugString(pchar(toString()));\CE{}}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Logisches_Lösen\CE{}}}
\L{\LB{}\Tab{2}{\V{logicalSolve};}}
\L{\LB{}\Tab{2}{\C{}//Test_auf_korrekte_Lösung\CE{}}}
\L{\LB{}\Tab{2}{\K{case}_\V{solved}()_\K{of}}}
\L{\LB{}\Tab{4}{\V{ssWrong}:_\K{exit}(\N{0});}}
\L{\LB{}\Tab{4}{\V{ssSolved}:_\K{begin}}}
\L{\LB{}\Tab{6}{\K{if}_\V{assigned}(\V{solutions})_\K{then}}}
\L{\LB{}\Tab{8}{\V{solutions.Add}(\V{self});}}
\L{\LB{}\Tab{6}{\K{exit}(\N{1});}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{\C{}//Abbruch_bei_zu_vielen_Lösungen\CE{}}}
\L{\LB{}\Tab{2}{\K{if}_(\V{solutions}\<\>\K{nil})\K{and}_(\V{solutions.Count}\>=\V{MAX\_SOLUTIONS})\K{and}_\V{allSolutions}_\K{then}}}
\L{\LB{}\Tab{4}{\K{exit};}}
\L{\LB{}\Tab{2}{\C{}//Rest_per_BF_Lösung\CE{}}}
\L{\LB{}\Tab{2}{\C{}//Auswahl_eines_Feldes_mit_maximaler_Füllungsdichte\CE{}}}
\L{\LB{}\Tab{2}{\V{maxR}:=\-\N{1};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{rows})_\K{do}}}
\L{\LB{}\Tab{4}{\K{if}_(\V{rows}[\V{i}][\V{tri0}]+\V{rows}[\V{i}][\V{tri1}]\<\N{2}*\V{maxcount})\K{and}_((\V{maxR}=\-\N{1})_\K{or}}}
\L{\LB{}\Tab{7}{(\V{rows}[\V{i}][\V{tri0}]+\V{rows}[\V{i}][\V{tri1}]+\V{deep}_\K{and}_\N{1}\>}}
\L{\LB{}\Tab{40}{\V{rows}[\V{maxR}][\V{tri0}]+\V{rows}[\V{maxR}][\V{tri1}]))_\K{then}}}
\L{\LB{}\Tab{6}{\V{maxR}:=\V{i};}}
\L{\LB{}\Tab{2}{\V{assert}(\V{maxR}\>\-\N{1},\S{}{'}Keine_Zeile_vorhanden{'}\SE{});}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\V{maxC}:=\-\N{1};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{4}{\K{if}_(\V{data}[\V{i},\V{maxR}]=\V{triUnset})_\K{and}_((\V{maxC}=\-\N{1})_\K{or}}}
\L{\LB{}\Tab{10}{(\V{cols}[\V{i}][\V{tri0}]+\V{cols}[\V{i}][\V{tri1}]+(\V{deep}_\K{and}_\N{2})\K{shr}_\N{1}\>}}
\L{\LB{}\Tab{39}{\V{cols}[\V{maxC}][\V{tri0}]+\V{cols}[\V{maxC}][\V{tri1}]))_\K{then}}}
\L{\LB{}\Tab{6}{\V{maxC}:=\V{i};}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\V{assert}(\V{maxC}\>\-\N{1},\S{}{'}Keine_Spalte_vorhanden{'}\SE{});}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\K{if}_\V{allSolutions}_\K{and}_\V{assigned}(\V{solutions})_\K{then}}}
\L{\LB{}\Tab{4}{\V{oldCount}:=\V{solutions.Count};}}
\L{\LB{}\Tab{2}{\K{for}_\V{tri}:=\V{tri0}_\K{to}_\V{tri1}_\K{do}_\K{begin}}}
\L{\LB{}\Tab{4}{\V{temp}:=\V{clone}();}}
\L{\LB{}\Tab{4}{\C{}//smBacktracking1_wird_im_zweiten_Durchlauf_verwendet,_wenn_der_andere_Wert\CE{}}}
\L{\LB{}\Tab{4}{\C{}//unmöglich_ist\CE{}}}
\L{\LB{}\Tab{4}{\K{if}_\V{deep}_\K{and}_\N{4}=\N{0}_\K{then}_\V{triUsed}:=\V{tri}}}
\L{\LB{}\Tab{4}{\K{else}_\V{triUsed}:=\V{TRI\_NOT}[\V{tri}];}}
\L{\LB{}\Tab{4}{\K{if}_(\V{tri}=\V{tri1})_\K{and}_(\V{result}=\N{0})_\K{then}}}
\L{\LB{}\Tab{6}{\V{temp.put}(\V{maxC},\V{maxR},\V{triUsed},\V{smBacktracking1})}}
\L{\LB{}\Tab{5}{\K{else}}}
\L{\LB{}\Tab{6}{\V{temp.put}(\V{maxC},\V{maxR},\V{triUsed},\V{smBacktracking2});}}
\L{\LB{}\Tab{4}{\C{}//Rekursiver_Aufruf\CE{}}}
\L{\LB{}\Tab{4}{\V{newSolutions}:=\V{temp.\_solve}(\V{allSolutions},\V{deep}+\N{1},\V{solutions});}}
\L{\LB{}\Tab{4}{\C{}//Lösungen_verarbeiten\CE{}}}
\L{\LB{}\Tab{4}{\K{if}_\V{newSolutions}\>\N{0}_\K{then}_\K{begin}}}
\L{\LB{}\Tab{6}{\V{result}+=\V{newSolutions};}\Tab{29}{\C{}//Zahl_speichern\CE{}}}
\L{\LB{}\Tab{6}{\K{if}_\K{not}_\V{allSolutions}_\K{then}_\K{begin}}}
\L{\LB{}\Tab{8}{\C{}//Bei_einer_Einzellösung_alle_Werte_in_self_speichern\CE{}}}
\L{\LB{}\Tab{8}{\K{for}_\V{k}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{10}{\K{for}_\V{l}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{k}])_\K{do}_\K{begin}}}
\L{\LB{}\Tab{12}{\K{if}_(\V{solutionMethod}[\V{k},\V{l}]=\V{smUnknown})_\K{then}}}
\L{\LB{}\Tab{14}{\V{put}(\V{k},\V{l},\V{temp.data}[\V{k},\V{l}],\V{temp.solutionMethod}[\V{k},\V{l}])}}
\L{\LB{}\Tab{13}{\K{else}}}
\L{\LB{}\Tab{14}{\V{put}(\V{k},\V{l},\V{temp.data}[\V{k},\V{l}],\V{solutionMethod}[\V{k},\V{l}]);}}
\L{\LB{}\Tab{11}{\K{end};}}
\L{\LB{}\Tab{8}{\C{}//und_zufrieden_beenden\CE{}}}
\L{\LB{}\Tab{8}{\V{temp.free};}}
\L{\LB{}\Tab{8}{\K{exit};}}
\L{\LB{}\Tab{6}{\K{end}_\K{else}_\K{if}_(\V{solutions}=\K{nil})_\K{or}_(\V{solutions.count}=\N{0})}}
\L{\LB{}\Tab{18}{\K{or}_(\V{solutions.Last}\<\>\V{pointer}(\V{temp}))}\Tab{54}{\K{then}}}
\L{\LB{}\Tab{8}{\V{temp.free};_\C{}//Nur_freigeben,_wenn_nicht_in_der_Liste\CE{}}}
\L{\LB{}\Tab{4}{\K{end}_\K{else}_\K{begin}}}
\L{\LB{}\Tab{6}{\C{}//Bei_einer_unmöglichen_zweiten_Lösung_(bei_der_ersten_läuft_die_Schleife\CE{}}}
\L{\LB{}\Tab{6}{\C{}//nicht)_alle_Lösungswege_auf_smBacktracking1_setzen\CE{}}}
\L{\LB{}\Tab{6}{\K{if}_\V{allSolutions}_\K{and}_\V{assigned}(\V{solutions})_\K{then}}}
\L{\LB{}\Tab{8}{\K{for}_\V{i}:=\V{oldCount}_\K{to}_\V{solutions.count}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{10}{\V{TBidoku}(\V{solutions}[\V{i}])\V{.solutionMethod}[\V{maxC},\V{maxR}]:=\V{smBacktracking1};}}
\L{\LB{}}
\L{\LB{}\Tab{6}{\V{temp.free};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Setzt_das_Feld_x,y_auf_den_Wert_c_und_speichert_dafür_die_Lösungsmethode\CE{}}}
\L{\LB{\C{}//rows,cols_und_fields_werden_auch_entsprechend_angepasst\CE{}}}
\index{TBidoku.put}\Proc{TBidoku.put}\L{\LB{\K{procedure}_\V{TBidoku.put}(\V{x},_\V{y}:_\V{longint};_\V{c}:_\V{trilean};_\V{method}:_\V{TSolutionMethod});}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{time}+=\N{1};}}
\L{\LB{}\Tab{2}{\K{if}_\V{solutionMethod}\<\>\K{nil}_\K{then}_\V{solutionMethod}[\V{x},\V{y}]:=\V{method}_;}}
\L{\LB{}\Tab{2}{\V{putTimes}[\V{x},\V{y}]:=\V{time};}}
\L{\LB{}\Tab{2}{\K{if}_\V{data}[\V{x},\V{y}]=\V{c}_\K{then}_\K{exit};}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Alten_Wert_entfernen\CE{}}}
\L{\LB{}\Tab{2}{\V{cols}[\V{x},\V{data}[\V{x},\V{y}]]\-=\N{1};}}
\L{\LB{}\Tab{2}{\V{rows}[\V{y},\V{data}[\V{x},\V{y}]]\-=\N{1};}}
\L{\LB{}\Tab{2}{\V{quadrates}[\V{x}_\K{div}_\V{n},\V{y}_\K{div}_\V{n},\V{data}[\V{x},\V{y}]]\-=\N{1};}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Neuen_Wert_einfügen\CE{}}}
\L{\LB{}\Tab{2}{\V{data}[\V{x},\V{y}]:=\V{c};}}
\L{\LB{}\Tab{2}{\V{cols}[\V{x},\V{c}]+=\N{1};}}
\L{\LB{}\Tab{2}{\V{rows}[\V{y},\V{c}]+=\N{1};}}
\L{\LB{}\Tab{2}{\V{quadrates}[\V{x}_\K{div}_\V{n},\V{y}_\K{div}_\V{n},\V{c}]+=\N{1};}}
\L{\LB{}\Tab{2}{\V{changed}:=\V{true};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Setzt_nur_leere_Felder\CE{}}}
\index{TBidoku.tryput}\Proc{TBidoku.tryput}\L{\LB{\K{procedure}_\V{TBidoku.tryput}(\V{x},_\V{y}:_\V{longint};_\V{c}:_\V{trilean};_\V{method}:_\V{TSolutionMethod});}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\K{if}_\V{data}[\V{x},\V{y}]=\V{triUnset}_\K{then}_\V{put}(\V{x},\V{y},\V{c},\V{method});}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Setzt_ein_Feld_durch_den_Benutzer\CE{}}}
\index{TBidoku.put}\Proc{TBidoku.put}\L{\LB{\K{procedure}_\V{TBidoku.put}(\V{x},_\V{y}:_\V{longint};_\V{c}:_\V{trilean});_\C{}//inline;\CE{}}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{put}(\V{x},\V{y},\V{c},\V{smUser});}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Setzt_nur_leere_Felder\CE{}}}
\index{TBidoku.tryput}\Proc{TBidoku.tryput}\L{\LB{\K{procedure}_\V{TBidoku.tryput}(\V{x},_\V{y}:_\V{longint};_\V{c}:_\V{trilean});_\K{inline};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\K{if}_\V{data}[\V{x},\V{y}]=\V{triUnset}_\K{then}_\V{put}(\V{x},\V{y},\V{c});}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Übernimmt_ein_Feld_von_einem_anderen_Bidoku\CE{}}}
\L{\LB{\C{}//(einzige_Möglichkeit_von_außen_den_Lösungsweg_zu_setzen)\CE{}}}
\index{TBidoku.copyField}\Proc{TBidoku.copyField}\L{\LB{\K{procedure}_\V{TBidoku.copyField}(\V{x},_\V{y}:_\V{longint};_\V{bidoku}:_\V{TBidoku});}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{put}(\V{x},\V{y},\V{bidoku.data}[\V{x},\V{y}],\V{bidoku.solutionMethod}[\V{x},\V{y}]);}}
\L{\LB{}\Tab{2}{\V{putTimes}[\V{x},\V{y}]:=\V{bidoku.putTimes}[\V{x},\V{y}];}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Auslesen\CE{}}}
\index{TBidoku.get}\Proc{TBidoku.get}\L{\LB{\K{function}_\V{TBidoku.get}(\V{x},_\V{y}:_\V{longint}):_\V{trilean};\K{inline};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\K{exit}(\V{data}[\V{x},\V{y}]);}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Auslesen\CE{}}}
\index{TBidoku.getSolutionMethod}\Proc{TBidoku.getSolutionMethod}\L{\LB{\K{function}_\V{TBidoku.getSolutionMethod}(\V{x},_\V{y}:_\V{longint}):_\V{TSolutionMethod};_\K{inline};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{result}:=\V{solutionMethod}[\V{x},\V{y}];}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}//Gibt_den_Lösungszeitpunkt_für_ein_Feld_zurück\CE{}}}
\index{TBidoku.getSolutionTime}\Proc{TBidoku.getSolutionTime}\L{\LB{\K{function}_\V{TBidoku.getSolutionTime}(\V{x},_\V{y}:_\V{longint}):_\V{longint};_\K{inline};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{result}:=\V{putTimes}[\V{x},\V{y}];}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Alle_Spalten,_Zeilen,_Quadrate_enthalten_genau_maxcount_Zahlen_von_jeder_Sorte\CE{}}}
\index{TBidoku.solved}\Proc{TBidoku.solved}\L{\LB{\K{function}_\V{TBidoku.solved}():\V{TSolveStatus};}}
\L{\LB{\K{var}_\V{count}:_\K{array}[\V{trilean}]_\K{of}_\V{longint};}}
\L{\LB{}\Tab{4}{\V{i},\V{j},\V{fi},\V{fj}:\V{longint};_\C{}//fi,fj:_Feld\CE{}}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{result}:=\V{ssSolved};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{4}{\C{}//Spalten_überprüfen\CE{}}}
\L{\LB{}\Tab{4}{\V{FillChar}(\V{count},\V{sizeof}(\V{count}),\N{0});}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{6}{\V{inc}(\V{count}[\V{data}[\V{i},\V{j}]]);}}
\L{\LB{}\Tab{4}{\K{if}_(\V{count}[\V{tri1}]\>\V{maxcount})_\K{or}_(\V{count}[\V{tri0}]\>\V{maxcount})_\K{then}_\K{exit}(\V{ssWrong});}}
\L{\LB{}\Tab{4}{\K{if}_(\V{count}[\V{tri1}]\<\V{maxcount})_\K{or}_(\V{count}[\V{tri0}]\<\V{maxcount})_\K{then}_\V{result}:=\V{ssPartly};}}
\L{\LB{}\Tab{4}{\C{}//Zeilen_überprüfen\CE{}}}
\L{\LB{}\Tab{4}{\V{FillChar}(\V{count},\V{sizeof}(\V{count}),\N{0});}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{6}{\V{inc}(\V{count}[\V{data}[\V{j},\V{i}]]);}}
\L{\LB{}\Tab{4}{\K{if}_(\V{count}[\V{tri1}]\>\V{maxcount})_\K{or}_(\V{count}[\V{tri0}]\>\V{maxcount})_\K{then}_\K{exit}(\V{ssWrong});}}
\L{\LB{}\Tab{4}{\K{if}_(\V{count}[\V{tri1}]\<\V{maxcount})_\K{or}_(\V{count}[\V{tri0}]\<\V{maxcount})_\K{then}_\V{result}:=\V{ssPartly};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{\C{}//Quadrate_überprüfen\CE{}}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{n}\-\N{1}_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\V{FillChar}(\V{count},\V{sizeof}(\V{count}),\N{0});}}
\L{\LB{}\Tab{6}{\K{for}_\V{fi}:=\V{n}*\V{i}_\K{to}_\V{n}*\V{i}_+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{8}{\K{for}_\V{fj}:=\V{n}*\V{j}_\K{to}_\V{n}*\V{j}_+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{10}{\V{inc}(\V{count}[\V{data}[\V{fi},\V{fj}]]);}}
\L{\LB{}\Tab{6}{\K{if}_(\V{count}[\V{tri1}]\>\V{maxcount})_\K{or}_(\V{count}[\V{tri0}]\>\V{maxcount})_\K{then}_\K{exit}(\V{ssWrong});}}
\L{\LB{}\Tab{6}{\K{if}_(\V{count}[\V{tri1}]\<\V{maxcount})_\K{or}_(\V{count}[\V{tri0}]\<\V{maxcount})_\K{then}_\V{result}:=\V{ssPartly};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Erzeugt_ein_leeres_Bidoku\CE{}}}
\index{TBidoku.create}\Proc{TBidoku.create}\L{\LB{\K{constructor}_\V{TBidoku.create}(\V{asize}:_\V{longint}=\N{4});}}
\L{\LB{\K{var}_\V{i},\V{j}:\V{longint};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{n}:=\V{asize};}}
\L{\LB{}\Tab{2}{\V{updateSize}();}}
\L{\LB{}\Tab{2}{\V{changed}:=\V{false};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{rows})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{4}{\V{rows}[\V{i}][\V{triUnset}]:=\N{2}*\V{maxcount};}}
\L{\LB{}\Tab{4}{\V{rows}[\V{i}][\V{tri0}]:=\N{0};_\V{rows}[\V{i}][\V{tri1}]:=\N{0};}}
\L{\LB{}\Tab{4}{\V{cols}[\V{i}][\V{triUnset}]:=\N{2}*\V{maxcount};}}
\L{\LB{}\Tab{4}{\V{cols}[\V{i}][\V{tri0}]:=\N{0};}}
\L{\LB{}\Tab{4}{\V{cols}[\V{i}][\V{tri1}]:=\N{0};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{quadrates})_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{quadrates}[\V{i}])_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\V{quadrates}[\V{i},\V{j}][\V{triUnset}]:=\N{2}*\V{maxcount};}}
\L{\LB{}\Tab{6}{\V{quadrates}[\V{i},\V{j}][\V{tri0}]:=\N{0};_\V{quadrates}[\V{i},\V{j}][\V{tri1}]:=\N{0};}}
\L{\LB{}\Tab{4}{\K{end};}}
\ProcCont{symmetricErrors}\L{\LB{\K{end};}}
\ProcCont{rateDifficulty}\L{\LB{}}
\L{\LB{\C{}//Reserviert_den_Speicher_für_ein_Bidoku_einer_bestimmten_Größe\CE{}}}
\index{TBidoku.updateSize}\Proc{TBidoku.updateSize}\L{\LB{\K{procedure}_\V{TBidoku.updateSize}();}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{data},\V{n}*\V{n},\V{n}*\V{n});}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{rows},\V{n}*\V{n});}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{cols},\V{n}*\V{n});}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{quadrates},\V{n},\V{n});}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{solutionMethod},\V{n}*\V{n},\V{n}*\V{n});;}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{putTimes},\V{n}*\V{n},\V{n}*\V{n});;}}
\L{\LB{}\Tab{2}{\V{maxcount}:=\V{n}*\V{n}_\K{div}_\N{2};}}
\L{\LB{\K{end};}}
\ProcCont{rateDifficulty}\L{\LB{}}
\index{TBidoku.destroy}\Proc{TBidoku.destroy}\L{\LB{\K{destructor}_\V{TBidoku.destroy}();}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\K{inherited}_\V{destroy}();}}
\L{\LB{\K{end};}}
\ProcCont{rateDifficulty}\L{\LB{}}
\L{\LB{\C{}//Kopiert_dass_Bidoku\CE{}}}
\index{TBidoku.clone}\Proc{TBidoku.clone}\L{\LB{\K{function}_\V{TBidoku.clone}():_\V{TBidoku};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{Result}:=\V{TBidoku.create}();}}
\L{\LB{}\Tab{2}{\V{Result.n}:=\V{n};}}
\L{\LB{}\Tab{2}{\V{result.maxcount}:=\V{maxcount};}}
\L{\LB{}\Tab{2}{\V{result.changed}:=\V{false};}}
\L{\LB{}\Tab{2}{\V{Result.rows}:=\V{rows};}}
\L{\LB{}\Tab{2}{\V{Result.cols}:=\V{cols};}}
\L{\LB{}\Tab{2}{\V{Result.quadrates}:=\V{quadrates};}}
\L{\LB{}\Tab{2}{\V{Result.data}:=\V{data};}}
\L{\LB{}\Tab{2}{\V{Result.solutionMethod}:=\V{solutionMethod};}}
\L{\LB{}\Tab{2}{\V{Result.putTimes}:=\V{putTimes};}}
\L{\LB{}\Tab{2}{\V{result.time}:=\V{time};}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{Result.rows},\V{length}(\V{Result.rows}));;}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{Result.cols},\V{length}(\V{Result.cols}));;}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{Result.quadrates},\V{length}(\V{Result.quadrates}),\V{length}(\V{Result.quadrates}));;}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{Result.data},\V{length}(\V{Result.data}),\V{length}(\V{Result.data}));;}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{Result.solutionMethod},\V{length}(\V{Result.data}),\V{length}(\V{Result.data}));;}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{result.putTimes},\V{n}*\V{n},\V{n}*\V{n});}}
\L{\LB{\K{end};}}
\ProcCont{rateDifficulty}\L{\LB{}}
\L{\LB{\C{}//Berechnet_ein_Bidoku_mit_bestimmter_Schwierigkeit_und_Muster\CE{}}}
\index{TBidoku.generate}\Proc{TBidoku.generate}\L{\LB{\K{procedure}_\V{TBidoku.generate}(\V{difficulty}:_\V{TDifficulty};\V{positions}:_\V{TPositionsArray});}}
\L{\LB{\K{var}_\V{i},\V{j}:\V{longint};_\C{}//Schleifenvariablen\CE{}}}
\L{\LB{}\Tab{4}{\V{c},\V{p}:\V{longint};_\C{}//Anzahl_verwendeter_Gruppen_und_aktuelle_Gruppe\CE{}}}
\L{\LB{}\Tab{4}{\V{fieldCount},\V{maxFieldCount}:_\V{longint};_\C{}//gefüllte_Felder_und_maximal_erwünschte\CE{}}}
\L{\LB{}\Tab{4}{\V{fixedTri}:_\V{boolean};}\Tab{26}{\C{}//Stehen_die_Gruppenwerte_fest?\CE{}}}
\L{\LB{}\Tab{4}{\V{bestDiff},\V{value}:_\V{longint};\C{}//Beste_bekannte_Abweichung_vom_Optimum\CE{}}}
\L{\LB{}\Tab{4}{\V{twin},\V{bidoku}:_\V{TBidoku};_\C{}//Kopie_und_neues_Bidoku\CE{}}}
\L{\LB{}\Tab{4}{\V{solutions}:_\V{TFPList};}\Tab{26}{\C{}//Liste_aller_Lösungen\CE{}}}
\L{\LB{}\Tab{4}{\V{tri}:_\V{trilean};}\Tab{26}{\C{}//Grundwert_für_eine_Gruppe\CE{}}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Überprüft,_ob_die_Gruppe_benutzbar_ist\CE{}}}
\index{freeFields}\Proc{freeFields}\L{\LB{}\Tab{2}{\K{function}_\V{freeFields}(\V{p}:\V{longint};\V{out}_\V{base}:_\V{trilean}):\V{boolean};}}
\L{\LB{}\Tab{2}{\K{var}_\V{i},\V{c}:\V{longint};}\Tab{20}{\C{}//Schleifenvariable_und_Zahl_der_belegten_Felder\CE{}}}
\L{\LB{}\Tab{2}{\K{begin}}}
\L{\LB{}\Tab{4}{\V{c}:=\N{0};}}
\L{\LB{}\Tab{4}{\V{base}:=\V{triUnset};}}
\L{\LB{}\Tab{4}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{positions}[\V{p}])_\K{do}}}
\L{\LB{}\Tab{6}{\K{with}_\V{positions}[\V{p},\V{i}]_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_\V{twin.solutionMethod}[\V{u},\V{v}]_\K{in}_\V{UNIQUE\_SOLUTION}_\K{then}_\K{begin}}}
\L{\LB{}\Tab{10}{\C{}//Feld_ist_belegt\CE{}}}
\L{\LB{}\Tab{10}{\K{if}_\V{c}=\N{0}_\K{then}_\K{begin}_\C{}//Erstes_belegtes_Feld?\CE{}}}
\L{\LB{}\Tab{12}{\V{base}:=\V{twin.data}[\V{u},\V{v}];}\Tab{35}{\C{}//=\>_Basiswert_ermitteln\CE{}}}
\L{\LB{}\Tab{12}{\K{if}_\V{negate}_\K{then}_\V{base}:=\V{TRI\_NOT}[\V{base}];}}
\L{\LB{}\Tab{10}{\K{end}_\K{else}_\K{if}_(\V{base}=\V{twin.data}[\V{u},\V{v}])_\K{xor}_\V{negate}_\K{then}\C{}//gleicher_Basiswert?\CE{}}}
\ProcCont{TBidoku.generate}\L{\LB{}\Tab{12}{\K{exit}(\V{false});_\C{}//Wenn_nicht_=\>_Abbruch\CE{}}}
\L{\LB{}\Tab{10}{\V{c}+=\N{1};}}
\L{\LB{}\Tab{8}{\K{end};}}
\ProcCont{rateDifficulty}\L{\LB{}\Tab{4}{\K{exit}(\V{c}\<\V{length}(\V{positions}[\V{p}]));}}
\L{\LB{}\Tab{2}{\K{end};}}
\ProcCont{decode}\L{\LB{}\Tab{4}{}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\C{}//Initialisieren\CE{}}}
\L{\LB{}\Tab{2}{\V{Randomize};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{6}{\V{put}(\V{i},\V{j},\V{triUnset},\V{smFixed});}}
\L{\LB{}\Tab{2}{\K{if}_\K{not}_\V{assigned}(\V{positions})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{4}{\V{SetLength}(\V{positions},\V{n}*\V{n}*\V{n}*\V{n},\N{1});}}
\L{\LB{}\Tab{4}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{6}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{8}{\K{with}_\V{positions}[\V{n}*\V{n}*\V{i}+\V{j},\N{0}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{10}{\V{u}:=\V{i};}}
\L{\LB{}\Tab{10}{\V{v}:=\V{j};}}
\L{\LB{}\Tab{8}{\K{end};}}
\ProcCont{minimize}\L{\LB{}\Tab{2}{\K{end};}}
\ProcCont{generateEncryption}\L{\LB{}\Tab{2}{\V{c}:=\N{0};}}
\L{\LB{}\Tab{2}{\V{fieldCount}:=\N{0};}}
\L{\LB{}\Tab{2}{\V{maxFieldCount}:=\V{n}*\V{n}*\V{n}*\V{n};}}
\L{\LB{}\Tab{2}{\V{twin}:=\V{clone};}}
\L{\LB{}\Tab{2}{\V{p}:=\V{high}(\V{positions});}}
\L{\LB{}\Tab{2}{\C{}//Generieren\CE{}}}
\L{\LB{}\Tab{2}{\K{repeat}}}
\L{\LB{}\Tab{4}{\C{}//Auswahl_einer_freien_Gruppe\CE{}}}
\L{\LB{}\Tab{4}{\K{repeat}}}
\L{\LB{}\Tab{6}{\V{positions}[\V{p}]:=\V{positions}[\V{high}(\V{positions})\-\V{c}];}}
\L{\LB{}\Tab{6}{\V{p}:=\V{random}(\V{length}(\V{positions})\-\V{c});}}
\L{\LB{}\Tab{6}{\V{fieldCount}+=\V{length}(\V{positions}[\V{p}]);}}
\L{\LB{}\Tab{6}{\V{c}+=\N{1};}}
\L{\LB{}\Tab{4}{\K{until}_(\V{freeFields}(\V{p},\V{tri}))_\K{or}_(\V{c}\>\V{high}(\V{positions}));}}
\L{\LB{}\Tab{4}{\V{fixedTri}:=\V{tri}\<\>\V{triUnset};}}
\L{\LB{}\Tab{4}{\K{if}_\K{not}_\V{fixedTri}_\K{then}_\V{tri}:=\V{trilean}(\V{random}(\N{2})+\N{1});}}
\L{\LB{}\Tab{4}{\C{}//Einfügen_der_Werte\CE{}}}
\L{\LB{}\Tab{4}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{positions}[\V{p}])_\K{do}}}
\L{\LB{}\Tab{6}{\K{with}_\V{positions}[\V{p},\V{i}]_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_\K{not}_(\V{twin.solutionMethod}[\V{u},\V{v}]_\K{in}_\V{UNIQUE\_SOLUTION})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{10}{\K{if}_\V{negate}_\K{then}_\V{put}(\V{u},\V{v},\V{TRI\_NOT}[\V{tri}],_\V{smFixed})}}
\L{\LB{}\Tab{10}{\K{else}_\V{put}(\V{u},\V{v},\V{tri},\V{smFixed});}}
\L{\LB{}\Tab{8}{\K{end};}}
\ProcCont{generate}\L{\LB{}\Tab{4}{\C{}//Lösbarkeit_überprüfen\CE{}}}
\L{\LB{}\Tab{4}{\V{twin.free};\V{twin}:=\V{clone}();}}
\L{\LB{}\Tab{4}{\V{twin.logicalSolve}();}}
\L{\LB{}\Tab{4}{\K{if}_\V{fieldCount}\>=\V{n}*\V{n}*\V{n}*\V{n}_\K{div}_\N{4}_\K{then}}}
\L{\LB{}\Tab{6}{\K{if}_\V{twin.\_solve}(\V{false},\N{0},\K{nil})_=_\N{0}_\K{then}}}
\L{\LB{}\Tab{8}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{positions}[\V{p}])_\K{do}}}
\L{\LB{}\Tab{10}{\K{with}_\V{positions}[\V{p},\V{i}]_\K{do}}}
\L{\LB{}\Tab{12}{\V{put}(\V{u},\V{v},\V{triUnset},\V{smUnknown});}}
\L{\LB{}\Tab{2}{\K{until}_(\V{c}\>=\V{high}(\V{positions}))_\K{or}_(\V{fieldCount}\>=\V{maxFieldCount});}}
\L{\LB{}\Tab{2}{\C{}//Alle_Lösungen_berechnen_und_eine_wählen\CE{}}}
\L{\LB{}\Tab{2}{\V{saveToFile}(\S{}{'}T:\2temp{'}\SE{});}}
\L{\LB{}\Tab{2}{\V{solutions}:=\V{TFPList.Create};}}
\L{\LB{}\Tab{2}{\V{twin}:=\V{clone};}}
\L{\LB{}\Tab{2}{\V{twin.\_solve}(\V{true},\N{0},\V{solutions});}}
\L{\LB{}\Tab{2}{\V{assert}(\V{solutions.count}\>\N{0},\S{}{'}Ungültige_Lösung_generiert{'}\SE{});}}
\L{\LB{}\Tab{2}{\C{}//Besten_Schwierigkeitswert_suchen\CE{}}}
\L{\LB{}\Tab{2}{\V{j}:=\N{0};}}
\L{\LB{}\Tab{2}{\K{case}_\V{difficulty}_\K{of}}}
\L{\LB{}\Tab{4}{\V{dEasy}:_\K{begin}_\C{}//Minimum\CE{}}}
\L{\LB{}\Tab{6}{\V{bestDiff}:=\V{TBidoku}(\V{solutions}[\N{0}])\V{.rateDifficulty};}}
\L{\LB{}\Tab{6}{\K{for}_\V{i}:=\N{1}_\K{to}_\V{solutions.count}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_\V{TBidoku}(\V{solutions}[\V{i}])\V{.rateDifficulty}\<\V{bestDiff}_\K{then}}}
\L{\LB{}\Tab{10}{\V{bestDiff}:=\V{TBidoku}(\V{solutions}[\V{i}])\V{.rateDifficulty};}}
\L{\LB{}\Tab{4}{\K{end};}}
\ProcCont{clone}\L{\LB{}\Tab{4}{\V{dHard}:_\K{begin}_\C{}//Maximum\CE{}}}
\L{\LB{}\Tab{6}{\V{bestDiff}:=\V{TBidoku}(\V{solutions}[\N{0}])\V{.rateDifficulty};}}
\L{\LB{}\Tab{6}{\K{for}_\V{i}:=\N{1}_\K{to}_\V{solutions.count}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_\V{TBidoku}(\V{solutions}[\V{i}])\V{.rateDifficulty}\>\V{bestDiff}_\K{then}}}
\L{\LB{}\Tab{10}{\V{bestDiff}:=\V{TBidoku}(\V{solutions}[\V{i}])\V{.rateDifficulty};}}
\L{\LB{}\Tab{4}{\K{end};}}
\ProcCont{destroy}\L{\LB{}\Tab{4}{\V{dNormal}:_\K{begin}}}
\L{\LB{}\Tab{6}{\C{}//Mittelwert_suchen\CE{}}}
\L{\LB{}\Tab{6}{\V{bestDiff}:=\V{TBidoku}(\V{solutions}[\N{0}])\V{.rateDifficulty};}}
\L{\LB{}\Tab{6}{\K{for}_\V{i}:=\N{1}_\K{to}_\V{solutions.count}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{8}{\V{bestDiff}+=\V{TBidoku}(\V{solutions}[\V{i}])\V{.rateDifficulty};}}
\L{\LB{}\Tab{6}{\V{bestDiff}:=\V{bestDiff}_\K{div}_\V{solutions.count};}}
\L{\LB{}\Tab{4}{\K{end};}}
\ProcCont{updateSize}\L{\LB{}\Tab{2}{\K{end};}}
\ProcCont{create}\L{\LB{}\Tab{2}{\C{}//Minimale_Abweichung_von_Symmetrie_und_Schwierigkeitsgrad\CE{}}}
\L{\LB{}\Tab{2}{\V{value}:=\V{abs}(\V{TBidoku}(\V{solutions}[\N{0}])\V{.rateDifficulty}\-\V{bestDiff})+}}
\L{\LB{}\Tab{9}{\V{TBidoku}(\V{solutions}[\N{0}])\V{.symmetricErrors}(\V{positions});}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{solutions.count}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{4}{\K{if}_\V{abs}(\V{TBidoku}(\V{solutions}[\V{i}])\V{.rateDifficulty}\-\V{bestDiff})+}}
\L{\LB{}\Tab{10}{\V{TBidoku}(\V{solutions}[\V{i}])\V{.symmetricErrors}(\V{positions})\<\V{value}_\K{then}_\K{begin}}}
\L{\LB{}\Tab{6}{\V{value}:=\V{abs}(\V{TBidoku}(\V{solutions}[\V{i}])\V{.rateDifficulty}\-\V{bestDiff})+}}
\L{\LB{}\Tab{13}{\V{TBidoku}(\V{solutions}[\V{i}])\V{.symmetricErrors}(\V{positions});}}
\L{\LB{}\Tab{6}{\V{j}:=\V{i};}}
\L{\LB{}\Tab{4}{\K{end};}}
\ProcCont{getSolutionTime}\L{\LB{}\Tab{2}{\C{}//Bidoku_wurde_gewählt\CE{}}}
\L{\LB{}\Tab{2}{\V{bidoku}:=\V{TBidoku}(\V{solutions}[\V{j}]);}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{6}{\K{if}_(\V{bidoku.solutionMethod}[\V{i},\V{j}]_=_\V{smBacktracking2})_\K{or}}}
\L{\LB{}\Tab{9}{((\V{bidoku.solutionMethod}[\V{i},\V{j}]_=_\V{smBacktracking1})_\K{and}}}
\L{\LB{}\Tab{10}{(\V{solutions.count}\>=\V{MAX\_SOLUTIONS}))_\K{then}}}
\L{\LB{}\Tab{8}{\V{put}(\V{i},\V{j},\V{bidoku.data}[\V{i},\V{j}],\V{smFixed});}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Schwierigkeitsgrad_anpassen\CE{}}}
\L{\LB{}\Tab{2}{\K{case}_\V{difficulty}_\K{of}}}
\L{\LB{}\Tab{4}{\V{dHard}:_\V{minimize};}}
\L{\LB{}\Tab{4}{\V{dEasy}:_\K{begin}}}
\L{\LB{}\Tab{6}{\C{}//Feldpositionen_und_leere_Felder_ermitteln\CE{}}}
\L{\LB{}\Tab{6}{\V{fieldCount}:=\N{0};}}
\L{\LB{}\Tab{6}{\V{SetLength}(\V{positions},\V{n}*\V{n}*\V{n}*\V{n},\N{1});}}
\L{\LB{}\Tab{6}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{8}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}_\K{begin}}}
\L{\LB{}\Tab{10}{\K{if}_\V{data}[\V{i},\V{j}]=\V{triUnset}_\K{then}_\V{fieldCount}+=\N{1};}}
\L{\LB{}\Tab{10}{\K{with}_\V{positions}[\V{n}*\V{n}*\V{i}+\V{j},\N{0}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{12}{\V{u}:=\V{i};}}
\L{\LB{}\Tab{12}{\V{v}:=\V{j};}}
\L{\LB{}\Tab{10}{\K{end};}}
\ProcCont{getSolutionMethod}\L{\LB{}\Tab{6}{\K{end};}}
\ProcCont{get}\L{\LB{}\Tab{6}{\C{}//Zufällig_schwere_Felder_füllen\CE{}}}
\L{\LB{}\Tab{6}{\V{c}:=\N{0};}}
\L{\LB{}\Tab{6}{\K{while}_(\V{fieldCount}\>\N{100})_\K{and}_(\V{c}\<\V{high}(\V{positions}))_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{p}:=\V{random}(\V{length}(\V{positions})\-\V{c});}}
\L{\LB{}\Tab{8}{\K{with}_\V{positions}[\V{p},\N{0}]_\K{do}}}
\L{\LB{}\Tab{10}{\K{if}_(\V{data}[\V{u},\V{v}]=\V{triUnset})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{12}{\V{put}(\V{u},\V{v},\V{bidoku.data}[\V{u},\V{v}],\V{smFixed});}}
\L{\LB{}\Tab{12}{\V{fieldCount}\-=\N{1};}}
\L{\LB{}\Tab{10}{\K{end};}}
\ProcCont{copyField}\L{\LB{}\Tab{8}{\V{positions}[\V{p}]:=\V{positions}[\V{high}(\V{positions})\-\V{c}];}}
\L{\LB{}\Tab{8}{\V{c}+=\N{1};}}
\L{\LB{}\Tab{6}{\K{end};}}
\ProcCont{tryput}\L{\LB{}\Tab{4}{\K{end};}}
\ProcCont{put}\L{\LB{}\Tab{2}{\K{end};}}
\ProcCont{tryput}\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Bidokus_löschen\CE{}}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{solutions.count}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{4}{\K{if}_\V{TBidoku}(\V{solutions}[\V{i}])\<\>\V{twin}_\K{then}}}
\L{\LB{}\Tab{6}{\V{TBidoku}(\V{solutions}[\V{i}])\V{.free};}}
\L{\LB{}\Tab{2}{\V{solutions.free};}}
\L{\LB{}\Tab{2}{\V{twin.free};}}
\L{\LB{\K{end};}}
\ProcCont{put}\L{\LB{}}
\index{TBidoku.generateEncryption}\Proc{TBidoku.generateEncryption}\L{\LB{\K{procedure}_\V{TBidoku.generateEncryption}(\V{s}:_\V{string});}}
\L{\LB{\K{var}_\V{sAsNumber}:_\K{array}_\K{of}_\V{longint};_\C{}//String_im_32er_System\CE{}}}
\L{\LB{}\Tab{4}{\V{sAsBits}:_\K{array}_\K{of}_\V{boolean};}\Tab{33}{\C{}//String_im_2er_System\CE{}}}
\L{\LB{}\Tab{4}{\V{i},\V{j},\V{bit}:\V{longint};}\Tab{33}{\C{}//Schleifenvariablen_und_aktuelles_Bit\CE{}}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\C{}//String_in_Zahl_im_32er_System_umwandeln\CE{}}}
\L{\LB{}\Tab{2}{\V{s}+=\S{}{'}}\Tab{8}{{'}\SE{};}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{sAsNumber},\V{length}(\V{s}));}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{sAsNumber})_\K{do}}}
\L{\LB{}\Tab{4}{\K{case}_\V{s}[\V{i}+\N{1}]_\K{of}}}
\L{\LB{}\Tab{6}{\S{}{'}a{'}\SE{}\V{.\,.}\S{}{'}z{'}\SE{}:_\V{sAsNumber}[\V{i}]:=\V{ord}(\V{s}[\V{i}+\N{1}])\-\V{ord}(\S{}{'}a{'}\SE{})+\N{1};}}
\L{\LB{}\Tab{6}{\S{}{'}A{'}\SE{}\V{.\,.}\S{}{'}Z{'}\SE{}:_\V{sAsNumber}[\V{i}]:=\V{ord}(\V{s}[\V{i}+\N{1}])\-\V{ord}(\S{}{'}A{'}\SE{})+\N{1};}}
\L{\LB{}\Tab{6}{\S{}{'}\-{'}\SE{}:_\V{sAsNumber}[\V{i}]:=\N{27};}}
\L{\LB{}\Tab{6}{\S{}{'}.{'}\SE{}:_\V{sAsNumber}[\V{i}]:=\N{28};}}
\L{\LB{}\Tab{6}{\S{}{'},{'}\SE{}:_\V{sAsNumber}[\V{i}]:=\N{29};}}
\L{\LB{}\Tab{6}{\S{}{'}?{'}\SE{}:_\V{sAsNumber}[\V{i}]:=\N{30};}}
\L{\LB{}\Tab{6}{\S{}{'}!{'}\SE{}:_\V{sAsNumber}[\V{i}]:=\N{31};}}
\L{\LB{}\Tab{6}{\K{else}_\V{sAsNumber}[\V{i}]:=\N{0};}}
\L{\LB{}\Tab{4}{\K{end};}}
\ProcCont{put}\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{2}{\C{}//String_in_Binärzahl_umwandeln\CE{}}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{sAsBits},\V{length}(\V{s})*\N{5});}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{sAsNumber})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{4}{\V{bit}:=\N{0};}}
\L{\LB{}\Tab{4}{\K{while}_\V{sAsNumber}[\V{i}]_\>_\N{0}_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\K{if}_\V{sAsNumber}[\V{i}]_\K{and}_\N{1}_=_\N{1}_\K{then}}}
\L{\LB{}\Tab{8}{\V{sAsBits}[\N{5}*\V{i}+\V{bit}]:=\V{true};}}
\L{\LB{}\Tab{6}{\V{sAsNumber}[\V{i}]:=\V{sAsNumber}[\V{i}]_\K{shr}_\N{1};}}
\L{\LB{}\Tab{6}{\V{bit}+=\N{1};}}
\L{\LB{}\Tab{4}{\K{end};}}
\ProcCont{\_solve}\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{}}
\L{\LB{}\Tab{2}{\C{}//Generieren,_so_dass_alle_freien_Felder_den_entsprechenden_Wert\CE{}}}
\L{\LB{}\Tab{2}{\C{}//erhalten\CE{}}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{6}{\V{put}(\V{i},\V{j},\V{triUnset},\V{smUnknown});}}
\L{\LB{}\Tab{2}{\V{bit}:=\N{0};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\C{}//Freie_Feldwahl_überprüfen\CE{}}}
\L{\LB{}\Tab{6}{\K{if}_\V{data}[\V{i},\V{j}]\<\>\V{triUnset}_\K{then}_\K{continue};}}
\L{\LB{}\Tab{6}{\V{put}(\V{i},\V{j},\V{tri0},\V{smFixed});}}
\L{\LB{}\Tab{6}{\K{if}_\K{not}_\V{isSolvable}()_\K{then}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{put}(\V{i},\V{j},\V{tri0},\V{smLogicCombined});}}
\L{\LB{}\Tab{8}{\K{continue};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\V{put}(\V{i},\V{j},\V{tri0},\V{smFixed});}}
\L{\LB{}\Tab{6}{\K{if}_\K{not}_\V{isSolvable}()_\K{then}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{put}(\V{i},\V{j},\V{tri1},\V{smLogicCombined});}}
\L{\LB{}\Tab{8}{\K{continue};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\C{}//Bit\CE{}}}
\L{\LB{}\Tab{6}{\K{if}_\V{sAsBits}[\V{bit}]_\K{then}_\V{put}(\V{i},\V{j},\V{tri1},\V{smFixed})}}
\L{\LB{}\Tab{6}{\K{else}_\V{put}(\V{i},\V{j},\V{tri0},\V{smFixed});}}
\L{\LB{}\Tab{6}{\V{bit}+=\N{1};}}
\L{\LB{}\Tab{6}{\K{if}_\V{bit}\>\V{high}(\V{sAsBits})_\K{then}_\K{break};}}
\L{\LB{}\Tab{6}{\V{logicalSolve}();}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{4}{\K{if}_\V{bit}\>\V{high}(\V{sAsBits})_\K{then}_\K{break};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{6}{\K{if}_\V{solutionMethod}[\V{i},\V{j}]_\K{in}_\V{LOGICAL\_SOLUTION}_\K{then}}}
\L{\LB{}\Tab{8}{\V{put}(\V{i},\V{j},\V{triUnset},\V{smUnknown});}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Minimiert_das_Bidoku\CE{}}}
\index{TBidoku.minimize}\Proc{TBidoku.minimize}\L{\LB{\K{procedure}_\V{TBidoku.minimize};}}
\L{\LB{\K{var}_\V{i},\V{j}:\V{longint};}\Tab{31}{\C{}//Schleifenvariablen\CE{}}}
\L{\LB{}\Tab{4}{\V{positions}:\K{array}_\K{of}_\V{tpoint};_\C{}//Alle_möglichen_Feldpositionen\CE{}}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\C{}//Alle_möglichen_Positionen_in_ein_Array_eintragen\CE{}}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{positions},\V{n}*\V{n}*\V{n}*\V{n});}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\K{with}_\V{positions}[\V{n}*\V{n}*\V{i}+\V{j}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{x}:=\V{i};}}
\L{\LB{}\Tab{8}{\V{y}:=\V{j};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\C{}//Feste_Felder_markieren_(nur_zur_Sicherheit,_eigentlich_unnötig)\CE{}}}
\L{\LB{}\Tab{6}{\K{if}_\V{data}[\V{i},\V{j}]\<\>\V{triUnset}_\K{then}}}
\L{\LB{}\Tab{8}{\V{solutionMethod}[\V{i},\V{j}]:=\V{smFixed};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{2}{\C{}//Alle_Felder_in_zufälliger_Reihenfolge_besuchen_und_dann\CE{}}}
\L{\LB{}\Tab{2}{\C{}//auf_ihre_Notwendigkeit_überprüfen\CE{}}}
\L{\LB{}\Tab{2}{\V{j}:=\N{0};}}
\L{\LB{}\Tab{2}{\K{while}_\V{j}\<=\V{high}(\V{positions})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{4}{\V{i}:=\V{random}(\V{length}(\V{positions})\-\V{j});}}
\L{\LB{}\Tab{4}{\K{with}_\V{positions}[\V{i}]_\K{do}}}
\L{\LB{}\Tab{6}{\K{if}_\V{data}[\V{x},\V{y}]_\<\>_\V{triUnset}_\K{then}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{put}(\V{x},\V{y},\V{TRI\_NOT}[\V{data}[\V{x},\V{y}]],\V{smFixed});}}
\L{\LB{}\Tab{8}{\K{if}_\V{isSolvable}()_\K{then}_\V{put}(\V{x},\V{y},\V{TRI\_NOT}[\V{data}[\V{x},\V{y}]],\V{smFixed})_\C{}//zurücksetzen\CE{}}}
\L{\LB{}\Tab{8}{\K{else}_\V{put}(\V{x},\V{y},\V{triUnset},\V{smUnknown});}\Tab{65}{\C{}//löschen\CE{}}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{4}{\V{positions}[\V{i}]:=\V{positions}[\V{high}(\V{positions})\-\V{j}];}}
\L{\LB{}\Tab{4}{\V{j}+=\N{1};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Findet_den_im_Bidoku_verborgenen_Text\CE{}}}
\index{TBidoku.decode}\Proc{TBidoku.decode}\L{\LB{\K{function}_\V{TBidoku.decode}():_\V{string};}}
\L{\LB{\K{var}_\V{bits}:_\K{array}_\K{of}_\V{boolean};}\Tab{30}{\C{}//String_als_Bitfolge\CE{}}}
\L{\LB{}\Tab{4}{\V{number}:_\K{array}_\K{of}_\V{longint};_\C{}//String_als_Zahl_im_32er_Sytem\CE{}}}
\L{\LB{}\Tab{4}{\V{i},\V{j},\V{bit}:\V{longint};}\Tab{30}{\C{}//Schleifen,_aktuelles_Bit\CE{}}}
\L{\LB{}\Tab{4}{\V{bidoku}:_\V{TBidoku};}\Tab{30}{\C{}//Bidoku,_das_gefüllt_wird\CE{}}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{bits},\V{length}(\V{data})*\V{length}(\V{data}));}}
\L{\LB{}\Tab{2}{\V{fillchar}(\V{bits}[\N{0}],\V{sizeof}(\V{bits}[\N{0}])*\V{length}(\V{bits}),\N{0});}}
\L{\LB{}\Tab{2}{\C{}//Generieren\CE{}}}
\L{\LB{}\Tab{2}{\V{bidoku}:=\V{TBidoku.create};}}
\L{\LB{}\Tab{2}{\V{bit}:=\N{0};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\K{if}_\V{bidoku.data}[\V{i},\V{j}]\<\>\V{triUnset}_\K{then}_\K{continue};}}
\L{\LB{}\Tab{6}{\C{}//Freie_Feldwahl_überprüfen\CE{}}}
\L{\LB{}\Tab{6}{\V{bidoku.put}(\V{i},\V{j},\V{tri0},\V{smFixed});}}
\L{\LB{}\Tab{6}{\K{if}_\K{not}_\V{bidoku.isSolvable}()_\K{then}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{bidoku.put}(\V{i},\V{j},\V{tri1},\V{smFixed});}}
\L{\LB{}\Tab{8}{\K{continue};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\V{bidoku.put}(\V{i},\V{j},\V{tri0},\V{smFixed});}}
\L{\LB{}\Tab{6}{\K{if}_\K{not}_\V{isSolvable}()_\K{then}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{bidoku.put}(\V{i},\V{j},\V{tri1},\V{smFixed});}}
\L{\LB{}\Tab{8}{\K{continue};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\V{bidoku.put}(\V{i},\V{j},\V{data}[\V{i},\V{j}],\V{smFixed});}}
\L{\LB{}\Tab{6}{\V{bidoku.logicalSolve}();}}
\L{\LB{}\Tab{6}{\C{}//Bit\CE{}}}
\L{\LB{}\Tab{6}{\V{bits}[\V{bit}]:=\V{data}[\V{i},\V{j}]=\V{tri1};}}
\L{\LB{}\Tab{6}{\V{bit}+=\N{1};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Binärzahl_in_32er_System_umwandeln\CE{}}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{number},\V{bit}_\K{div}_\N{5});}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{number})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{4}{\V{number}[\V{i}]:=\N{0};}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{4}_\K{downto}_\N{0}_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\V{number}[\V{i}]*=\N{2};}}
\L{\LB{}\Tab{6}{\K{if}_\V{bits}[\V{j}+\N{5}*\V{i}]_\K{then}_\V{number}[\V{i}]+=\N{1};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Zahl_in_String_umwandeln\CE{}}}
\L{\LB{}\Tab{2}{\V{result}:=\S{}{'}{'}\SE{};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{number})_\K{do}}}
\L{\LB{}\Tab{4}{\K{case}_\V{number}[\V{i}]_\K{of}}}
\L{\LB{}\Tab{6}{\N{1}\V{.\,.26}:\V{result}+=\V{chr}(\V{number}[\V{i}]+\V{ord}(\S{}{'}a{'}\SE{})\-\N{1});}}
\L{\LB{}\Tab{6}{\N{27}:_\V{result}+=\S{}{'}\-{'}\SE{};}}
\L{\LB{}\Tab{6}{\N{28}:_\V{result}+=\S{}{'}.{'}\SE{};}}
\L{\LB{}\Tab{6}{\N{29}:_\V{result}+=\S{}{'},{'}\SE{};}}
\L{\LB{}\Tab{6}{\N{30}:_\V{result}+=\S{}{'}?{'}\SE{};}}
\L{\LB{}\Tab{6}{\N{31}:_\V{result}+=\S{}{'}!{'}\SE{};}}
\L{\LB{}\Tab{6}{\K{else}_\V{result}+=\S{}{'}_{'}\SE{}}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}//Öffentliche_Lösungsmethode\CE{}}}
\index{TBidoku.solve}\Proc{TBidoku.solve}\L{\LB{\K{function}_\V{TBidoku.solve}(\V{allSolutions},\V{list}:_\V{boolean}):\V{TSolveResult};}}
\L{\LB{\K{var}_\V{i},\V{j}:\V{longint};}}
\L{\LB{}\Tab{4}{\V{wtime}:_\V{cardinal};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{wtime}:=\V{GetTickCount};}}
\L{\LB{}\Tab{2}{\K{if}_\V{list}_\K{then}_\V{result.solutions}:=\V{TFPList.create}}}
\L{\LB{}\Tab{2}{\K{else}_\V{result.solutions}:=\K{nil};}}
\L{\LB{}\Tab{2}{\C{}//Markiere_festgelegte_Felder\CE{}}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}}}
\L{\LB{}\Tab{5}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{7}{\K{if}_\V{data}[\V{i},\V{j}]=\V{triUnset}_\K{then}_\V{solutionMethod}[\V{i},\V{j}]:=\V{smUnknown}}}
\L{\LB{}\Tab{7}{\K{else}_\V{solutionMethod}[\V{i},\V{j}]:=\V{smFixed};}}
\L{\LB{}\Tab{2}{\C{}//Eigentliches_Lösungsverfahren_aufrufen\CE{}}}
\L{\LB{}\Tab{2}{\V{result.solutioncount}:=\V{\_solve}(\V{allSolutions},\N{0},\V{result.solutions});}}
\L{\LB{}\Tab{2}{\C{}//Ergebnisse_setzen\CE{}}}
\L{\LB{}\Tab{2}{\V{result.solved}:=\V{result.solutioncount}\>\N{0};}}
\L{\LB{}\Tab{2}{\K{if}_(\V{result.solutions}\<\>\K{nil})\K{and}(\V{result.solutions.count}\>\N{0})_\K{and}}}
\L{\LB{}\Tab{5}{(\V{Tbidoku}(\V{result.solutions}[\N{0}])=\V{Self})_\K{then}}}
\L{\LB{}\Tab{4}{\V{result.solutions}[\N{0}]:=\V{clone};}}
\L{\LB{}\Tab{2}{\V{OutputDebugString}(\V{pchar}(\V{IntToStr}(\V{GetTickCount}\-\V{wtime})));}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Überprüft,_ob_es_eine_Lösung_gibt,_indem_das_Rätsel_geklont_und_gelöst_wird\CE{}}}
\index{TBidoku.issolvable}\Proc{TBidoku.issolvable}\L{\LB{\K{function}_\V{TBidoku.issolvable}():_\V{boolean};}}
\L{\LB{\K{var}_\V{temp}:_\V{TBidoku};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{temp}:=\V{clone}();}}
\L{\LB{}\Tab{2}{\V{result}:=\V{temp.\_solve}(\V{false},\N{0},\K{nil})\>\N{0};}}
\L{\LB{}\Tab{2}{\V{temp.free};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//In_einen_String_umwandeln\CE{}}}
\index{TBidoku.toString}\Proc{TBidoku.toString}\L{\LB{\K{function}_\V{TBidoku.toString}():_\V{string};}}
\L{\LB{\K{var}_\V{i},\V{j}:_\V{longint};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{result}:=\S{}{'}{'}\SE{};}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}_\K{begin}_\C{}//Zeilen\CE{}}}
\L{\LB{}\Tab{4}{\K{if}_\V{i}_\K{mod}_\V{n}_=_\N{0}_\K{then}_\K{begin}}}
\L{\LB{}\Tab{6}{\C{}//Trennlinie_einfügen\CE{}}}
\L{\LB{}\Tab{6}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_\V{j}_\K{mod}_\V{n}_=_\N{0}_\K{then}_\V{result}+=\S{}{'}\|\-{'}\SE{}}}
\L{\LB{}\Tab{8}{\K{else}_\V{result}+=\S{}{'}\-{'}\SE{};}}
\L{\LB{}\Tab{6}{\V{result}+=\S{}{'}\|{'}\SE{}\V{\#13}\V{\#10};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}_\K{begin}_\C{}//Spalten\CE{}}}
\L{\LB{}\Tab{6}{\K{if}_\V{j}_\K{mod}_\V{n}_=_\N{0}_\K{then}}}
\L{\LB{}\Tab{8}{\V{result}+=\S{}{'}\|{'}\SE{};_\C{}//Trennspalte\CE{}}}
\L{\LB{}\Tab{6}{\K{case}_\V{data}[\V{j},\V{i}]_\K{of}}}
\L{\LB{}\Tab{8}{\V{triUnset}:_\V{result}+=\S{}{'}_{'}\SE{};}}
\L{\LB{}\Tab{8}{\V{tri0}:_\V{result}+=\S{}{'}0{'}\SE{};}}
\L{\LB{}\Tab{8}{\V{tri1}:_\V{result}+=\S{}{'}1{'}\SE{};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{4}{\V{result}:=\V{result}+\S{}{'}\|{'}\SE{}\V{\#13}\V{\#10};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{\C{}//Schlusslinie\CE{}}}
\L{\LB{}\Tab{2}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{4}{\K{if}_\V{j}_\K{mod}_\V{n}_=_\N{0}_\K{then}_\V{result}+=\S{}{'}\|\-{'}\SE{}}}
\L{\LB{}\Tab{4}{\K{else}_\V{result}+=\S{}{'}\-{'}\SE{};}}
\L{\LB{}\Tab{2}{\V{result}+=\S{}{'}\|{'}\SE{}\V{\#13}\V{\#10};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Speichern\CE{}}}
\index{TBidoku.saveToFile}\Proc{TBidoku.saveToFile}\L{\LB{\K{procedure}_\V{TBidoku.saveToFile}(\V{fn}:_\V{string});}}
\L{\LB{\K{var}_\V{f}:_\V{TFileStream};}}
\L{\LB{}\Tab{4}{\V{str}:_\V{string};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{f}:=\V{TFileStream.Create}(\V{fn},\V{fmCreate});}}
\L{\LB{}\Tab{2}{\V{str}:=\V{toString}();}}
\L{\LB{}\Tab{2}{\V{f.WriteBuffer}(\V{str}[\N{1}],\V{length}(\V{str}));}}
\L{\LB{}\Tab{2}{\V{f.free};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Laden\CE{}}}
\index{TBidoku.loadFromFile}\Proc{TBidoku.loadFromFile}\L{\LB{\K{procedure}_\V{TBidoku.loadFromFile}(\V{fn}:_\V{string});}}
\L{\LB{\K{var}_\V{f}:_\V{TFileStream};}}
\L{\LB{}\Tab{4}{\V{str}:\V{string};}}
\L{\LB{}\Tab{4}{\V{p},\V{i},\V{j}:\V{longint};_\C{}//Stringposition,_Spalte,_Zeile\CE{}}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\C{}//Dateiinhalt_in_einen_String_kopieren\CE{}}}
\L{\LB{}\Tab{2}{\V{f}:=\V{TFileStream.Create}(\V{fn},\V{fmOpenRead});}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{str},\V{f.Size}\-\N{1});}}
\L{\LB{}\Tab{2}{\V{f.ReadBuffer}(\V{str}[\N{1}],\V{length}(\V{str}));}}
\L{\LB{}\Tab{2}{\V{f.free};}}
\L{\LB{}\Tab{2}{}}
\L{\LB{}}
\L{\LB{}\Tab{2}{\C{}//Fehlertolerantes_Lesen\CE{}}}
\L{\LB{}\Tab{2}{\C{}//Länge_ermitteln_(n\52+n+1=a_=\>_n=-0.5+-sqrt(0.25-(1-a))=-0.5+-sqrt(a-0.75))\CE{}}}
\L{\LB{}\Tab{2}{\K{for}_\V{p}:=\N{1}_\K{to}_\V{length}(\V{str})_\K{do}}}
\L{\LB{}\Tab{4}{\K{if}_\V{str}[\V{p}]_\K{in}_[\V{\#13},\V{\#10}]_\K{then}_\K{begin}}}
\L{\LB{}\Tab{6}{\V{n}:=\V{trunc}(\V{sqrt}(\V{p}\-\N{0.75}));}}
\L{\LB{}\Tab{6}{\V{updateSize}();}}
\L{\LB{}\Tab{6}{\K{break};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{2}{\V{i}:=\N{0};}}
\L{\LB{}\Tab{2}{\V{j}:=\N{0};}}
\L{\LB{}\Tab{2}{\K{for}_\V{p}:=\V{n}*\V{n}+\V{n}+\N{1}_\K{to}_\V{length}(\V{str})_\K{do}}}
\L{\LB{}\Tab{4}{\K{if}_\V{str}[\V{p}]_\K{in}_[\S{}{'}0{'}\SE{},\S{}{'}1{'}\SE{},\S{}{'}O{'}\SE{},\S{}{'}X{'}\SE{},\S{}{'}_{'}\SE{}]_\K{then}_\K{begin}}}
\L{\LB{}\Tab{6}{\K{if}_\V{str}[\V{p}]_\K{in}_[\S{}{'}0{'}\SE{},\S{}{'}O{'}\SE{}]_\K{then}_\V{put}(\V{j},\V{i},\V{tri0},\V{smFixed})}}
\L{\LB{}\Tab{6}{\K{else}_\K{if}_\V{str}[\V{p}]_\K{in}_[\S{}{'}1{'}\SE{},\S{}{'}X{'}\SE{}]_\K{then}_\V{put}(\V{j},\V{i},\V{tri1},\V{smFixed})}}
\L{\LB{}\Tab{6}{\K{else}_\V{put}(\V{j},\V{i},\V{triUnset},\V{smFixed});}}
\L{\LB{}\Tab{6}{\V{j}+=\N{1};}}
\L{\LB{}\Tab{6}{\K{if}_\V{j}\>\V{high}(\V{data})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{j}:=\N{0};}}
\L{\LB{}\Tab{8}{\V{i}+=\N{1};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Erzeugt_eine_horizontale_Spiegelung_um_die_Bidokumitte\CE{}}}
\index{TBidoku.makeMirrorSymmetryH}\Proc{TBidoku.makeMirrorSymmetryH}\L{\LB{\K{function}_\V{TBidoku.makeMirrorSymmetryH}(\V{invert}:_\V{boolean}):_\V{TPositionsArray};}}
\L{\LB{\K{var}_\V{i},\V{j}:\V{longint};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{result},\V{length}(\V{data})*\V{length}(\V{data})\K{div}_\N{2},\N{2});}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{div}_\N{2}_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[\V{i}*\V{length}(\V{data})+\V{j},\N{0}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{i};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{false};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[\V{i}*\V{length}(\V{data})+\V{j},\N{1}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{high}(\V{data})\-\V{i};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{invert};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Erzeugt_eine_vertikale_Spiegelung_um_die_Bidokumitte\CE{}}}
\index{TBidoku.makeMirrorSymmetryV}\Proc{TBidoku.makeMirrorSymmetryV}\L{\LB{\K{function}_\V{TBidoku.makeMirrorSymmetryV}(\V{invert}:_\V{boolean}):_\V{TPositionsArray};}}
\L{\LB{\K{var}_\V{i},\V{j}:\V{longint};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{result},\V{length}(\V{data})*\V{length}(\V{data})\K{div}_\N{2},\N{2});}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{div}_\N{2}_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[\V{i}*\V{length}(\V{data})+\V{j},\N{0}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{i};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{false};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[\V{i}*\V{length}(\V{data})+\V{j},\N{1}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{high}(\V{data})\-\V{i};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{invert};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Erzeugt_eine_horizontale_Spiegelung_um_die_Mitte_der_einen_und\CE{}}}
\L{\LB{\C{}//der_anderen_Hälft_des_Bidokus\CE{}}}
\index{TBidoku.makeMirrorSymmetrySubH}\Proc{TBidoku.makeMirrorSymmetrySubH}\L{\LB{\K{function}_\V{TBidoku.makeMirrorSymmetrySubH}(\V{invert}:_\V{boolean}):_\V{TPositionsArray};}}
\L{\LB{\K{var}_\V{i},\V{j}:\V{longint};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{result},\V{length}(\V{data})*\V{length}(\V{data})\K{div}_\N{2},\N{2});}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{div}_\N{4}_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[\V{i}*\V{length}(\V{data})+\V{j},\N{0}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{i};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{false};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[\V{i}*\V{length}(\V{data})+\V{j},\N{1}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{high}(\V{data})_\K{div}_\N{2}\-\V{i};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{invert};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[(\V{i}+\V{length}(\V{data})_\K{div}_\N{4})*\V{length}(\V{data})+\V{j},\N{0}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{i}+\V{length}(\V{data})_\K{div}_\N{2};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{false};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[(\V{i}+\V{length}(\V{data})_\K{div}_\N{4})*\V{length}(\V{data})+\V{j},\N{1}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{high}(\V{data})\-\V{i};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{invert};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{\C{}//Erzeugt_eine_vertikale_Spiegelung_um_die_Mitte_der_einen_und\CE{}}}
\L{\LB{\C{}//der_anderen_Hälft_des_Bidokus\CE{}}}
\index{TBidoku.makeMirrorSymmetrySubV}\Proc{TBidoku.makeMirrorSymmetrySubV}\L{\LB{\K{function}_\V{TBidoku.makeMirrorSymmetrySubV}(\V{invert}:_\V{boolean}):_\V{TPositionsArray};}}
\L{\LB{\K{var}_\V{i},\V{j}:\V{longint};}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\V{SetLength}(\V{result},\V{length}(\V{data})*\V{length}(\V{data})\K{div}_\N{2},\N{2});}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{div}_\N{4}_\K{do}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{data})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[\V{i}*\V{length}(\V{data})+\V{j},\N{0}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{i};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{false};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[\V{i}*\V{length}(\V{data})+\V{j},\N{1}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{high}(\V{data})_\K{div}_\N{2}\-\V{i};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{invert};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[(\V{i}+\V{length}(\V{data})_\K{div}_\N{4})*\V{length}(\V{data})+\V{j},\N{0}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{i}+\V{length}(\V{data})_\K{div}_\N{2};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{false};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\K{with}_\V{result}[(\V{i}+\V{length}(\V{data})_\K{div}_\N{4})*\V{length}(\V{data})+\V{j},\N{1}]_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{u}:=\V{j};}}
\L{\LB{}\Tab{8}{\V{v}:=\V{high}(\V{data})\-\V{i};}}
\L{\LB{}\Tab{8}{\V{negate}:=\V{invert};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{\C{}//Verbindet_zwei_Muster\CE{}}}
\index{TBidoku.mergeSymmetry}\Proc{TBidoku.mergeSymmetry}\L{\LB{\K{function}_\V{TBidoku.mergeSymmetry}(\V{a},_\V{b}:_\V{TPositionsArray}):_\V{TPositionsArray};}}
\L{\LB{}\Tab{2}{\C{}//Berechnet_alle_Schnitte_zwischen_den_Gruppen_g_und_h\CE{}}}
\L{\LB{}\Tab{2}{\C{}//und_gibt_zurück,_ob_diese_Schnittstelle_die_eine_Gruppe_invertiert\CE{}}}
\index{groupIntersection}\Proc{groupIntersection}\L{\LB{}\Tab{2}{\K{function}_\V{groupIntersection}(\K{const}_\V{g},\V{h}:\V{TPositionGroup};\V{out}_\V{negate}:_\V{boolean}):\V{boolean};}}
\L{\LB{}\Tab{2}{\K{var}_\V{i},\V{j}:\V{longint};}}
\L{\LB{}\Tab{2}{\K{begin}}}
\L{\LB{}\Tab{4}{\V{result}:=\V{false};}}
\L{\LB{}\Tab{4}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{g})_\K{do}}}
\L{\LB{}\Tab{6}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{h})_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_(\V{h}[\V{j}]\V{.u}=\V{g}[\V{i}]\V{.u})_\K{and}_(\V{g}[\V{i}]\V{.v}=\V{h}[\V{j}]\V{.v})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{10}{\K{if}_\V{result}_\K{then}}}
\L{\LB{}\Tab{12}{\V{assert}((\V{g}[\V{i}]\V{.negate}_\K{xor}_\V{h}[\V{j}]\V{.negate})=\V{negate},\S{}{'}Symmetrien_unpassend{'}\SE{})}}
\L{\LB{}\Tab{11}{\K{else}}}
\L{\LB{}\Tab{12}{\V{negate}:=\V{g}[\V{i}]\V{.negate}_\K{xor}_\V{h}[\V{j}]\V{.negate};}}
\L{\LB{}\Tab{10}{\V{result}:=\V{true};}}
\L{\LB{}\Tab{8}{\K{end};}}
\ProcCont{TBidoku.mergeSymmetry}\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{}}
\L{\LB{}\Tab{2}{\C{}//Fügt_die_Gruppe_h_zur_Gruppe_g_hinzu\CE{}}}
\index{addPositionGroup}\Proc{addPositionGroup}\L{\LB{}\Tab{2}{\K{procedure}_\V{addPositionGroup}(\K{var}_\V{g},\V{h}:\V{TPositionGroup};\V{negate}:_\V{boolean});}}
\L{\LB{}\Tab{2}{\K{var}_\V{i},\V{j}:\V{longint};}}
\L{\LB{}\Tab{6}{\V{found}:\V{boolean};_\C{}//Feld_existiert_schon_in_Gruppe_g\CE{}}}
\L{\LB{}\Tab{2}{\K{begin}}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{h})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\V{found}:=\V{false};}}
\L{\LB{}\Tab{6}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{g})_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_(\V{h}[\V{j}]\V{.u}=\V{g}[\V{i}]\V{.u})_\K{and}_(\V{g}[\V{i}]\V{.v}=\V{h}[\V{j}]\V{.v})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{10}{\V{found}:=\V{true};}}
\L{\LB{}\Tab{10}{\K{break};}}
\L{\LB{}\Tab{8}{\K{end};}}
\L{\LB{}\Tab{8}{\K{if}_\K{not}_\V{found}_\K{then}_\K{begin}}}
\L{\LB{}\Tab{10}{\V{SetLength}(\V{g},\V{length}(\V{g})+\N{1});}}
\L{\LB{}\Tab{10}{\V{g}[\V{high}(\V{g})]:=\V{h}[\V{j}];}}
\L{\LB{}\Tab{10}{\K{if}_\V{negate}_\K{then}_\K{with}_\V{g}[\V{high}(\V{g})]_\K{do}}}
\L{\LB{}\Tab{12}{\V{negate}:=\K{not}_\V{negate};}}
\L{\LB{}\Tab{8}{\K{end};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}}
\L{\LB{\K{var}_\V{i},\V{j},\V{p}:\V{longint};_\C{}//Schleifenvariablen_und_Anzahl_zurückgegebener_Gruppen\CE{}}}
\L{\LB{}\Tab{4}{\V{negate},\V{groupchanged}:\V{boolean};_\C{}//Wurde_die_Gruppe_negiert/geändert?\CE{}}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\K{if}_\V{a}=\K{nil}_\K{then}_\K{exit}(\V{b});}}
\L{\LB{}\Tab{2}{\K{if}_\V{b}=\K{nil}_\K{then}_\K{exit}(\V{a});}}
\L{\LB{}\Tab{2}{\C{}//a_mit_b_verbinden\CE{}}}
\L{\LB{}\Tab{2}{\V{setlength}(\V{result},\V{length}(\V{a}));}}
\L{\LB{}\Tab{2}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{a})_\K{do}_\K{begin}}}
\L{\LB{}\Tab{4}{\V{setlength}(\V{result}[\V{i}],\V{length}(\V{a}[\V{i}]));}}
\L{\LB{}\Tab{4}{\V{move}(\V{a}[\V{i},\N{0}],\V{result}[\V{i},\N{0}],\V{length}(\V{a}[\V{i}])*\V{sizeof}(\V{a}[\V{i},\N{0}]));}}
\L{\LB{}\Tab{4}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{b})_\K{do}}}
\L{\LB{}\Tab{7}{\K{if}_\V{groupIntersection}(\V{a}[\V{i}],\V{b}[\V{j}],\V{negate})_\K{then}}}
\L{\LB{}\Tab{9}{\V{addPositionGroup}(\V{result}[\V{i}],\V{b}[\V{j}],\V{negate});}}
\L{\LB{}\Tab{2}{\K{end};}}
\L{\LB{}\Tab{2}{\C{}//Gruppen_mit_gemeinsamen_Feldern_suchen\CE{}}}
\L{\LB{}\Tab{2}{\V{p}:=\V{high}(\V{result});}}
\L{\LB{}\Tab{2}{\K{repeat}}}
\L{\LB{}\Tab{4}{\V{groupchanged}:=\V{false};}}
\L{\LB{}\Tab{4}{\K{for}_\V{i}:=\V{p}_\K{downto}_\N{0}_\K{do}}}
\L{\LB{}\Tab{6}{\K{for}_\V{j}:=\V{p}_\K{downto}_\V{i}+\N{1}_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_\V{groupIntersection}(\V{result}[\V{i}],\V{result}[\V{j}],\V{negate})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{10}{\V{addPositionGroup}(\V{result}[\V{i}],\V{result}[\V{j}],\V{negate});}}
\L{\LB{}\Tab{10}{\V{result}[\V{j}]:=\V{result}[\V{p}];}}
\L{\LB{}\Tab{10}{\V{p}\-=\N{1};}}
\L{\LB{}\Tab{10}{\V{groupchanged}:=\V{true};}}
\L{\LB{}\Tab{8}{\K{end};}}
\L{\LB{}\Tab{2}{\K{until}_\K{not}_\V{groupchanged};}}
\L{\LB{}\Tab{2}{\V{setlength}(\V{result},\V{p}+\N{1})}}
\L{\LB{\K{end};}}
\L{\LB{}}
\L{\LB{}}
\index{TBidoku.logicalSolve}\Proc{TBidoku.logicalSolve}\L{\LB{\K{procedure}_\V{TBidoku.logicalSolve}();}}
\L{\LB{\K{var}_\V{waschanged}:_\V{boolean};_\C{}//Gab_es_eine_Änderung?\CE{}}}
\L{\LB{}\Tab{4}{\V{i},\V{j},\V{k},\V{l}:\V{longint};}\Tab{25}{\C{}//Schleifenvariablen\CE{}}}
\L{\LB{}\Tab{4}{\V{num},\V{num2}:_\V{trilean};}\Tab{25}{\C{}//Aktuelle_Zahl_und_invertierte\CE{}}}
\L{\LB{}\Tab{4}{\V{count}:\V{longint};}\Tab{25}{\C{}//Anzahl_der_gefüllten_Felder\CE{}}}
\L{\LB{\K{begin}}}
\L{\LB{}\Tab{2}{\K{repeat}}}
\L{\LB{}\Tab{4}{\V{waschanged}:=\V{false};}}
\L{\LB{}\Tab{4}{\C{}//Vervollständigen_von_Reihen\CE{}}}
\L{\LB{}\Tab{4}{\K{repeat}}}
\L{\LB{}\Tab{6}{\V{num2}:=\V{tri1};}}
\L{\LB{}\Tab{6}{\K{for}_\V{num}:=\V{tri0}_\K{to}_\V{tri1}_\K{do}_\K{begin}}}
\L{\LB{}\Tab{8}{\V{changed}:=\V{false};}}
\L{\LB{}\Tab{8}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{cols})_\K{do}}}
\L{\LB{}\Tab{10}{\K{if}_(\V{cols}[\V{i}][\V{num}]=\V{maxcount})_\K{and}_(\V{cols}[\V{i}][\V{num2}]\<\V{maxcount})_\K{then}}}
\L{\LB{}\Tab{12}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{rows})_\K{do}}}
\L{\LB{}\Tab{14}{\V{tryPut}(\V{i},\V{j},\V{num2},\V{smLogicTrivial});}}
\L{\LB{}\Tab{8}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{rows})_\K{do}}}
\L{\LB{}\Tab{10}{\K{if}_(\V{rows}[\V{i}][\V{num}]=\V{maxcount})_\K{and}_(\V{rows}[\V{i}][\V{num2}]\<\V{maxcount})_\K{then}}}
\L{\LB{}\Tab{12}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{cols})_\K{do}}}
\L{\LB{}\Tab{14}{\V{tryPut}(\V{j},\V{i},\V{num2},\V{smLogicTrivial});}}
\L{\LB{}\Tab{8}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{quadrates})_\K{do}}}
\L{\LB{}\Tab{10}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{quadrates}[\V{i}])_\K{do}}}
\L{\LB{}\Tab{12}{\K{if}_(\V{quadrates}[\V{i}][\V{j}][\V{num}]=\V{maxcount})_\K{and}}}
\L{\LB{}\Tab{15}{(\V{quadrates}[\V{i}][\V{j}][\V{num2}]\<\V{maxcount})_\K{then}}}
\L{\LB{}\Tab{14}{\K{for}_\V{k}:=\V{i}*\V{n}_\K{to}_\V{i}*\V{n}+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{16}{\K{for}_\V{l}:=\V{j}*\V{n}_\K{to}_\V{j}*\V{n}+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{18}{\V{tryPut}(\V{k},\V{l},\V{num2},\V{smLogicTrivial});}}
\L{\LB{}\Tab{8}{\V{num2}:=\V{num};}}
\L{\LB{}\Tab{6}{\K{end};}}
\L{\LB{}\Tab{6}{\V{waschanged}:=\V{waschanged}_\K{or}_\V{changed};}}
\L{\LB{}\Tab{4}{\K{until}_\K{not}_\V{changed};}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\V{changed}:=\V{waschanged};}}
\L{\LB{}\Tab{4}{}}
\L{\LB{}\Tab{4}{\V{num2}:=\V{tri1};}}
\L{\LB{}\Tab{4}{\K{for}_\V{num}:=\V{tri0}_\K{to}_\V{tri1}_\K{do}_\K{begin}}}
\L{\LB{}\Tab{6}{\C{}//Prüfe,_wo_nur_wenige_von_einer_Sorte_eingefügt_werden_können_und_deshalb\CE{}}}
\L{\LB{}\Tab{6}{\C{}//von_der_anderen_Sorte_soviele_eingefügt_werden_müssen_das_ein_Bereich\CE{}}}
\L{\LB{}\Tab{6}{\C{}//voll_ist\CE{}}}
\L{\LB{}\Tab{6}{\C{}//Spalte_=\>_bekanntes_Quadrat\CE{}}}
\L{\LB{}\Tab{6}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{cols})_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_(\V{cols}[\V{i}][\V{num}]\>\V{maxcount}\-\V{n})}}
\L{\LB{}\Tab{12}{\K{and}_(\V{cols}[\V{i}][\V{num}]+\V{cols}[\V{i}][\V{num2}]\<\N{2}*\V{maxcount})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{10}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{quadrates}[\N{0}])_\K{do}}}
\L{\LB{}\Tab{12}{\K{if}_(\V{quadrates}[\V{i}_\K{div}_\V{n},\V{j}][\V{num2}]+\V{n}\-(\V{maxcount}\-\V{cols}[\V{i}][\V{num}])\>=\V{maxcount})_\K{and}}}
\L{\LB{}\Tab{15}{(\V{quadrates}[\V{i}_\K{div}_\V{n},\V{j}][\V{num}]+\V{quadrates}[\V{i}_\K{div}_\V{n},\V{j}][\V{num2}]}}
\L{\LB{}\Tab{17}{\<\N{2}*\V{maxcount})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{14}{\V{count}:=\N{0};}}
\L{\LB{}\Tab{14}{\K{for}_\V{k}:=\V{j}*\V{n}_\K{to}_\V{j}*\V{n}+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{16}{\K{if}_\V{data}[\V{i},\V{k}]=\V{triUnset}_\K{then}_\V{inc}(\V{count});}}
\L{\LB{}\Tab{14}{\K{if}_(\V{quadrates}[\V{i}_\K{div}_\V{n},\V{j}][\V{num2}]+\V{count}\-}}
\L{\LB{}\Tab{20}{(\V{maxcount}\-\V{cols}[\V{i}][\V{num}])\>=\V{maxcount})_\K{and}}}
\L{\LB{}\Tab{17}{(\V{quadrates}[\V{i}_\K{div}_\V{n},\V{j}][\V{num}]+\V{quadrates}[\V{i}_\K{div}_\V{n},\V{j}][\V{num2}]+\V{count}\<}}
\L{\LB{}\Tab{18}{\N{2}*\V{maxcount})_\K{then}}}
\L{\LB{}\Tab{16}{\K{for}_\V{l}:=\V{j}*\V{n}_\K{to}_\V{j}*\V{n}+\V{n}\-\N{1}_\K{do}_\K{begin}}}
\L{\LB{}\Tab{18}{\K{for}_\V{k}:=(\V{i}_\K{div}_\V{n})*\V{n}_\K{to}_\V{i}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{20}{\V{tryPut}(\V{k},\V{l},\V{num},\V{smLogicCombined});}}
\L{\LB{}\Tab{18}{\K{for}_\V{k}:=\V{i}+\N{1}_\K{to}_(\V{i}_\K{div}_\V{n})*\V{n}+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{20}{\V{tryPut}(\V{k},\V{l},\V{num},\V{smLogicCombined});}}
\L{\LB{}\Tab{16}{\K{end};}}
\L{\LB{}\Tab{12}{\K{end};}}
\L{\LB{}\Tab{8}{\K{end};}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}\Tab{6}{\C{}//Zeile_=\>_bekanntes_Quadrat\CE{}}}
\L{\LB{}\Tab{6}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{rows})_\K{do}}}
\L{\LB{}\Tab{8}{\K{if}_(\V{rows}[\V{i}][\V{num}]\>\V{maxcount}\-\V{n})}}
\L{\LB{}\Tab{12}{\K{and}_(\V{rows}[\V{i}][\V{num}]+\V{rows}[\V{i}][\V{num2}]\<\N{2}*\V{maxcount})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{10}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{quadrates})_\K{do}}}
\L{\LB{}\Tab{12}{\K{if}_(\V{quadrates}[\V{j},\V{i}_\K{div}_\V{n}][\V{num2}]+\V{n}\-}}
\L{\LB{}\Tab{20}{(\V{maxcount}\-\V{rows}[\V{i}][\V{num}])\>=\V{maxcount})_\K{and}}}
\L{\LB{}\Tab{15}{(\V{quadrates}[\V{j},\V{i}_\K{div}_\V{n}][\V{num}]+\V{quadrates}[\V{j},\V{i}_\K{div}_\V{n}][\V{num2}]\<}}
\L{\LB{}\Tab{18}{\N{2}*\V{maxcount})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{14}{\V{count}:=\N{0};}}
\L{\LB{}\Tab{14}{\K{for}_\V{k}:=\V{j}*\V{n}_\K{to}_\V{j}*\V{n}+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{16}{\K{if}_\V{data}[\V{k},\V{i}]=\V{triUnset}_\K{then}_\V{inc}(\V{count});}}
\L{\LB{}\Tab{14}{\K{if}_(\V{quadrates}[\V{j},\V{i}_\K{div}_\V{n}][\V{num2}]+\V{count}\-}}
\L{\LB{}\Tab{20}{(\V{maxcount}\-\V{rows}[\V{i}][\V{num}])\>=\V{maxcount})\K{and}}}
\L{\LB{}\Tab{17}{(\V{quadrates}[\V{j},\V{i}_\K{div}_\V{n}][\V{num}]+\V{quadrates}[\V{j},\V{i}_\K{div}_\V{n}][\V{num2}]+\V{count}\<}}
\L{\LB{}\Tab{19}{\N{2}*\V{maxcount})_\K{then}}}
\L{\LB{}\Tab{16}{\K{for}_\V{l}:=\V{j}*\V{n}_\K{to}_\V{j}*\V{n}+\V{n}\-\N{1}_\K{do}_\K{begin}}}
\L{\LB{}\Tab{18}{\K{for}_\V{k}:=(\V{i}_\K{div}_\V{n})*\V{n}_\K{to}_\V{i}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{20}{\V{tryPut}(\V{l},\V{k},\V{num},\V{smLogicCombined});}}
\L{\LB{}\Tab{18}{\K{for}_\V{k}:=\V{i}+\N{1}_\K{to}_(\V{i}_\K{div}_\V{n})*\V{n}+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{20}{\V{tryPut}(\V{l},\V{k},\V{num},\V{smLogicCombined});}}
\L{\LB{}\Tab{16}{\K{end};}}
\L{\LB{}\Tab{12}{\K{end};}}
\L{\LB{}\Tab{8}{\K{end};}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}\Tab{6}{\C{}//Fast_volle_Quadrate\CE{}}}
\L{\LB{}\Tab{6}{\K{for}_\V{i}:=\N{0}_\K{to}_\V{high}(\V{quadrates})_\K{do}}}
\L{\LB{}\Tab{8}{\K{for}_\V{j}:=\N{0}_\K{to}_\V{high}(\V{quadrates}[\N{0}])_\K{do}}\Tab{43}{\C{}//_i,_j_bestimmen_Quadrat\CE{}}}
\L{\LB{}\Tab{10}{\K{if}_(\V{quadrates}[\V{i}][\V{j}][\V{num}]\>\V{maxcount}\-\V{n})}}
\L{\LB{}\Tab{13}{\K{and}(\V{quadrates}[\V{i}][\V{j}][\V{num}]+\V{quadrates}[\V{i}][\V{j}][\V{num2}]\<\N{2}*\V{maxcount})\K{then}_\K{begin}}}
\L{\LB{}}
\L{\LB{}\Tab{12}{\C{}//Quadrat_=\>_bekannte_Spalte?\CE{}}}
\L{\LB{}\Tab{12}{\K{for}_\V{k}:=\V{i}*\V{n}_\K{to}_\V{i}*\V{n}+\V{n}\-\N{1}_\K{do}_\C{}//k_bestimmt_Spalte\CE{}}}
\L{\LB{}\Tab{14}{\K{if}_(\V{cols}[\V{k}][\V{num2}]+\V{n}\-(\V{maxcount}\-\V{quadrates}[\V{i}][\V{j}][\V{num}])\>=\V{maxcount})_\K{and}}}
\L{\LB{}\Tab{17}{(\V{cols}[\V{k}][\V{num}]+\V{cols}[\V{k}][\V{num2}]\<\N{2}*\V{maxcount})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{16}{\C{}//Anzahl_unbekannter_Felder_in_der_Schnittmenge_Quadrat/Spalte\CE{}}}
\L{\LB{}\Tab{16}{\C{}//bestimmen\CE{}}}
\L{\LB{}\Tab{16}{\V{count}:=\N{0};}}
\L{\LB{}\Tab{16}{\K{for}_\V{l}:=\V{j}*\V{n}_\K{to}_\V{j}*\V{n}+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{18}{\K{if}_\V{data}[\V{k},\V{l}]=\V{triUnset}_\K{then}_\V{inc}(\V{count});}}
\L{\LB{}\Tab{16}{\C{}//Spalte_füllen,_falls_nun_bekannt\CE{}}}
\L{\LB{}\Tab{16}{\K{if}_(\V{cols}[\V{k}][\V{num2}]+\V{count}\-(\V{maxcount}\-\V{quadrates}[\V{i}][\V{j}][\V{num}])\>=}}
\L{\LB{}\Tab{21}{\V{maxcount})\K{and}}}
\L{\LB{}\Tab{19}{(\V{cols}[\V{k}][\V{num}]+\V{cols}[\V{k}][\V{num2}]+\V{count}\<\N{2}*\V{maxcount})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{18}{\K{for}_\V{l}:=\N{0}_\K{to}_\V{j}*\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{20}{\V{tryPut}(\V{k},\V{l},\V{num},\V{smLogicCombined});}}
\L{\LB{}\Tab{18}{\K{for}_\V{l}:=\V{j}*\V{n}+\V{n}_\K{to}_\V{high}(\V{rows})_\K{do}}}
\L{\LB{}\Tab{20}{\V{tryPut}(\V{k},\V{l},\V{num},\V{smLogicCombined});}}
\L{\LB{}\Tab{16}{\K{end};}}
\L{\LB{}\Tab{14}{\K{end};}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}\Tab{12}{\C{}//Quadrat_=\>_bekannte_Zeile\CE{}}}
\L{\LB{}\Tab{12}{\K{for}_\V{k}:=\V{j}*\V{n}_\K{to}_\V{j}*\V{n}+\V{n}\-\N{1}_\K{do}_\C{}//k_bestimmt_Zeile\CE{}}}
\L{\LB{}\Tab{14}{\K{if}_(\V{rows}[\V{k}][\V{num2}]+\V{n}\-(\V{maxcount}\-\V{quadrates}[\V{i}][\V{j}][\V{num}])\>=\V{maxcount})_\K{and}}}
\L{\LB{}\Tab{17}{(\V{rows}[\V{k}][\V{num}]+\V{rows}[\V{k}][\V{num2}]\<\N{2}*\V{maxcount})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{16}{\C{}//Anzahl_unbekannter_Felder_in_der_Schnittmenge_Quadrat/Spalte\CE{}}}
\L{\LB{}\Tab{16}{\C{}//bestimmen\CE{}}}
\L{\LB{}\Tab{16}{\V{count}:=\N{0};}}
\L{\LB{}\Tab{16}{\K{for}_\V{l}:=\V{i}*\V{n}_\K{to}_\V{i}*\V{n}+\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{18}{\K{if}_\V{data}[\V{l},\V{k}]=\V{triUnset}_\K{then}_\V{inc}(\V{count});}}
\L{\LB{}\Tab{16}{\C{}//Zeile_füllen,_falls_nun_bekannt\CE{}}}
\L{\LB{}\Tab{16}{\K{if}_(\V{rows}[\V{k}][\V{num2}]+\V{count}\-(\V{maxcount}\-\V{quadrates}[\V{i}][\V{j}][\V{num}])\>=\V{maxcount})}}
\L{\LB{}\Tab{19}{\K{and}(\V{rows}[\V{k}][\V{num}]+\V{rows}[\V{k}][\V{num2}]+\V{count}\<\N{2}*\V{maxcount})_\K{then}_\K{begin}}}
\L{\LB{}\Tab{18}{\K{for}_\V{l}:=\N{0}_\K{to}_\V{i}*\V{n}\-\N{1}_\K{do}}}
\L{\LB{}\Tab{20}{\V{tryPut}(\V{l},\V{k},\V{num},\V{smLogicCombined});}}
\L{\LB{}\Tab{18}{\K{for}_\V{l}:=\V{i}*\V{n}+\V{n}_\K{to}_\V{high}(\V{rows})_\K{do}}}
\L{\LB{}\Tab{20}{\V{tryPut}(\V{l},\V{k},\V{num},\V{smLogicCombined});}}
\L{\LB{}\Tab{16}{\K{end};}}
\L{\LB{}\Tab{14}{\K{end};}}
\L{\LB{}\Tab{10}{\K{end};}}
\L{\LB{}}
\L{\LB{}}
\L{\LB{}\Tab{6}{\V{num2}:=\V{num};}}
\L{\LB{}\Tab{4}{\K{end};}}
\L{\LB{}\Tab{2}{\K{until}_\K{not}_\V{changed};}}
\L{\LB{\K{end};}}
\L{\LB{\K{end.}}}
\L{\LB{}}
