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
|
Function CheckPosibilite(ALeft, ATop, ARight, ABottom: Integer) : tArrPossibilite;
var
y,x : integer;
candidates : tArrPossibilite;
i : integer;
begin
for i:= low(candidates) to high(candidates) do
candidates[i] := i;
for y := ATop to ABottom do
begin
for x := ALeft to ARight do
begin
if Board[x,y] > 0 then // si une on trouve un élément on enlève la valeur
candidates[Board[x,y]] := 0;
end;
end;
Result := candidates;
end;
Function DonnePossibilite(aRow,aCol : Integer) : tPossibilite;
var
k,l : Integer;
tmpPoss : tArrPossibilite; // array of
candidates : tPossibilite; // set of
ii : Integer;
begin
Result :=[];
FillChar(tmpPoss,sizeof(tmpPoss),0);
candidates := [ValMin..ValMax];
if Board[aRow,aCol] = 0 Then // si pas de valeur trouvé
begin
tmpPoss := CheckPosibilite(aRow,1, aRow, Width );// on verifie la ligne
for ii:=low(tmpPoss) to High(tmpPoss) do
if tmpPoss[ii] = 0 Then
exclude(candidates,ii); // toutes les valeur trouve sont exclu
tmpPoss := CheckPosibilite(1,aCol, Height,aCol);// on verifie la colonne
for ii:=low(tmpPoss) to High(tmpPoss) do
if tmpPoss[ii] = 0 Then
exclude(candidates,ii);
k :=(((aRow-1) div 3)*3)+1;//détermine la premier ligne du group
l :=(((aCol-1) div 3)*3)+1; //détermine la premier colonne group
tmpPoss := CheckPosibilite(k,l,k+2,l+2);// on vérifie les groupes
for ii:=low(tmpPoss) to High(tmpPoss) do
if tmpPoss[ii] = 0 Then
exclude(candidates,ii);
result := candidates; // ne reste plus que les candidats potentiel
end;
end;
Procedure InitCheckBordPoss ;
var
i,j : Integer;
begin
// verifie les colonnes et les lignes
for i:= 1 to Height do
begin
For j:= 1 To Width do
begin
FPoss[i,j] := DonnePossibilite(i,j)
end;
end;
end; |