Stage 1 gave you the seed. Stage 2 lets you grow it.
Each click after the first attempts to add a new land cell to the island —
but only if it passes the same three-part test that Java's
Island.isValidExpansion() enforces.
The Three-Part Validity Test
A clicked cell is accepted if all three rules pass:
- In bounds — the cell must be inside the 20×30 ocean grid.
- Empty — the cell must not already be part of the island.
- Orthogonally adjacent — at least one of its four
neighbors (up, down, left, right) must already be in the island.
Diagonal adjacency is explicitly not enough.
The third rule is why the Java code uses DR4/DC4
(four orthogonal directions) and not DR8/DC8
(eight directions including diagonals) when collecting expansion candidates.
You can test this by clicking a cell that only touches a corner of your island
— it will be rejected.
Visual Feedback
-
Faint green tint — shows before you click: every cell
that is currently a legal move. This is the candidates list that
Island.grow() builds (one orthogonal neighbor per island cell,
de-duplicated) before shuffling and recursing. Seeing it live here makes
that collection step concrete before Stage 3 automates it.
-
Light green fill — a cell you clicked that was
accepted and added to the island.
-
Fading red flash — a cell you clicked that was
rejected (not adjacent to the island). The flash alpha-fades over about
one second so it doesn’t permanently clutter the grid.
-
Orange — the original seed cell, always visually
distinct from grown cells so you can see where the island started.
The Java Connection
The validation logic in handleCellClick() mirrors
Island.isValidExpansion() rule for rule:
- Bounds check →
row ≥ 0 && row < numRows && …
- Water check →
ocean[row][col] == 0 → here: isInIsland(row, col)
- Orthogonal adjacency → loop over
DR4/DC4 → here: isOrthogonalNeighbor(row, col)
There is still no SWIsland class. The island is a plain JavaScript
array of { row, col, square, isSeed } objects. A dedicated class
will be introduced once the automatic growth algorithm is in place.
The Road Ahead
Stage 2 → you grow the island manually, one click at a time.
Stage 3 → the computer grows it automatically using recursive backtracking
(JS port of Island.grow()).
Stage 4 → animate the growth step-by-step, one cell per frame.
Later → introduce a SWIsland class to encapsulate the logic.