Disclaimer: I have not studied the algorithm in detail. The comments below are just my first reactions after you looked at the code for less than ten seconds.
I have very quick comments. Firstly i think
TCellState = (csUnoccupied, csPlayerA, csPlayerB) TBoard = Array[1..7, 1..6] of TCellState;
it is better. Of course, you can keep compatibility with old code by doing
TCellState = (csUnoccupied = 0, csPlayerA = 1, csPlayerB = -1)
Secondly,
draw := true; for s := 1 to 7 do begin for z := 1 to 6 do begin if Board[s, z] = 0 then draw := false; end; end;
You do not need the begin and end parts:
draw := TRUE; for s := 1 to 7 do for z := 1 to 6 do if Board[s, z] = 0 then draw := false;
More importantly, as a performance boost, you should break the loops as soon as you set drawn to false:
draw := true; for s := 1 to 7 do for z := 1 to 6 do if Board[s, z] = 0 then begin draw := false; break; end;
This, however, leads to a rupture of the cycle z . To break both loops, the best way is to place the whole block above in a local function. Let me call it CheckDraw :
function CheckDraw: boolean; begin result := true; for s := 1 to 7 do for z := 1 to 6 do if Board[s, z] = 0 then Exit(false); end;
Alternatively, you can use label and goto to break two loops at the same time.
Update
Now I see that you can just do
for s := 1 to 7 do for z := 1 to 6 do if Board[s, z] = 0 then Exit(0);
and you don’t even need to enter a local draw variable!
Final update
Besides,
if inRow = 4 then result := TRUE else result := FALSE;
Bad. You should only do
result := inRow = 4;
Finally, in my opinion
s := s+sChange;
should be written
inc(s, sChange);
and
inRow := inRow+1
it should be
inc(inRow);
Oh and nil is a pointer, not an integer.