Regression: legal-move generation still dominates search, so hard never gets past depth 3
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 38/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript
- 領域
- backend, performance
調査の方向性
Start with js/rules.js at legalMovesFrom, allLegalMoves and allLegalCaptures, then read the search and quiescence call sites in js/ai.js. Run npm test and use the provided Node benchmark steps to compare move generation with evaluation. Done means all acceptance criteria pass, including the generator cross-checks and the hard depth 4 timing target.
索引モデルが issue の本文から書いたものです。
説明
Summary
#86 was closed, but legal-move generation is still the main cost of the engine search. It costs about 40 times as much as evaluation. As a result, the "hard" level never finishes a search deeper than its base depth of 3, and its maxDepth: 8 cannot be reached.
Where
js/rules.js:243-270(legalMovesFrom)js/rules.js:302-360(allLegalMoves,allLegalCaptures)js/ai.js:16(hard: { depth: 3, timeMs: 1000, maxDepth: 8 })js/ai.js:118,js/ai.js:201(search and quiescence call sites)
Details
For every piece, legalMovesFrom tests all 64 target squares with isPseudoLegalMove and isPathObstructed. For each candidate move it copies the whole board (applyMove) and runs isInCheck. The search calls this at every interior node, and quiescence calls allLegalCaptures, which also runs one applyMove per capture.
Measured in Node on a middlegame position:
| Operation | Cost |
|---|---|
allLegalMoves |
685 µs per call |
allLegalCaptures |
173 µs per call |
evaluatePosition |
17.5 µs per call |
| Depth-3 search | 1.1 s, 10.7k nodes |
| Depth-4 search | 16.9 s, 115k nodes |
Impact
hard is allowed about 1 s, or at most 3 s on the clock (searchBudget), so iterative deepening never completes depth 4. The worker then spends the rest of its allowance on a depth-4 search that is thrown away. Hard plays at its fixed depth, and every computer move and every hint keeps a core busy for the full allowance. On phones, depth 3 alone takes longer than the 1 s allowance. The same constant also makes review scoring (see the issue on review steps) and the no-worker fallback slow.
Steps to reproduce
- Time
searchPositionat depth 3 and depth 4 on a middlegame position, usingrules.jsandai.jsin Node or in a jest test. - Compare the cost of
allLegalMoveswith the cost ofevaluatePosition.
Suggested fix
- Generate pseudo-legal moves from piece offsets and sliding rays instead of scanning all 64 squares.
- Check legality only where it can fail: king moves, pinned pieces (one ray scan from the king), en passant, and positions in check.
- Or defer the legality test until the search actually plays a move, and count a node with no legal child as mate or stalemate.
- Make and unmake moves on one board (or a flat 64-entry array) instead of copying it for each move.
- Then add move ordering (MVV-LVA, killer moves).
Keep the public functions in rules.js as wrappers so callers and tests don't change. The existing generator cross-check tests ("quick generators agree") act as a perft-style safety net.
Acceptance criteria
-
allLegalMovesis at least 5 times faster on the benchmark position. - Hard completes depth 4 within its 1 s allowance on desktop.
- All rules tests and generator cross-checks pass unchanged.
Getting started
- Relevant files:
js/rules.js,js/ai.js,tests/unit/rules.test.js,tests/unit/ai-strength.test.js - How to run tests:
npm test
Regression of #86.
Filed by repo-audit/full-audit at 01c6a35. Severity: medium. Effort: M. audit-key: performance|js/rules.js|legalMovesFrom
- 主要言語
- JavaScript
- スター
- 4
- フォーク
- 2
- 平均マージ
- 22時間 16分
- マージ済み PR(30日)
- 9
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
TMHSDigital/Static_Chess のほかの issue
-
enhancement help wanted severity: low
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
TMHSDigital/Static_Chess#184 ·
メンテナーはふだん 1 日以内に返信
-
enhancement help wanted severity: low
難易度 4/5 3〜5日 初心者へのやさしさ 58/100
TMHSDigital/Static_Chess#182 ·
メンテナーはふだん 1 日以内に返信
-
help wanted severity: medium tech-debt
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
TMHSDigital/Static_Chess#173 ·
メンテナーはふだん 1 日以内に返信
-
severity: medium tech-debt
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
TMHSDigital/Static_Chess#171 ·
メンテナーはふだん 1 日以内に返信
-
enhancement help wanted severity: low
難易度 4/5 3〜5日 初心者へのやさしさ 61/100
TMHSDigital/Static_Chess#161 ·
メンテナーはふだん 1 日以内に返信
TMHSDigital/Static_Chess の issue をすべて見る
似ている issue
-
priority: low server testing
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
blamechris/chroxy#9277 ·
メンテナーはふだん 1 日以内に返信
-
[MCP]: page snapshots in .playwright-mcp/ are not git-ignored (.playwright-cli/ is, since #42318)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
microsoft/playwright#44289 ·
メンテナーはふだん 1 日以内に返信
-
Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Ionaru/easy-markdown-editor#657 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
TMHSDigital/Free-Game-Dev-Assets#320 ·
メンテナーはふだん 1 日以内に返信
-
area:webapp bug finding
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信