Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# tictactoe

Posted on 1999-07-25
Medium Priority
148 Views
can you give me an example program code of tictactoe using pascal?
0
Question by:maria1
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5
• 3
• 2
• +3

LVL 8

Accepted Solution

shlomoy earned 200 total points
ID: 1218667
program tictactoe;                                                                                                                                                                      {plays a tic-tac-toe}
type
boardtype = array[1..3, 1..3] of char;
var
board: boardtype;
x, y, a, b, turn, player: integer;
procedure writeboard (board: boardtype);
var
a, b: integer;
begin
for a := 1 to 3 do
begin
writeln('');
for b := 1 to 3 do
begin
write(board[a, b], '  ');
end;
end;
end;
function checker (board: boardtype): integer;
var
a, b: integer;
begin
if (turn = 9) then
checker := 1
else
begin
for a := 1 to 3 do
begin
if ((board[a, 1] = board[a, 2]) and (board[a, 1] = board[a, 3]) and (board[a, 1] = 'X')) then
begin
checker := 2;
end
else if ((board[a, 1] = board[a, 2]) and (board[a, 1] = board[a, 3]) and (board[a, 1] = 'O')) then
begin
checker := 3;
end
else if ((board[1, a] = board[2, a]) and (board[1, a] = board[3, a]) and (board[1, a] = 'X')) then
begin
checker := 2;
end
else if ((board[1, a] = board[2, a]) and (board[1, a] = board[3, a]) and (board[1, a] = 'O')) then
begin
checker := 3;
end
else if ((board[1, 1] = 'X') and (board[1, 1] = board[2, 2]) and (board[1, 1] = board[3, 3])) then
checker := 2
else if ((board[1, 1] = 'O') and (board[1, 1] = board[2, 2]) and (board[1, 1] = board[3, 3])) then
checker := 3
else if ((board[1, 3] = 'X') and (board[1, 3] = board[2, 2]) and (board[1, 3] = board[3, 1])) then
checker := 2
else if ((board[1, 3] = 'O') and (board[1, 3] = board[2, 2]) and (board[1, 1] = board[3, 1])) then
checker := 3
end;
end;
end;
begin
for a := 1 to 3 do
for b := 1 to 3 do
board[a, b] := '*';
turn := 0;
repeat
if (turn mod 2 = 0) then
begin
writeln('');
player := 1;
end
else
begin
writeln('');
player := 2;
end;
repeat
writeln('');
writeln('What is the y-coordinate of your move, player ', player);
writeln('');
writeln('What is the x-coordinate of your move?');
until ((board[y, x] <> 'X') and (board[y, x] <> 'O'));
case player of
1:
begin
board[y, x] := 'X';
end;
2:
begin
board[y, x] := 'O';
end;
end;
writeboard(board);
turn := turn + 1;
until ((checker(board) = 1) or (checker(board) = 2) or (checker(board) = 3));
case checker(board) of
2:
begin
writeln('');
writeln('Player 1 won.');
end;
1:
begin
writeln('');
writeln('Draw.');
end;
3:
begin
writeln('');
writeln('Player 2 won.');
end;
end;
end.

see: http://www.geocities.com/SiliconValley/Heights/4157/johntictactoe.html
0

LVL 8

Expert Comment

ID: 1218668
0

Author Comment

ID: 1218669
i would like to know if this only a procedure. and if it is, can u provide me the whole program?
0

LVL 8

Expert Comment

ID: 1218670
this is the whole program
0

LVL 1

Expert Comment

ID: 1218671
... Which reminds me that I made once 4x4x4 tictactoe
if you are interested (but most of the code is playing with graphics)

Fuzzy
0

LVL 5

Expert Comment

ID: 1218672
I am working on a 4x4x4 tictactoe for Delphi right now (1 player).  Didn't even start with the graphics yet.
0

LVL 8

Expert Comment

ID: 1218673
maria1, are you satisfied?

0

Expert Comment

ID: 1218674
Will somebody be so kind as to explain what is tictactoe to me? Thanks.
0

LVL 5

Expert Comment

ID: 1218675
it is a 3x3 board...one player is X, the other is O...players take turn making their marks in the squares...first one with three in a row wins...hopefully this is not a trick question =)
0

LVL 84

Expert Comment

ID: 1218676
a.k.a. noughts-and-crosses
0

Expert Comment

ID: 1218677
Thank you, scrapdog.
0

Expert Comment

ID: 1218678
Thank you, scrapdog.
0

LVL 8

Expert Comment

ID: 1218679
maria1?
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

While opting for any web-to-print solution, you need to discuss with your team and some of your end users and know their opinions about your decisions. In this article we list down some questions you need to ask yourself.
Check out what's been happening in the Experts Exchange community.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vulnâ€¦
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonstâ€¦
###### Suggested Courses
Course of the Month9 days, 10 hours left to enroll