I REALLY need some help. I ahve been writing a tic-tac-toe console application program in delphi. I had most of the logic finished for the program when I made a mistake. At the beginning of a class period the program was working fine, at the end of the class it had an error. At some point in my program I must have added an extra END;. I am unable to find this extra end (even though I might have just missed it). I was wondering if Delphi has any properties similar to the new VB where you can see which end matches up to each begin. Here is the current code for my program
program TICTACTOE;
{$APPTYPE CONSOLE}
uses
SysUtils;
Var
Win,SaveMove,MoveTaken: Boolean;
Board: Array [1..3,1..3] of integer;
Choice,ComputerChoice,FinalChoice: Integer;
begin
{Austin Schroeder}
Randomize ;
Win := False;
While Win = False do
begin
MoveTaken:= True;
While MoveTaken = True do
begin
If Choice = 0 then
Begin
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
end;
writeln('Select Placement (Top Left = 1, Top Middle = 2, and so on)');
Readln(Choice);
If Board[1][1] = 0 Then
begin
If Choice = 1 Then
begin
Board[1][1]:= 3;
writeln('\ /| | ');
writeln(' \ | | ');
writeln('/ \| | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
end;
end;
If Board[1][2] = 0 Then
begin
If Choice = 2 Then
begin
Board[1][2]:= 3;
writeln(' |\ /| ');
writeln(' | \ | ');
writeln(' |/ \| ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
end;
end;
If Board[1][3] = 0 then
begin
If Choice = 3 Then
begin
Board[1][3]:= 3;
writeln(' | |\ /');
writeln(' | | \ ');
writeln(' | |/ \');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
end;
end;
If Board[2][1] = 0 Then
begin
If Choice = 4 Then
begin
Board[2][1]:= 3;
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln('\ /| | ');
writeln(' \ | | ');
writeln('/ \| | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
end;
end;
if Board[2][2] = 0 then
If Choice = 5 Then
begin
Board[2][2]:= 3;
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' |\ /| ');
writeln(' | \ | ');
writeln(' |/ \| ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
end;
end;
If Board[2][3] = 0 Then
begin
If Choice = 6 Then
begin
Board[2][3]:= 3;
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | |\ /');
writeln(' | | \ ');
writeln(' | |/ \');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
end;
end;
If Board[3][1] = 0 THen
begin
If Choice = 7 Then
begin
Board[3][1]:= 3;
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln('\ /| | ');
writeln(' \ | | ');
writeln('/ \| | ');
end;
end;
If Board[3][2] = 0 Then
begin
If Choice = 8 Then
begin
Board[3][2]:= 3;
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' |\ /| ');
writeln(' | \ | ');
writeln(' |/ \| ');
end;
end;
If Board[3][3] = 0 then
begin
If Choice = 9 Then
begin
Board[3][3]:= 3;
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | | ');
writeln(' | | ');
writeln(' | | ');
writeln('---|---|---');
writeln(' | |\ /');
writeln(' | | \ ');
writeln(' | |/ \');
end;
end;
writeln('Sorry that spot is taken please choose again.');
end;
FinalChoice := Choice;
{End of First Turn For Player}
MoveTaken:= True;
{Checking For Win}
If Board[1][1] + Board[1][2] + Board[1][3] = 9 then
begin
Writeln('Player Won');
Win := True;
end;
If Board[2][1] + Board[2][2] + Board[2][3] = 9 then
begin
Writeln('Player Won');
Win := True;
end;
If Board[3][1] + Board[3][2] + Board[3][3] = 9 then
begin
Writeln('Player Won');
Win := True;
end;
If Board[1][1] + Board[2][1] + Board[3][1] = 9 then
begin
Writeln('Player Won');
Win := True;
end;
If Board[1][2] + Board[2][2] + Board[3][2] = 9 then
begin
Writeln('Player Won');
Win := True;
end;
If Board[1][3] + Board[2][3] + Board[3][3] = 9 then
begin
Writeln('Player Won');
Win := True;
end;
If Board[1][1] + Board[2][2] + Board[3][3] = 9 then
begin
Writeln('Player Won');
Win := True;
end;
If Board[1][3] + Board[2][2] + Board[3][1] = 9 then
begin
Writeln('Player Won');
Win := True;
end;
{cheking For Computer Potential Winning Spot}
{Right Horizontal}
If Win = False Then
begin
If Board[1][1] + Board[1][2] = 10 then
begin
ComputerChoice:= 3;
Board[1][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][1] + Board[2][2] = 10 Then
begin
ComputerChoice:= 6;
Board[2][3] := 5;
FinalChoice := Choice +1;
End;
If Board[3][1] + Board[3][2] = 10 then
begin
ComputerChoice:= 9;
Board[3][3]:= 5;
FinalChoice := Choice +1;
end;
{Middle Horizontal}
If Board[1][1] + Board[1][3] = 10 then
begin
ComputerChoice:= 2;
Board[1][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][1] + Board[2][3] = 10 then
begin
ComputerChoice:= 5;
Board[2][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[3][1] + Board[3][3] = 10 then
begin
ComputerChoice:= 8;
Board[3][2]:= 5;
FinalChoice := Choice +1;
end;
{Left Horizontal}
If Board[1][2] + Board[1][3] = 10 then
begin
ComputerChoice:= 1;
Board[1][1]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][2] + Board[2][3] = 10 then
begin
ComputerChoice:= 4;
Board[2][1]:= 5;
FinalChoice := Choice +1;
end;
If Board[3][2] + Board[3][3] = 10 then
begin
ComputerChoice:= 7;
Board[3][1]:= 5;
FinalChoice := Choice +1;
end;
{Bottom Vertical}
If Board[1][1] + Board[2][1] = 10 then
begin
ComputerChoice:= 7;
Board[3][1]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][2] + Board[2][2] = 10 then
begin
ComputerChoice:= 8;
Board[3][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][3] + Board[2][3] = 10 then
begin
ComputerChoice:= 9;
Board[3][3]:= 5;
FinalChoice := Choice +1;
end;
{Middle Vertical}
If Board[1][3] + Board[3][3] = 10 then
begin
ComputerChoice:= 6;
Board[2][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][2] + Board[3][2] = 10 then
begin
ComputerChoice:= 5;
Board[2][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][1] + Board[3][1] = 10 then
begin
ComputerChoice:= 4;
Board[2][1]:= 5;
FinalChoice := Choice +1;
end;
{Top Vertical}
If Board[2][3] + Board[3][3] = 10 then
begin
ComputerChoice:= 3;
Board[1][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][2] + Board[3][2] = 10 then
begin
ComputerChoice:= 2;
Board[1][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][1] + Board[3][1] = 10 then
begin
ComputerChoice:= 1;
Board[1][1]:= 5;
FinalChoice := Choice +1;
end;
{Diagonol Top Left-Bottom Right}
If Board[1][1] + Board[2][2] = 10 then
begin
ComputerChoice:= 9;
Board[3][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][1] + Board[3][3] = 10 then
begin
ComputerChoice:= 5;
Board[2][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][2] + Board[3][3] = 10 then
begin
ComputerChoice:= 1;
Board[1][1]:= 5;
FinalChoice := Choice +1;
end;
{Diagonol Top Right-Bottom Left}
If Board[1][3] + Board[2][2] = 10 then
begin
ComputerChoice:= 7;
Board[3][1]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][3] + Board[3][1] = 10 then
begin
ComputerChoice:= 5;
Board[2][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][2] + Board[3][1] = 10 then
begin
ComputerChoice:= 3;
Board[1][3]:= 5;
FinalChoice := Choice +1;
end;
{End of Checking For Computer Winning Spot}
{Player Potential Winning Spot}
{Right Horizontal}
If Board[1][1] + Board[1][2] = 6 then
begin
ComputerChoice:= 3;
Board[1][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][1] + Board[2][2] = 6 Then
begin
ComputerChoice:= 6;
Board[2][3] := 5;
FinalChoice := Choice +1;
End;
If Board[3][1] + Board[3][2] = 6 then
begin
ComputerChoice:= 9;
Board[3][3]:= 5;
FinalChoice := Choice +1;
end;
{Middle Horizontal}
If Board[1][1] + Board[1][3] = 6 then
begin
ComputerChoice:= 2;
Board[1][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][1] + Board[2][3] = 6 then
begin
ComputerChoice:= 5;
Board[2][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[3][1] + Board[3][3] = 6 then
begin
ComputerChoice:= 8;
Board[3][2]:= 5;
FinalChoice := Choice +1;
end;
{Left Horizontal}
If Board[1][2] + Board[1][3] = 6 then
begin
ComputerChoice:= 1;
Board[1][1]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][2] + Board[2][3] = 6 then
begin
ComputerChoice:= 4;
Board[2][1]:= 5;
FinalChoice := Choice +1;
end;
If Board[3][2] + Board[3][3] = 6 then
begin
ComputerChoice:= 7;
Board[3][1]:= 5;
FinalChoice := Choice +1;
end;
{Bottom Vertical}
If Board[1][1] + Board[2][1] = 6 then
begin
ComputerChoice:= 7;
Board[3][1]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][2] + Board[2][2] = 6 then
begin
ComputerChoice:= 8;
Board[3][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][3] + Board[2][3] = 6 then
begin
ComputerChoice:= 9;
Board[3][3]:= 5;
FinalChoice := Choice +1;
end;
{Middle Vertical}
If Board[1][3] + Board[3][3] = 6 then
begin
ComputerChoice:= 6;
Board[2][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][2] + Board[3][2] = 6 then
begin
ComputerChoice:= 5;
Board[2][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][1] + Board[3][1] = 6 then
begin
ComputerChoice:= 4;
Board[2][1]:= 5;
FinalChoice := Choice +1;
end;
{Top Vertical}
If Board[2][3] + Board[3][3] = 6 then
begin
ComputerChoice:= 3;
Board[1][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][2] + Board[3][2] = 6 then
begin
ComputerChoice:= 2;
Board[1][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][1] + Board[3][1] = 6 then
begin
ComputerChoice:= 1;
Board[1][1]:= 5;
FinalChoice := Choice +1;
end;
{Diagonol Top Left-Bottom Right}
If Board[1][1] + Board[2][2] = 6 then
begin
ComputerChoice:= 9;
Board[3][3]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][1] + Board[3][3] = 6 then
begin
ComputerChoice:= 5;
Board[2][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][2] + Board[3][3] = 6 then
begin
ComputerChoice:= 1;
Board[1][1]:= 5;
FinalChoice := Choice +1;
end;
{Diagonol Top Right-Bottom Left}
If Board[1][3] + Board[2][2] = 6 then
begin
ComputerChoice:= 7;
Board[3][1]:= 5;
FinalChoice := Choice +1;
end;
If Board[1][3] + Board[3][1] = 6 then
begin
ComputerChoice:= 5;
Board[2][2]:= 5;
FinalChoice := Choice +1;
end;
If Board[2][2] + Board[3][1] = 6 then
begin
ComputerChoice:= 3;
Board[1][3]:= 5;
FinalChoice := Choice +1;
end;
{End Of Player Winning Spot Check}
{Computer Choice Without Winning Spot}
While FinalChoice = Choice do
begin
Randomize;
ComputerChoice := 1 + Random(9);
If ComputerChoice = 1 then
begin
If Board[1][1] = 0 Then
begin
FinalChoice:= Choice + 1;
Board[1][1] := 5;
end;
end;
If ComputerChoice = 2 then
begin
If Board[1][2] = 0 Then
begin
FinalChoice:= Choice + 1;
Board[1][2] := 5;
end;
end;
If ComputerChoice = 3 then
begin
If Board[1][3] = 0 Then
begin
FinalChoice:= Choice + 1;
Board[1][3] := 5;
end;
end;
If ComputerChoice = 4 then
begin
If Board[2][1] = 0 Then
begin
FinalChoice:= Choice + 1;
Board[2][1] := 5;
end;
end;
If ComputerChoice = 5 then
begin
If Board[2][2] = 0 Then
begin
FinalChoice:= Choice + 1;
Board[2][2] := 5;
end;
end;
If ComputerChoice = 6 then
begin
If Board[2][3] = 0 Then
begin
FinalChoice:= Choice + 1;
Board[2][3] := 5;
end;
end;
If ComputerChoice = 7 then
begin
If Board[3][1] = 0 Then
begin
FinalChoice:= Choice + 1;
Board[3][1] := 5;
end;
end;
If ComputerChoice = 8 then
begin
If Board[3][2] = 0 Then
begin
FinalChoice:= Choice + 1;
Board[3][2] := 5;
end;
end;
If ComputerChoice = 9 then
begin
If Board[3][3] = 0 Then
begin
FinalChoice:= Choice + 1;
Board[3][3] := 5;
end;
end;
{Ending Random Choice While-Do}
end;
{Ending Player Win Check}
end;
{Just for me to see how the program is working until I am done with the visual potrtion of the program}
writeln('-----');
writeln(ComputerChoice);
writeln('-----');
writeln(Board[1][1]);
writeln(Board[1][2]);
writeln(Board[1][3]);
writeln(Board[2][1]);
writeln(Board[2][2]);
writeln(Board[2][3]);
writeln(Board[3][1]);
writeln(Board[3][2]);
writeln(Board[3][3]);
{Ending Major While-Do}
end;
{End Of Program}
readln
end.