Skip to content
Game 8 Unit 7 of 16 1 hr learning time

Hidden and Revealed

Add a second array to track which cells the player has uncovered.

44% of Minefield

In a real Minesweeper, you can’t see the numbers until you reveal them. The mine data is hidden — you only see what you’ve uncovered. This needs a second array to track each cell’s visibility.

The Program

10 CLS
20 DIM m(8, 8)
30 DIM s(8, 8)
40 REM m = mine grid, s = state (0=hidden, 1=revealed)
50 REM place 10 mines
60 FOR i = 1 TO 10
70 LET r = INT (RND * 8) + 1
80 LET c = INT (RND * 8) + 1
90 IF m(r, c) = 9 THEN GO TO 70
100 LET m(r, c) = 9
110 NEXT i
120 REM calculate counts
130 FOR r = 1 TO 8
140 FOR c = 1 TO 8
150 IF m(r, c) = 9 THEN GO TO 225
160 LET n = 0
170 FOR i = r - 1 TO r + 1
180 FOR j = c - 1 TO c + 1
190 IF i < 1 OR i > 8 OR j < 1 OR j > 8 THEN GO TO 210
200 IF m(i, j) = 9 THEN LET n = n + 1
210 NEXT j
212 NEXT i
220 LET m(r, c) = n
225 NEXT c
230 NEXT r
240 REM reveal a few cells
250 LET s(1, 1) = 1
260 LET s(4, 4) = 1
270 LET s(7, 2) = 1
280 REM draw grid
290 PRINT "Hidden grid (. = hidden):"
300 FOR r = 1 TO 8
310 FOR c = 1 TO 8
320 IF s(r, c) = 0 THEN PRINT ".";
330 IF s(r, c) = 1 AND m(r, c) = 9 THEN PRINT "*";
340 IF s(r, c) = 1 AND m(r, c) <> 9 THEN PRINT m(r, c);
350 NEXT c
360 PRINT
370 NEXT r
380 PRINT
390 PRINT "Revealed grid (answer key):"
400 FOR r = 1 TO 8
410 FOR c = 1 TO 8
420 IF m(r, c) = 9 THEN PRINT "*";
430 IF m(r, c) <> 9 THEN PRINT m(r, c);
440 NEXT c
450 PRINT
460 NEXT r

How It Works

Line 30 creates the state array: DIM s(8,8). Every cell starts at 0 — hidden.

Lines 250-270 reveal three cells by setting s(1,1) = 1, s(4,4) = 1, and s(7,2) = 1.

Lines 300-370 draw the grid with visibility. The display logic checks s(r,c) first:

320 IF s(r, c) = 0 THEN PRINT ".";
330 IF s(r, c) = 1 AND m(r, c) = 9 THEN PRINT "*";
340 IF s(r, c) = 1 AND m(r, c) <> 9 THEN PRINT m(r, c);
State s(r,c)Display
0 (hidden).
1 (revealed), mine*
1 (revealed), safenumber

Lines 400-460 show the full “answer key” — every cell revealed — so you can verify the hidden view is correct.

Parallel Arrays

Two arrays with the same dimensions, working together:

ArrayPurposeValues
m(r,c)Mine grid0-8 (counts) or 9 (mine)
s(r,c)Cell state0 (hidden) or 1 (revealed)

The mine grid never changes after setup. The state grid changes during gameplay as the player reveals cells. Keeping them separate means the display logic can check both: “what is here?” and “can the player see it?”

Try This

Reveal all. Add a loop that sets every s(r,c) = 1, then redraw. The hidden view should match the answer key.

Random reveals. Reveal 10 random cells instead of 3 fixed ones. Each time you run the program, different cells are visible.

What You’ve Learnt

  • Parallel arrays — two arrays with the same dimensions, different purposes
  • State tracking — 0 for hidden, 1 for revealed
  • Conditional display — check state before deciding what to show
  • Separation of data and visibility — the world exists whether or not you can see it