fix(v0.3.1): mechanical food/stuck fixes — bot reaches the chicken now
The wedge wasn't only in the manifesto layer; several mechanical bugs kept the bot in a dead random-walk: - storyline / manifesto / curriculum: "local food" now means an edible passive mob within <=32 blocks. A distant chicken or a cod no longer fools the bot into dispatching acquire-food (which then fails on no_path). Long-range food goes through scout-food instead. - scout-food: partial approach to a target now counts as progress (approached_target, e.g. moved:14); a blocked heading is NOT counted as movement; added blind/tunnel fallback so it doesn't die when the pathfinder can't route cleanly. - acquire-food: on no_path it now also tries a blind/tunnel approach to the animal; no_drop routes back into food scouting instead of giving up. - explore.far / relocate / flee: fewer false "done" results (micro-steps no longer counted as success), more genuine escapes from stuck. - scripts/show-story.js: live IPC now actually renders the current storyline step. Verification: scripts/lint-patch.js clean; npm test 404/404 green; bot relaunched in tmux `pepa`. Live logs show real progress — bot switched to survive.scout-food, approached the chicken (approached_target moved:14), then reached survive.acquire-food: hunting chicken. Food isn't fully closed yet but the remaining issue is concrete pickup/drop, not dead random-walk. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
+49
-22
@@ -52,6 +52,7 @@ const FOOD_ITEMS = [
|
||||
"apple", "carrot", "potato", "beetroot", "melon_slice", "sweet_berries",
|
||||
"golden_apple", "golden_carrot",
|
||||
];
|
||||
const PASSIVE_FOOD_MOBS = new Set(["cow", "pig", "chicken", "sheep", "rabbit", "mooshroom"]);
|
||||
|
||||
function hasSetItem(inv, set) {
|
||||
if (!inv) return false;
|
||||
@@ -92,6 +93,27 @@ function countPlanks(inv) {
|
||||
return total;
|
||||
}
|
||||
|
||||
function woodBudget(inv) {
|
||||
if (!inv) return 0;
|
||||
const placedOrCarriedTable = (inv.crafting_table ?? 0) > 0 ? 4 : 0;
|
||||
return countLogs(inv) * 4 + countPlanks(inv) + placedOrCarriedTable;
|
||||
}
|
||||
|
||||
function blockCount(snap, kind) {
|
||||
const v = snap?.nearbyBlocks?.[kind];
|
||||
if (typeof v === "number") return v;
|
||||
if (v && typeof v.count === "number") return v.count;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function hasLocalFoodMob(snap, maxDistance = 32) {
|
||||
for (const e of snap?.nearbyEntities?.passives ?? []) {
|
||||
if (!PASSIVE_FOOD_MOBS.has(e?.name)) continue;
|
||||
if ((e.distance ?? Infinity) <= maxDistance) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function emergencyPause(snap) {
|
||||
if (!snap?.connected) return false;
|
||||
const hp = snap.health ?? 20;
|
||||
@@ -120,11 +142,10 @@ export const STORYLINE = Object.freeze([
|
||||
// scan radius might never see logs/stone/crops/beds, and we
|
||||
// were getting stuck on step 1 for hours.
|
||||
if (hp < 18) return false;
|
||||
const sawBlocks = (snap.nearbyBlocks?.logs ?? 0)
|
||||
+ (snap.nearbyBlocks?.stone ?? 0)
|
||||
+ (snap.nearbyBlocks?.crops ?? 0)
|
||||
+ (snap.nearbyBlocks?.beds ?? 0)
|
||||
> 0;
|
||||
const sawBlocks = blockCount(snap, "logs")
|
||||
+ blockCount(snap, "stone")
|
||||
+ blockCount(snap, "crops")
|
||||
+ blockCount(snap, "beds") > 0;
|
||||
if (sawBlocks) return true;
|
||||
// Fallback: settled for long enough → call orient done and let
|
||||
// later steps drive forward into the biome.
|
||||
@@ -140,13 +161,17 @@ export const STORYLINE = Object.freeze([
|
||||
|
||||
{
|
||||
id: "first_wood",
|
||||
title: "Собрать 8 поленьев",
|
||||
narration_ru: "Цель: 8 поленьев. Иду рубить ближайшие деревья.",
|
||||
title: "Собрать стартовое дерево",
|
||||
narration_ru: "Нужно дерево для первого крафта. Доберу минимум и сразу к верстаку.",
|
||||
completed(snap) {
|
||||
return countLogs(snap?.inventory) >= 8;
|
||||
const inv = snap?.inventory ?? {};
|
||||
return woodBudget(inv) >= 16
|
||||
|| hasSetItem(inv, PICKAXE_WOOD)
|
||||
|| hasSetItem(inv, AXE_WOOD)
|
||||
|| hasSetItem(inv, SWORD_WOOD);
|
||||
},
|
||||
suggestSkill(snap) {
|
||||
const trees = snap?.nearbyBlocks?.logs ?? 0;
|
||||
const trees = blockCount(snap, "logs");
|
||||
if (trees > 0) return { skillId: "gather.logs" };
|
||||
// No tree in sight — scout further. In a biome with no trees
|
||||
// (desert, ocean) the bot must commit to a long heading; the
|
||||
@@ -163,17 +188,16 @@ export const STORYLINE = Object.freeze([
|
||||
narration_ru: "Делаю верстак и палки — без них ничего не скрафтить.",
|
||||
completed(snap) {
|
||||
const inv = snap?.inventory ?? {};
|
||||
return (inv.crafting_table ?? 0) > 0
|
||||
&& (inv.stick ?? 0) >= 2
|
||||
&& countPlanks(inv) >= 4;
|
||||
return ((inv.stick ?? 0) >= 2 && countPlanks(inv) >= 4)
|
||||
|| hasSetItem(inv, PICKAXE_WOOD)
|
||||
|| hasSetItem(inv, AXE_WOOD)
|
||||
|| hasSetItem(inv, SWORD_WOOD);
|
||||
},
|
||||
suggestSkill(snap) {
|
||||
const inv = snap?.inventory ?? {};
|
||||
if (countPlanks(inv) < 4) return { skillId: "craft.planks" };
|
||||
if ((inv.stick ?? 0) < 2) return { skillId: "craft.sticks" };
|
||||
// We have raw materials, need to *place* a crafting table for tools.
|
||||
// (No place-table skill yet — flagged as improvement_request elsewhere.)
|
||||
return { skillId: "craft.sticks" };
|
||||
return null;
|
||||
},
|
||||
emergencyPause,
|
||||
},
|
||||
@@ -190,6 +214,11 @@ export const STORYLINE = Object.freeze([
|
||||
},
|
||||
suggestSkill(snap) {
|
||||
const inv = snap?.inventory ?? {};
|
||||
if (countPlanks(inv) < 4) {
|
||||
if (countLogs(inv) > 0) return { skillId: "craft.planks" };
|
||||
return { skillId: "gather.logs" };
|
||||
}
|
||||
if ((inv.stick ?? 0) < 2) return { skillId: "craft.sticks" };
|
||||
if (!hasSetItem(inv, PICKAXE_WOOD)) return { skillId: "craft.wooden-pickaxe" };
|
||||
if (!hasSetItem(inv, AXE_WOOD)) return { skillId: "craft.wooden-axe" };
|
||||
if (!hasSetItem(inv, SWORD_WOOD)) return { skillId: "craft.wooden-sword" };
|
||||
@@ -213,8 +242,7 @@ export const STORYLINE = Object.freeze([
|
||||
// It commits to a cardinal for ~200 blocks, rescans, and
|
||||
// on biome boundary detection heads toward food-capable
|
||||
// terrain.
|
||||
const hasPassiveNearby = (snap?.nearbyEntities?.passives?.length ?? 0) > 0;
|
||||
if (hasPassiveNearby) return { skillId: "survive.acquire-food" };
|
||||
if (hasLocalFoodMob(snap)) return { skillId: "survive.acquire-food" };
|
||||
return { skillId: "survive.scout-food" };
|
||||
},
|
||||
emergencyPause,
|
||||
@@ -225,7 +253,7 @@ export const STORYLINE = Object.freeze([
|
||||
title: "Простой шелтер с кроватью",
|
||||
narration_ru: "Поставлю кровать и стены — пережить ночь.",
|
||||
completed(snap) {
|
||||
return (snap?.nearbyBlocks?.beds ?? 0) > 0;
|
||||
return blockCount(snap, "beds") > 0;
|
||||
},
|
||||
suggestSkill(snap) {
|
||||
const inv = snap?.inventory ?? {};
|
||||
@@ -272,7 +300,7 @@ export const STORYLINE = Object.freeze([
|
||||
},
|
||||
suggestSkill(snap) {
|
||||
const inv = snap?.inventory ?? {};
|
||||
if ((inv.wheat_seeds ?? 0) > 0 && (snap?.nearbyBlocks?.crops ?? 0) > 0) {
|
||||
if ((inv.wheat_seeds ?? 0) > 0 && blockCount(snap, "crops") > 0) {
|
||||
return { skillId: "farm.wheat" };
|
||||
}
|
||||
return { skillId: "survive.acquire-food" };
|
||||
@@ -300,8 +328,7 @@ export const STORYLINE = Object.freeze([
|
||||
title: "Постоянная база",
|
||||
narration_ru: "Выбираю место под деревню — нужно нормальное основание.",
|
||||
completed(snap) {
|
||||
const nb = snap?.nearbyBlocks ?? {};
|
||||
return (nb.beds ?? 0) >= 1 && (nb.storage ?? 0) >= 1;
|
||||
return blockCount(snap, "beds") >= 1 && blockCount(snap, "storage") >= 1;
|
||||
},
|
||||
suggestSkill(snap) {
|
||||
const inv = snap?.inventory ?? {};
|
||||
@@ -335,5 +362,5 @@ export function getStep(id) {
|
||||
// Test exports
|
||||
export const __testing = {
|
||||
countLogs, countPlanks, countAny, hasAny, hasSetItem,
|
||||
FOOD_ITEMS, BED_ITEMS, emergencyPause,
|
||||
FOOD_ITEMS, BED_ITEMS, emergencyPause, blockCount, woodBudget, hasLocalFoodMob,
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ test("STORYLINE: 11 steps, all have id/title/narration/completed/suggestSkill",
|
||||
});
|
||||
|
||||
test("getStep: lookup by id", () => {
|
||||
assert.equal(getStep("first_wood").title, "Собрать 8 поленьев");
|
||||
assert.equal(getStep("first_wood").title, "Собрать стартовое дерево");
|
||||
assert.equal(getStep("does-not-exist"), null);
|
||||
});
|
||||
|
||||
@@ -49,16 +49,18 @@ test("emergencyPause: low hp + close hostile → true", () => {
|
||||
assert.equal(emergencyPause(snap({ food: 0 })), true);
|
||||
});
|
||||
|
||||
test("step first_wood: completed when ≥8 logs", () => {
|
||||
test("step first_wood: completed when bootstrap wood budget is enough", () => {
|
||||
const s = getStep("first_wood");
|
||||
assert.equal(s.completed(snap()), false);
|
||||
assert.equal(s.completed(snap({ inventory: { oak_log: 8 } })), true);
|
||||
assert.equal(s.completed(snap({ inventory: { oak_log: 4, birch_log: 4 } })), true);
|
||||
assert.equal(s.completed(snap({ inventory: { oak_log: 4 } })), true);
|
||||
assert.equal(s.completed(snap({ inventory: { oak_log: 2, oak_planks: 8 } })), true);
|
||||
assert.equal(s.completed(snap({ inventory: { wooden_pickaxe: 1 } })), true);
|
||||
});
|
||||
|
||||
test("step first_wood: suggest gather.logs if trees nearby, explore.far otherwise", () => {
|
||||
const s = getStep("first_wood");
|
||||
assert.equal(s.suggestSkill(snap({ nearbyBlocks: { logs: 5 } })).skillId, "gather.logs");
|
||||
assert.equal(s.suggestSkill(snap({ nearbyBlocks: { logs: { count: 1 } } })).skillId, "gather.logs");
|
||||
assert.equal(s.suggestSkill(snap()).skillId, "explore.far");
|
||||
});
|
||||
|
||||
@@ -77,10 +79,27 @@ test("step first_food: completed at ≥2 food items", () => {
|
||||
assert.equal(s.completed(snap({ inventory: { bread: 2 } })), true);
|
||||
});
|
||||
|
||||
test("step first_food: local hunt only for edible passive mobs within acquire range", () => {
|
||||
const s = getStep("first_food");
|
||||
assert.equal(
|
||||
s.suggestSkill(snap({ nearbyEntities: { passives: [{ name: "chicken", distance: 18 }] } })).skillId,
|
||||
"survive.acquire-food",
|
||||
);
|
||||
assert.equal(
|
||||
s.suggestSkill(snap({ nearbyEntities: { passives: [{ name: "chicken", distance: 51 }] } })).skillId,
|
||||
"survive.scout-food",
|
||||
);
|
||||
assert.equal(
|
||||
s.suggestSkill(snap({ nearbyEntities: { passives: [{ name: "cod", distance: 12 }] } })).skillId,
|
||||
"survive.scout-food",
|
||||
);
|
||||
});
|
||||
|
||||
test("step shelter_minimal: completed when bed placed nearby", () => {
|
||||
const s = getStep("shelter_minimal");
|
||||
assert.equal(s.completed(snap()), false);
|
||||
assert.equal(s.completed(snap({ nearbyBlocks: { beds: 1 } })), true);
|
||||
assert.equal(s.completed(snap({ nearbyBlocks: { beds: { count: 1 } } })), true);
|
||||
});
|
||||
|
||||
test("step stone_tier: needs cobblestone first", () => {
|
||||
@@ -133,6 +152,18 @@ test("pickCurrentStep: bot with 8+ logs → first_wood done, picks crafting_basi
|
||||
assert.equal(r.completedSteps, 2, "orient_self + first_wood done");
|
||||
});
|
||||
|
||||
test("pickCurrentStep: bot with planks and sticks advances to first_tools", () => {
|
||||
_resetForTest();
|
||||
const r = pickCurrentStep(snap({
|
||||
_sessionMs: 60_000,
|
||||
nearbyBlocks: { logs: { count: 3 } },
|
||||
inventory: { oak_planks: 16, stick: 4 },
|
||||
}));
|
||||
assert.ok(r);
|
||||
assert.equal(r.step.id, "first_tools");
|
||||
assert.equal(r.suggestion.skillId, "craft.wooden-pickaxe");
|
||||
});
|
||||
|
||||
test("pickCurrentStep: emergency pauses suggestion", () => {
|
||||
_resetForTest();
|
||||
const r = pickCurrentStep(snap({
|
||||
|
||||
Reference in New Issue
Block a user