AI News HubLIVE
站内改写2 min read

ZCode

A detailed record of building an intelligent Gomoku game from scratch, featuring heuristic AI, win detection, and a fully local browser interface.

SourceHacker News AIAuthor: chvid

Create an intelligent Gomoku (Five-in-a-Row) game where the player competes against a smart algorithm that can make strategic moves and accurately detect winning conditions.

05:10 PM

Worked for 3m 1s

I’m going to inspect the current Gomoku project structure first, then I’ll identify what already exists for board state, rendering, and game flow before wiring in AI and win detection.

Explored

1 search, 1 fileFailed

Ran

pwd

Searched

List in ~/ryan/gomoku-aiFailed

The repository looks either empty or nearly empty. I’m checking the actual directory contents now and confirming whether there’s an existing app to extend or whether I should build the game from scratch.

Ran

git status --shortFailed

$git status --short

2026-04-19 17:10:16.280 xcodebuild[60663:50240053] DVTFilePathFSEvents: Failed to start fs event stream. git: warning: confstr() failed with code 5: couldn't get path of DARWIN_USER_TEMP_DIR; using /tmp instead fatal: not a git repository (or any of the parent directories): .git

There isn’t an existing app here, so I’m building a self-contained implementation from scratch. I’m checking whether there are any local project conventions to respect, then I’ll add a browser-based Gomoku with a heuristic AI, turn handling, and explicit five-in-a-row detection.

Wrote

,,

+733

Wrote

+62

Wrote

+471

Wrote

+200

The full UI and core logic are in place. I’m verifying the JavaScript parses cleanly and reviewing the move-scoring logic for edge cases like first-move response, draw handling, and long-line wins.

Ran

node --check app.js

$node --check app.js

No output.

I found one avoidable dependency: the page was pulling a web font. I’m removing that so the game stays fully local and works by opening index.html with no network requirement.

Updated

,

+1 -7

Updated

+1-1

Updated

-6

Built a standalone browser Gomoku game in , , and . It renders a 15x15 board, lets the player place black stones, detects wins in all four directions, highlights the winning line, tracks turns and move count, and supports restarting the match.

The AI is heuristic rather than random. It searches nearby candidate moves, scores offensive patterns for itself, scores defensive blocks against the player, adds center preference, and chooses the strongest move. There's also an optional “AI focus area” overlay so you can see the strongest candidate points it considered.

Verification: node --check app.js passed. I did not run an interactive browser session here, so the remaining step is to open in a browser and play.

app.js

+471-0

index.html

+62-6

styles.css

+201-1