NOUG-INNOUGHTSNOUG-IN!BOOT 3 ##00*BASIC
PAGE=&1900
*FX21
CLOSE#0:CHAIN "NOUG-IN"
Noughts and Crosses
# 21 Games for the BBC (c) 1983
(*FX200,3
27
<23;8202;0;0;0;
F1"";157;9);141;135;"Noughts and Crosses"
P1"";157;9);141;135;"Noughts and Crosses"
Z"Noughts and Crosses is a simple game ofstrategy. The problem with playing it against a computer is that the computercan be programmed so that the person challenging it can never win."
d"However, this program makes your BBC Micro an opponent who can be beaten. The BBC Micro will make sensible moves but is not infallible so it is worth playing on until you beat it. It's"
nL"actually a very good way of learning about game-playing strategy."
xx"This game is played on a simple three- by-three grid in the traditional way. You have the'X'and play first."
"To make your move you have to specify which square to place your mark on. Type in the row number first, then the column number. For example, type 11 to place your cross in the top, lefthand"
"corner."
00,23)" Press any key to continue.";
*FX15,0
A=:
1"";157;9);141;135;"Noughts and Crosses"
1"";157;9);141;135;"Noughts and Crosses"
"If you type a number in a wrong format (for example 1,1) or a number that doesnot correspond to a position on the grid, for example 41, the BBC Micro won't accept it and will beep at you."
w"If you type the number of a position that is already occupied a message to that effect will be displayed."
b"Once you've made your move the computerreplies with its'O'and you make your next move."
"At the end the BBC Micro will display 'I WIN'if it has been successful, 'YOU WIN'if you've been successful and'DRAW'if it's stalemate. The board hasto be completely filled for the game to be over."
"The program only looks one move ahead with deciding its move so does not takeaccount of the next move you'll make - which is why it slips up sometimes."
20,23)" Press any key to load the game.";
*FX15,0
A=:
=&1900:"NOUGHTS"
"
Noughts and Crosses
5
INIT
( MOVE
2
BOARD
<
REPLY
F FIN=1 dlD
P FIN=2 BOARD:dDD
Z DR=1 dXD
d
BOARD
n Th@
x
VAL
Z=1 4
X(Z)=0
Y(Z)=0
Z
L=1 3
S=0
T=0
K=1 3
A(L,K)=1 S=S+1
B(L,K)=1 T=T+1
K
S=0 Y(T+1)=Y(T+1)+1
T=0 X(S+1)=X(S+1)+1
L
L=1 3
T=0
"S=0
,
K=1 3
6 A(K,L)=1 S=S+1
@ B(K,L)=1 T=T+1
J K
T S=0 Y(T+1)=Y(T+1)+1
^ T=0 X(S+1)=X(S+1)+1
h L
r DIA1
| DIA2
X(4)=1 FIN=1:
Y(4)=1 FIN=2
-E=128*Y(4)-63*X(3)+31*Y(3)-15*X(2)+7*Y(2)
DIA1
T=0
S=0
K=1 3
T=T+A(K,K)
S=S+B(K,K)
K
S=0 X(T+1)=X(T+1)+1
T=0 Y(S+1)=Y(S+1)+1
DIA2
T=0
&S=0
0
K=1 3
:T=T+A(4-K,K)
DS=S+B(4-K,K)
N K
X S=0 X(T+1)=X(T+1)+1
b T=0 Y(S+1)=Y(S+1)+1
l
v REPLY
M=-256: DR=1
J=1 3
I=1 3
A(I,J)=1 B(I,J)=1 dZB
DR=0:B(I,J)=1
VAL
FIN=1
E>M M=E: A=I:B=J
B(I,J)=0
I
J
B(A,B)=1
MOVE
*FX21,0
0,25);
"Your move (row col) ",A$
$ (A$)<>2 1,-10,100,2:TLC
* J=(A$,1,1)):I=(A$,2,1))
4% I<1 I>3 1,-10,100,2:TLC
>% J<1 J>3 1,-10,100,2:TLC
H A(I,J)=1 DzC
R B(I,J)=1 DzC
\A(I,J)=1
f 0,25);(100)
p
z* 0,28);"Position already"'"occupied"
1,-10,100,2
TLC
BOARD
J=1 3
I=1 3
# A(I,J)=1 I*3+2,J*6);"X";
$ B(I,J)=1 I*3+2,J*6);"O";
. A(I,J)+B(I,J)=0 I*3+2,J*6);" ";
I
J
INIT
A(3,3)
B(3,3)
X(4),Y(4)
$
BOARD
. 23;8202;0;0;0;
8 0,3
B 4,450,900
L 1,0,-600
V 4,650,900
` 1,0,-600
j 4,250,525
t
1,600,0
~ 4,250,725
1,600,0
FIN=0
DR=0
3
128
0,30);"I WIN"
dqD
0,30);"DRAW"
dqD
0,30);"YOU WIN"
*FX15,0
"Another game Y/N",A$
A$="N" !-4