?
Solved

program

Posted on 1999-07-28
4
Medium Priority
?
156 Views
Last Modified: 2010-04-16
Can you give me a sample program of tic tac toe-using pascal?
0
Comment
Question by:cherry6
[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
  • Learn & ask questions
  • 3
4 Comments
 
LVL 8

Accepted Solution

by:
shlomoy earned 200 total points
ID: 1218680
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('');
           writeln('Player 1, your turn.');
           player := 1;
          end
         else
          begin
           writeln('');
           writeln('Player2, your turn.');
           player := 2;
          end;
         repeat
          writeln('');
          writeln('What is the y-coordinate of your move, player ', player);
          readln(y);
          writeln('');
          writeln('What is the x-coordinate of your move?');
          readln(x);
         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 6

Expert Comment

by:My name is Mud
ID: 1218681
is this Q, a homework???
0
 
LVL 8

Expert Comment

by:shlomoy
ID: 1218682
I hope it isn't.
Maybe it's an excerise in a selfstudy book...

0
 
LVL 8

Expert Comment

by:shlomoy
ID: 1218683
Thanks.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you’re involved with your company’s wide area network (WAN), you’ve probably heard about SD-WANs. They’re the “boy wonder” of networking, ostensibly allowing companies to replace expensive MPLS lines with low-cost Internet access. But, are they …
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question