Corner and Edge Strategy
The AI now values strategic positions. Corners get priority, edges matter.
The AI now considers adjacency and defense, but it treats all board positions equally. A corner cell scores the same as a centre cell if they have the same neighbours. But in territory games, corners and edges are strategically different — they have fewer adjacent cells, making them easier to secure.
This unit adds positional awareness. Corners get a +2 bonus, edges get +1. The AI now prefers strategic positions, especially in the opening when few cells have neighbours.
Run It
pasmonext --sna inkwar.asm inkwar.sna

Watch the AI’s opening moves. It now gravitates toward corners and edges rather than claiming random centre cells.
Why Corners Matter
Consider a corner cell at position (0,0):
- Only 2 adjacent cells: (0,1) and (1,0)
- Easier to “secure” — fewer cells needed to surround it
Compare to a centre cell at (3,3):
- 4 adjacent cells: up, down, left, right
- More contested — more ways for opponents to claim adjacent territory
In games like Reversi/Othello, corners are famously valuable because once claimed, they can’t be flipped. Our game doesn’t have flipping, but the strategic principle remains: fewer neighbours means less exposure.
Position Bonus Calculation
The new function determines if a cell is a corner, edge, or centre:
This code sample could not be loaded. The file may be missing or the path may be incorrect.
The logic:
- Extract row and column from the cell index
- Check if row is 0 or 7 (top/bottom edge)
- Check if column is 0 or 7 (left/right edge)
- Corner = both row AND column are edges
- Edge = either row OR column is edge (but not both)
- Centre = neither
Combined Scoring
The position bonus adds to the existing adjacency score:
This code sample could not be loaded. The file may be missing or the path may be incorrect.
Three factors now contribute to each cell’s value:
- Adjacent AI cells (offense)
- Adjacent human cells (defense)
- Position bonus (strategy)
Opening Game Impact
The position bonus has the biggest impact early in the game:
Without position bonus (Unit 11):
- First AI move is random (no neighbours yet)
- Any empty cell scores 0
- No preference for strategic positions
With position bonus (Unit 12):
- Corner cells score 2 even with no neighbours
- Edge cells score 1
- AI prefers corners > edges > centre
As the game progresses and cells accumulate neighbours, adjacency scores dominate. But the opening moves now show strategic awareness.
The Board Layout
Visualising the position bonuses:
2 1 1 1 1 1 1 2 <- corners (2) and top edge (1)
1 0 0 0 0 0 0 1 <- left/right edges (1), centre (0)
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 1
2 1 1 1 1 1 1 2 <- corners (2) and bottom edge (1)
24 edge cells (including 4 corners) get bonuses. The remaining 40 centre cells get none.
The Complete Code
This code sample could not be loaded. The file may be missing or the path may be incorrect.
Try This: Higher Corner Value
Make corners even more attractive:
.gpb_corner:
ld a, 4 ; Corner bonus = 4
ret
.gpb_edge:
ld a, 2 ; Edge bonus = 2
ret
This makes the AI aggressively pursue corners, even over contested centre cells.
Try This: Centre Preference
Or flip the strategy entirely:
get_position_bonus:
; ... extract row/col ...
; Check if centre (not edge)
ld a, b
or a
jr z, .gpb_edge
cp 7
jr z, .gpb_edge
ld a, c
or a
jr z, .gpb_edge
cp 7
jr z, .gpb_edge
; Centre - give bonus
ld a, 2
ret
.gpb_edge:
xor a
ret
This creates an AI that prefers the centre, leaving corners for later.
What You’ve Learnt
- Positional evaluation — Static bonuses based on board location
- Multi-factor scoring — Combining adjacency + defense + position
- Opening strategy — Early moves now show preference
- Edge detection — Checking if values equal 0 or maximum
What’s Next
In Unit 13, we’ll add difficulty levels — letting players choose between easy (random), medium (adjacent), and hard (full strategy) AI opponents.