Hab auch noch eine Idee, die das ursprüngliche 2D Array
( 0 = leer, 1 = Spieler 1 , 2 = Spieler 2) nutzt.
Delphi-Quellcode:
var
daten : array[0..6,0..5] of integer;
function TForm1.Gewonnen:integer;
var tmp1,tmp2 : integer;
begin
result := 0;
// Reihen
for x := 0 to 5 do begin
tmp1 := 0;
tmp2 := 0;
for t := 0 to 6 do begin
if (daten[t,x] = 1) then tmp1 := tmp1 + trunc(power(2,(t+1)));
if (daten[t,x] = 2) then tmp2 := tmp2 + trunc(power(2,(t+1)));
end;
for t := 0 to 2 do begin
if ((tmp1 shr t) AND 15) = 15) then result := 1;
if ((tmp2 shr t) AND 15) = 15) then result := 2;
end;
end;
// spalten
for t := 0 to 6 do begin
tmp1 := 0;
tmp2 := 0;
for x := 0 to 5 do begin
if (daten[t,x] = 1) then tmp1 := tmp1 + trunc(power(2,(t+1)));
if (daten[t,x] = 2) then tmp2 := tmp2 + trunc(power(2,(t+1)));
end;
for x := 0 to 2 do begin
if ((tmp1 shr t) AND 15) = 15) then result := 1;
if ((tmp2 shr t) AND 15) = 15) then result := 2;
end;
end;
// diagonal SW -> NO
for u := 3 to 9 do begin
tmp1 := 0;
tmp2 := 0;
for t := 0 to 6 do begin
x := u - t;
if ( ( x >= 0 ) AND (x <= 5) ) then begin
if (daten[t,x] = 1) then tmp1 := tmp1 + trunc(power(2,(t+1)));
if (daten[t,x] = 2) then tmp2 := tmp2 + trunc(power(2,(t+1)));
end;
end;
for x := 0 to 2 do begin
if ((tmp1 shr t) AND 15) = 15) then result := 1;
if ((tmp2 shr t) AND 15) = 15) then result := 2;
end;
end;
// diagonal SO -> NW
for u := 3 to 9 do begin
tmp1 := 0;
tmp2 := 0;
for t := 0 to 6 do begin
x := u - (6 - t);
if ( ( x >= 0 ) AND (x <= 5) ) then begin
if (daten[t,x] = 1) then tmp1 := tmp1 + trunc(power(2,(t+1)));
if (daten[t,x] = 2) then tmp2 := tmp2 + trunc(power(2,(t+1)));
end;
end;
for x := 0 to 2 do begin
if ((tmp1 shr t) AND 15) = 15) then result := 1;
if ((tmp2 shr t) AND 15) = 15) then result := 2;
end;
end;
end;
Rückgabe Wert ist dann 0=keiner, 1=Spieler1, 2=Spieler2