I am a little stuck with my code, and need a bit of direction. Not a solution, just some guidance. Basically, using Delphi, I am trying to create a tic tac toe game using bit buttons (TBitBtn). So far I have the following:
begin
case SquareVal of
0: begin Board[pos].SquareFace.Glyph := Mainform.EmptyFace.glyph;
Board[pos].SquareValue:= 0; end;
1: begin Board[pos].SquareFace.Glyph := Mainform.BlueNoughtFace.glyph;
Board[pos].SquareValue:= 1; end;
2: begin Board[pos].SquareFace.Glyph := Mainform.RedCrossFace.glyph;
Board[pos].SquareValue:= 2; end;
end;
end;
procedure IncrementBoardSquare(Pos: Integer);
var
NewVal: Integer;
begin
NewVal:= (Board[Pos].SquareValue + 1) mod 3;
SetBoardSquare(Pos, NewVal);
end;
procedure TMainform.SquareClick(Sender: TObject);
begin
if (Sender = Board[1].SquareFace) then IncrementBoardSquare(1);
if (Sender = Board[2].SquareFace) then IncrementBoardSquare(2);
if (Sender = Board[3].SquareFace) then IncrementBoardSquare(3);
if (Sender = Board[4].SquareFace) then IncrementBoardSquare(4);
if (Sender = Board[5].SquareFace) then IncrementBoardSquare(5);
if (Sender = Board[6].SquareFace) then IncrementBoardSquare(6);
if (Sender = Board[7].SquareFace) then IncrementBoardSquare(7);
if (Sender = Board[8].SquareFace) then IncrementBoardSquare(8);
if (Sender = Board[9].SquareFace) then IncrementBoardSquare(9);
end;
procedure TMainform.Play_a_turnClick(Sender: TObject);
begin
begin
if
MessageDlg(
'Start Over?',
mtConfirmation,
mbOKCancel,0) = mrCancel then
Exit;
end;
end;
end.
I am stuck with the actual mechanics of using the procedure Play_a_turn to increment the non-user Bit Button, i.e. if the player is crosses, then the noughts need to increment each time Play_a_turn is pressed.
Any help or pseudo code would be greatly appreciated.
Once again, just to clarify, I'm not really in need of direct answers, more of a "where to from here" in order to get the Play_a_turn procedure working.
I'd find a 3x3 "magic square" matrix such that each row, column, and diagonal has a total of 15. Plug these values into the Tag property of the corresponding buttons.
The software player can then try to find moves that either will (a) cause it to have three squares totalling 15, or a move that will prevent the human player from having three squares totalling 15, with preference given to blocking multiple paths simultaneously if possible. Obviously, if the software player goes first, it must take the center square.
Cheers.