Skip to content

Credit Baritone, and adopt its octile + Y heuristic shape#9

Open
XaXayo12 wants to merge 3 commits into
Minecraft-Pathfinding:2026-rewritefrom
XaXayo12:heuristic-credit
Open

Credit Baritone, and adopt its octile + Y heuristic shape#9
XaXayo12 wants to merge 3 commits into
Minecraft-Pathfinding:2026-rewritefrom
XaXayo12:heuristic-credit

Conversation

@XaXayo12

Copy link
Copy Markdown

Follow-up to #8 (tick-based costs), which merged before these two review items landed.

1. Specific credit to Baritone

The cost constants and the heuristic come from Baritone (Leijurv and contributors, LGPL-3.0). Named the exact sources where they are used:

  • costs.ts: the ActionCosts interface for the tick constants.
  • goals.ts: GoalXZ / GoalYLevel for the heuristic.
  • docs/MovementCosts.md and a new README Credits section.

2. Heuristic, compared to Baritone

Gen asked to compare goals.ts to how Baritone handles its heuristic. Baritone splits the estimate into a horizontal octile part (GoalXZ: a diagonal run plus a straight run) and a separate vertical part (GoalYLevel: jump up / fall down), rather than one 3D straight-line distance. I adopted that shape (heuristicXZ + heuristicY in goals.ts), which matches how the bot actually moves.

Where we deliberately differ (with measurements)

Baritone scales by the sprint cost (costHeuristic ≈ 3.563), which is admissible, so its A* is guaranteed optimal. We keep the walk cost instead, for a measured reason: this A* uses a plain binary heap with no f-tie-breaker, so the admissible sprint weight floods an equal-cost plateau on open ground.

Benchmarked (deterministic node counts, flat goals):

goal sprint weight (admissible) walk weight (this PR)
flat 150×40 4281 visited, ~199ms 151 visited, ~9ms
flat 100 straight 201 101
flat 200 straight 344 201

Same path cost, but the admissible weight does up to ~28x more work here. Baritone avoids the plateau with tie-breaking and short path segments this implementation does not have. Walk keeps the fast beeline; node counts are identical to the current heuristic, and the suboptimality bound is ~1.3x (walk/sprint).

Verification

  • npm run build and npx ts-standard -y clean.
  • npm test 31/31.
  • Deterministic bench: identical visited/generated node counts to the pre-PR heuristic.

Two follow-ups from review:

1. Specific Baritone credit. The cost constants and the heuristic come from
   Baritone (Leijurv & contributors, https://github.com/cabaletta/baritone,
   LGPL-3.0). Named the exact sources (ActionCosts, GoalXZ, GoalYLevel) in
   costs.ts, goals.ts, docs/MovementCosts.md and a README Credits section.

2. Heuristic, compared to Baritone. Baritone splits the estimate into a
   horizontal "octile" part (GoalXZ: diagonal run + straight run) and a vertical
   part (GoalYLevel: jump up / fall down), and scales by the SPRINT cost so it is
   admissible (optimal paths). Adopted that SHAPE (heuristicXZ + heuristicY in
   goals.ts) instead of the rough 3D-Euclidean distance.

   Kept the WALK weight rather than Baritone's sprint weight, for a measured
   reason: this A* uses a plain binary heap with no f-tie-breaker, so the
   admissible sprint weight floods an equal-cost plateau on open ground (a flat
   150x40 goal: ~4300 nodes visited vs ~150 with the walk weight, same path).
   Baritone avoids that with tie-breaking + short segments we do not have. Walk
   weight keeps the fast beeline; node counts are identical to before.

Verified: build + ts-standard clean, 31/31 tests pass, deterministic bench shows
identical visited/generated node counts to the previous heuristic.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bd349ee80e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/mineflayer-specific/goals.ts
XaXayo12 added 2 commits June 19, 2026 17:55
…ristic

Review catch (chatgpt-codex): isEnd() used heuristic() as a distance gate
(`dist > this.distance + 3`). Now that heuristic() is the octile+vertical TICK
estimate, a normal close look (e.g. standing diagonally adjacent to a floor
block, ~1.3 blocks away) scores ~7.6 ticks and is rejected before the raycast;
the old Euclidean-scaled value was ~6.1 and passed. Use distHeuristic() (real
block distance) for the gate, which is what `this.distance` is measured in.
Affects GoalLookAt and its subclasses GoalMineBlock / GoalPlaceBlock.
Review catch (deep review): GoalBlock.distHeuristic multiplied by COST_HEURISTIC
(tick units) while every other goal's distHeuristic returns raw block distance
(GoalNear, GoalNearXZ, GoalLookAt, GoalFollowEntity). The only magnitude consumer
is PartialPathProducer.maxPathLength = min(partialPathLength, goal.distHeuristic(start)),
compared against result.path.length (a move COUNT). So GoalBlock's inflated value
(~4.6x) let a GoalBlock partial segment grow ~4.6x longer than the same-distance
GoalNear/GoalNearXZ segment before being cut. Pre-existing inconsistency surfaced
while reviewing the heuristic changes; drop the factor so all goals agree.

Verified: build + ts-standard clean, 31/31 tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant