You've already forked lazarus-ccr
Sudoku: unify indentation style (begin..end blocks). No functional changes.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7241 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -169,16 +169,12 @@ begin
|
|||||||
if aCol in [0..2, 6..8] then
|
if aCol in [0..2, 6..8] then
|
||||||
begin
|
begin
|
||||||
if aRow in [0..2, 6..8] then
|
if aRow in [0..2, 6..8] then
|
||||||
begin
|
|
||||||
NeedsColor := True;
|
NeedsColor := True;
|
||||||
end;
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
if aRow in [3..5] then
|
if aRow in [3..5] then
|
||||||
begin
|
|
||||||
NeedsColor := True;
|
NeedsColor := True;
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
if NeedsColor then
|
if NeedsColor then
|
||||||
(Sender as TStringGrid).Canvas.Brush.Color := $00EEEEEE;
|
(Sender as TStringGrid).Canvas.Brush.Color := $00EEEEEE;
|
||||||
@@ -204,8 +200,10 @@ var
|
|||||||
Steps, AValue: Integer;
|
Steps, AValue: Integer;
|
||||||
begin
|
begin
|
||||||
theValues := Default(TValues); //initialize all to zero
|
theValues := Default(TValues); //initialize all to zero
|
||||||
for Col := 0 to 8 do begin
|
for Col := 0 to 8 do
|
||||||
for Row := 0 to 8 do begin
|
begin
|
||||||
|
for Row := 0 to 8 do
|
||||||
|
begin
|
||||||
if Length(SGrid.Cells[Col, Row]) >= 1 then
|
if Length(SGrid.Cells[Col, Row]) >= 1 then
|
||||||
begin
|
begin
|
||||||
if TryStrToInt(SGrid.Cells[Col, Row][1], AValue) then
|
if TryStrToInt(SGrid.Cells[Col, Row][1], AValue) then
|
||||||
|
@@ -72,8 +72,10 @@ var
|
|||||||
begin
|
begin
|
||||||
Result := 0;
|
Result := 0;
|
||||||
aValue := 0;
|
aValue := 0;
|
||||||
for D := 1 to 9 do begin
|
for D := 1 to 9 do
|
||||||
if D in ASet then begin
|
begin
|
||||||
|
if D in ASet then
|
||||||
|
begin
|
||||||
Inc(Result);
|
Inc(Result);
|
||||||
aValue := D;
|
aValue := D;
|
||||||
end;
|
end;
|
||||||
@@ -86,13 +88,18 @@ procedure TSudoku.FillGridFromValues(Values: TValues);
|
|||||||
var
|
var
|
||||||
c, r: Integer;
|
c, r: Integer;
|
||||||
begin
|
begin
|
||||||
for c := 1 to 9 do begin
|
for c := 1 to 9 do
|
||||||
for r := 1 to 9 do begin
|
begin
|
||||||
if Values[c, r] in [1..9] then begin
|
for r := 1 to 9 do
|
||||||
|
begin
|
||||||
|
if Values[c, r] in [1..9] then
|
||||||
|
begin
|
||||||
Grid[c, r].Locked := True;
|
Grid[c, r].Locked := True;
|
||||||
Grid[c, r].Value := Values[c, r];
|
Grid[c, r].Value := Values[c, r];
|
||||||
Grid[c, r].DigitsPossible := [(Values[c, r])];
|
Grid[c, r].DigitsPossible := [(Values[c, r])];
|
||||||
end else begin
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
Grid[c, r].Locked := False;
|
Grid[c, r].Locked := False;
|
||||||
Grid[c, r].Value := 0;
|
Grid[c, r].Value := 0;
|
||||||
Grid[c, r].DigitsPossible := [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
Grid[c, r].DigitsPossible := [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||||
@@ -108,9 +115,12 @@ begin
|
|||||||
Steps := 0;
|
Steps := 0;
|
||||||
repeat
|
repeat
|
||||||
inc(Steps);
|
inc(Steps);
|
||||||
for c := 1 to 9 do begin
|
for c := 1 to 9 do
|
||||||
for r := 1 to 9 do begin
|
begin
|
||||||
if not Grid[c, r].Locked then begin
|
for r := 1 to 9 do
|
||||||
|
begin
|
||||||
|
if not Grid[c, r].Locked then
|
||||||
|
begin
|
||||||
CheckRow(c, r);
|
CheckRow(c, r);
|
||||||
CheckCol(c, r);
|
CheckCol(c, r);
|
||||||
CheckBlock(c, r);
|
CheckBlock(c, r);
|
||||||
@@ -128,8 +138,10 @@ var
|
|||||||
begin
|
begin
|
||||||
FillGridFromValues(Values);
|
FillGridFromValues(Values);
|
||||||
Result := Solve(Steps);
|
Result := Solve(Steps);
|
||||||
for c := 1 to 9 do begin
|
for c := 1 to 9 do
|
||||||
for r := 1 to 9 do begin
|
begin
|
||||||
|
for r := 1 to 9 do
|
||||||
|
begin
|
||||||
Values[c, r] := Grid[c, r].Value;
|
Values[c, r] := Grid[c, r].Value;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -165,9 +177,11 @@ procedure TSudoku.CheckCol(Col, Row: Integer);
|
|||||||
var
|
var
|
||||||
i, d: Integer;
|
i, d: Integer;
|
||||||
begin
|
begin
|
||||||
for i := 1 to 9 do begin
|
for i := 1 to 9 do
|
||||||
|
begin
|
||||||
if i = Row then continue;
|
if i = Row then continue;
|
||||||
for d := 1 to 9 do begin
|
for d := 1 to 9 do
|
||||||
|
begin
|
||||||
if Grid[Col, i].Value = d then exclude(Grid[Col, Row].DigitsPossible, d);
|
if Grid[Col, i].Value = d then exclude(Grid[Col, Row].DigitsPossible, d);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -177,9 +191,11 @@ procedure TSudoku.CheckRow(Col, Row: Integer);
|
|||||||
var
|
var
|
||||||
i, d: Integer;
|
i, d: Integer;
|
||||||
begin
|
begin
|
||||||
for i := 1 to 9 do begin
|
for i := 1 to 9 do
|
||||||
|
begin
|
||||||
if i = Col then continue;
|
if i = Col then continue;
|
||||||
for d := 1 to 9 do begin
|
for d := 1 to 9 do
|
||||||
|
begin
|
||||||
if Grid[i, Row].Value = d then exclude(Grid[Col, Row].DigitsPossible, d);
|
if Grid[i, Row].Value = d then exclude(Grid[Col, Row].DigitsPossible, d);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -189,10 +205,14 @@ procedure TSudoku.CheckBlock(Col, Row: Integer);
|
|||||||
var
|
var
|
||||||
i, j, d: Integer;
|
i, j, d: Integer;
|
||||||
begin
|
begin
|
||||||
for i := cmin[Col] to cmax[Col] do begin
|
for i := cmin[Col] to cmax[Col] do
|
||||||
for j := cmin[Row] to cmax[Row] do begin
|
begin
|
||||||
if not ((i = Col) and (j = Row)) then begin
|
for j := cmin[Row] to cmax[Row] do
|
||||||
for d := 1 to 9 do begin
|
begin
|
||||||
|
if not ((i = Col) and (j = Row)) then
|
||||||
|
begin
|
||||||
|
for d := 1 to 9 do
|
||||||
|
begin
|
||||||
if Grid[i, j].Value = d then exclude(Grid[Col, Row].DigitsPossible, d);
|
if Grid[i, j].Value = d then exclude(Grid[Col, Row].DigitsPossible, d);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@@ -207,25 +227,34 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
value: Integer;
|
value: Integer;
|
||||||
begin
|
begin
|
||||||
for c := 1 to 9 do begin
|
for c := 1 to 9 do
|
||||||
for r := 1 to 9 do begin
|
begin
|
||||||
|
for r := 1 to 9 do
|
||||||
|
begin
|
||||||
if Grid[c, r].Locked
|
if Grid[c, r].Locked
|
||||||
or (CountSetMembers(Grid[c, r].DigitsPossible, Value) = 1) then continue;
|
or (CountSetMembers(Grid[c, r].DigitsPossible, Value) = 1) then continue;
|
||||||
if ADigit in Grid[c, r].DigitsPossible then begin
|
if ADigit in Grid[c, r].DigitsPossible then
|
||||||
|
begin
|
||||||
OtherPossible := False;
|
OtherPossible := False;
|
||||||
for i := 1 to 9 do begin
|
for i := 1 to 9 do
|
||||||
|
begin
|
||||||
if i <> c then OtherPossible := (ADigit in Grid[i, r].DigitsPossible);
|
if i <> c then OtherPossible := (ADigit in Grid[i, r].DigitsPossible);
|
||||||
if OtherPossible then Break;
|
if OtherPossible then Break;
|
||||||
end;
|
end;
|
||||||
if not OtherPossible then begin
|
if not OtherPossible then
|
||||||
|
begin
|
||||||
Grid[c, r].DigitsPossible := [ADigit];
|
Grid[c, r].DigitsPossible := [ADigit];
|
||||||
end else begin
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
OtherPossible := False;
|
OtherPossible := False;
|
||||||
for i := 1 to 9 do begin
|
for i := 1 to 9 do
|
||||||
|
begin
|
||||||
if i <> r then OtherPossible := (ADigit in Grid[c, i].DigitsPossible);
|
if i <> r then OtherPossible := (ADigit in Grid[c, i].DigitsPossible);
|
||||||
if OtherPossible then Break;
|
if OtherPossible then Break;
|
||||||
end;
|
end;
|
||||||
if not OtherPossible then begin
|
if not OtherPossible then
|
||||||
|
begin
|
||||||
Grid[c, r].DigitsPossible := [ADigit];
|
Grid[c, r].DigitsPossible := [ADigit];
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user