mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-02-05 19:32:48 -08:00
Added tictactoe1 in Pascal
This commit is contained in:
3
89_Tic-Tac-Toe/go/README.md
Normal file
3
89_Tic-Tac-Toe/go/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
|
||||
|
||||
Conversion to [Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language))
|
||||
103
89_Tic-Tac-Toe/pascal/tictactoe1.pas
Normal file
103
89_Tic-Tac-Toe/pascal/tictactoe1.pas
Normal file
@@ -0,0 +1,103 @@
|
||||
program tictactoe1;
|
||||
var
|
||||
a, b, c, d, e: integer;
|
||||
p, q, r, s: integer;
|
||||
procedure computerMoves(m: integer);
|
||||
begin
|
||||
write('COMPUTER MOVES ');
|
||||
writeln(m);
|
||||
end;
|
||||
|
||||
function readYourMove() : integer;
|
||||
var number: integer;
|
||||
begin
|
||||
write('YOUR MOVE?');
|
||||
readln(number);
|
||||
readYourMove := number;
|
||||
end;
|
||||
|
||||
function move(number: integer): integer;
|
||||
begin
|
||||
move := number - 8 * trunc((number - 1) / 8);
|
||||
end;
|
||||
|
||||
function padLeft(m: string; n: integer): string;
|
||||
var tmp: string;
|
||||
begin
|
||||
tmp := '';
|
||||
repeat
|
||||
tmp := tmp + ' ';
|
||||
n := n - 1;
|
||||
until n = 0;
|
||||
tmp := tmp + m;
|
||||
padLeft := tmp;
|
||||
end;
|
||||
|
||||
begin
|
||||
writeln(padLeft('TIC TAC TOE', 30));
|
||||
writeln(padLeft('CREATIVE COMPUTING MORRISTOWN, NEW JERSEY', 15));
|
||||
writeln('');
|
||||
writeln('');
|
||||
writeln('');
|
||||
writeln('THE GAME BOARD IS NUMBERED:');
|
||||
writeln('');
|
||||
writeln('1 2 3');
|
||||
writeln('8 9 4');
|
||||
writeln('7 6 5');
|
||||
while(true) do
|
||||
begin
|
||||
writeln('');
|
||||
writeln('');
|
||||
a := 9;
|
||||
computerMoves(a);
|
||||
p := readYourMove();
|
||||
b := move(p + 1);
|
||||
computerMoves(b);
|
||||
q := readYourMove();
|
||||
if (q = move(b + 4)) then
|
||||
begin
|
||||
c := move(b + 2);
|
||||
computerMoves(c);
|
||||
r := readYourMove();
|
||||
if (r = move(c + 4)) then
|
||||
begin
|
||||
if (p mod 2 <> 0) then
|
||||
begin
|
||||
d := move(c + 3);
|
||||
computerMoves(d);
|
||||
s := readYourMove();
|
||||
if (s = move(d + 4)) then
|
||||
begin
|
||||
e := move(d + 6);
|
||||
computerMoves(e);
|
||||
writeln('THE GAME IS A DRAW.');
|
||||
end
|
||||
else
|
||||
begin
|
||||
e := move(d + 4);
|
||||
computerMoves(e);
|
||||
writeln('AND WINS ********');
|
||||
end
|
||||
end
|
||||
else
|
||||
begin
|
||||
d := move(c + 7);
|
||||
computerMoves(d);
|
||||
writeln('AND WINS ********');
|
||||
end
|
||||
end
|
||||
else
|
||||
begin
|
||||
d := move(c + 4);
|
||||
computerMoves(d);
|
||||
writeln('AND WINS ********');
|
||||
end
|
||||
end
|
||||
else
|
||||
begin
|
||||
c := move(b + 4);
|
||||
computerMoves(c);
|
||||
writeln('AND WINS ********');
|
||||
end;
|
||||
end;
|
||||
end.
|
||||
Reference in New Issue
Block a user