Skip to content

Tick-based movement costs (replace arbitrary numbers)#8

Merged
GenerelSchwerz merged 1 commit into
Minecraft-Pathfinding:2026-rewritefrom
XaXayo12:tick-based-costs
Jun 18, 2026
Merged

Tick-based movement costs (replace arbitrary numbers)#8
GenerelSchwerz merged 1 commit into
Minecraft-Pathfinding:2026-rewritefrom
XaXayo12:tick-based-costs

Conversation

@XaXayo12

Copy link
Copy Markdown

What

Redesigns every movement provider so its cost is a game-tick time estimate instead of an arbitrary number, completing the Baritone-based cost work whose constants already lived (unused) in costs.ts.

Why

Costs used to be made-up: forward = 1, diagonal = √2, jump = +0.5, a 3-block drop = +1.5, break = 1 + 3·digTime/1000. They had no shared unit, so A* couldn't honestly compare "walk around" vs "dig through" vs "drop down". Now everything is ticks (20/sec), so those comparisons are real.

Changes

  • travelCost(blocks) helper on Movement: sprint (or walk) time per block.
  • Base costs now use the tick constants for Forward, Diagonal, ForwardJump, ForwardDropDown, StraightDown, StraightUp, ParkourForward, ParkourDiagonal (SPRINT/WALK_ONE_BLOCK_COST, JUMP_ONE_BLOCK_COST, FALL_N_BLOCKS_COST, WALK_OFF_BLOCK_COST, LADDER_UP_ONE_COST).
  • breakCost: real mining time in ticks (ms / 50) instead of the old made-up formula.
  • movement.ts defaults (liquidCost, placeCost, jumpCost, digCost) are now tick-based and documented.
  • COST_HEURISTIC constant replaces the repeated 20 / 4.317 magic number in goals.ts.
  • New docs/MovementCosts.md explaining the whole model.

No new block lookups, no splice, Move.cost stays read-only (costs are folded in before Move.fromPrevious).

Heuristic / optimality

The heuristic was already in ticks at the walk cost per block. Kept it there (not the cheaper sprint cost) on purpose: A* stays a lightly weighted search — the same fast beeline as before — but returned paths are now ≤1.3× optimal (walk/sprint = 4.633/3.564) instead of the old ~4.6× (per-move cost was ~1 while the heuristic was ~4.633). Same speed, much better paths.

Verification

  • npm run build ✅ and npx ts-standard -y ✅ (clean).
  • npm test31/31.
  • Deterministic benchmark over flat 100–200 block goals: identical visited / generated node counts before and after (no search regression); path costs are now realistic ticks (e.g. 100 sprint-blocks = 361 ticks ≈ 18 s).
  • Updated the hard-exclusion detour test: with realistic costs A* now finds the optimal detour around the wall using diagonals at the same move count (swings out to |z| ≥ 4, 0 nodes inside the zone), so the old "must be > 21 moves" proxy was wrong; the test now asserts the geometric detour directly.

Every movement provider used made-up costs (forward = 1, diagonal = sqrt2,
jump = +0.5, a 3-block drop = +1.5, break = 1 + 3*digTime/1000). They had no
shared unit, so A* could not honestly compare "walk around" vs "dig through"
vs "drop down". Now every cost is measured in game ticks (20/sec) using
Baritone's hardcoded estimates, which already lived (unused) in costs.ts.

- travelCost(blocks): sprint (or walk) time per block.
- Forward / Diagonal: travelCost(1) / travelCost(sqrt2).
- ForwardJump: max(jump arc, walk) - you rise and move at once.
- ForwardDropDown / StraightDown: walk-off + real FALL_N_BLOCKS_COST fall time.
- StraightUp: ladder speed when climbing, else jump + place.
- Parkour (forward + diagonal): jump + sprint time across the gap.
- breakCost: real mining time in ticks (ms / 50), not a made-up formula.
- movement.ts defaults: liquid / place / jump / dig costs are now tick-based.

The goal heuristic was already in ticks (walk cost per block). Kept it at the
walk cost (not the cheaper sprint cost) on purpose: A* stays a lightly weighted
search - same fast beeline - but returned paths are now <=1.3x optimal
(walk / sprint = 4.633 / 3.564) instead of the old ~4.6x (per-move cost was ~1
while the heuristic was ~4.633). Centralized that number as COST_HEURISTIC.

Verified: build + ts-standard clean, 31/31 tests pass. A deterministic flat
benchmark shows identical visited/generated node counts before and after (no
search regression); only path quality improves. Added docs/MovementCosts.md.

The hard-exclusion detour test asserted "detour > 21 moves"; with realistic
costs A* now finds the optimal detour around the wall using diagonals at the
same move count (it swings out to |z| >= 4, 0 nodes inside the zone), so that
proxy was wrong. The test now asserts that geometric fact directly.

@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: 73d5642ebd

ℹ️ 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/movements/movementProviders.ts
@XaXayo12

Copy link
Copy Markdown
Author

In-game test (real server)

Ran a real offline-mode vanilla 1.20.4 server (superflat, survival, peaceful) and drove a mineflayer bot with bot.pathfinder.goto(...), capturing the planned path and the bot's actual sampled trajectory / final position. Each scenario teleports to its own clean lane and builds the structure with op commands.

To attribute behavior, I ran the identical harness on this branch and on baseline (2026-rewrite, before the cost change).

scenario baseline (arbitrary) this PR (ticks) reached?
flat straight 25 plan cost 25 plan cost 89.1t (25×3.564 sprint) ✅ both
flat diagonal 18 25.46 90.72t (18×3.564×√2) ✅ both
staircase up (3 steps) 7.5 24.59t (Forward×3 + ForwardJump×3) ✅ both
drop down 3 10 40.01t (ForwardDropDown + Forward×8) ✅ both
wall detour fails fails ❌ both

Result: walking, diagonals, jump-up (ascend) and drop-down all plan with realistic tick costs and physically execute to the goal. The bot reaches the goal in 4/5 scenarios.

The one failure, wall-detour, fails identically on baseline (the bot rounds the wall but then oscillates at the final corner / "Too many failures"). It is a pre-existing executor cornering issue, not introduced by this cost change — planning produces a correct go-around route in both cases. Flagging it separately; out of scope for this PR.

Net: this is a planning/cost change, and the in-game behavior matches baseline's success profile exactly while making the costs reflect real traversal time.

@GenerelSchwerz

Copy link
Copy Markdown
Collaborator

That executor bug looks like a different issue and could use a separate PR fix. This current code LGTM.

@GenerelSchwerz GenerelSchwerz merged commit d0ef472 into Minecraft-Pathfinding:2026-rewrite Jun 18, 2026
1 check passed
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.

2 participants