The Board
A nine-cell array is the board; an INT-divide turns each cell number into a row and column, and the grid is drawn with PLOT and DRAW.
Noughts and Crosses needs somewhere to keep the board. Nine cells, numbered 1 to 9, each empty or holding a cross or a nought — a single array does it, and the cell number doubles as the player's input later.
10 BORDER 0: PAPER 0: INK 7: CLS
90 DIM b(9)
120 CLS
130 LET a$ = "*** THREE IN A ROW ***": LET y = 0: GO SUB 9000
150 INK 7: FOR i = 0 TO 3: PLOT 80 + i * 32, 55: DRAW 0, 96: NEXT i
160 FOR i = 0 TO 3: PLOT 80, 55 + i * 32: DRAW 96, 0: NEXT i
170 FOR n = 1 TO 9
180 LET row = INT ((n - 1) / 3)
190 LET col = n - 1 - row * 3
200 LET cx = 100 + col * 32: LET cy = 131 - row * 32
210 IF b(n) = 0 THEN PRINT AT 5 + row * 4, 12 + col * 4; CHR$ (48 + n)
240 NEXT n
250 STOP
9000 PRINT AT y, (32 - LEN a$) / 2; BRIGHT 1; a$
9010 RETURN
Nine cells in one array
DIM b(9) (line 90) is the board — nine cells you met as arrays in Quiz Master, each starting at
0 for empty. Numbering them 1 to 9 is the trick the whole game turns on: the cell number is
both where a mark lives in the array and what the player types to place it. Sonar used two indices
for a grid; here a single index runs across the 3×3, because the player thinks of the squares as
1 to 9, not as rows and columns.
From cell number to position
The drawing loop still has to place each cell on a 3×3 grid, so lines 180–190 convert. `INT((n -
- / 3)
gives the row (0, 1 or 2) and the remainder gives the column — the standard way to fold a flat count onto a grid.INTyou met rounding random numbers; here it does integer division. Lines 150–160 rule the grid withPLOTandDRAW, and line 210 prints each empty cell's number withCHR$(48 + n)` so the digit sits cleanly inside its square.
Next: let the player take a square.