From 71f2a4260fafe71e50257319fdb32579c589d6dd Mon Sep 17 00:00:00 2001 From: xmanrui <841206367@qq.com> Date: Sun, 1 Mar 2026 12:51:21 +0800 Subject: [PATCH] fix(bugs): prevent single-bug circling behavior --- lib/pixel-office/bugs/bugSystem.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pixel-office/bugs/bugSystem.ts b/lib/pixel-office/bugs/bugSystem.ts index 90f93e4..1c0c6f7 100644 --- a/lib/pixel-office/bugs/bugSystem.ts +++ b/lib/pixel-office/bugs/bugSystem.ts @@ -530,7 +530,11 @@ export class BugSystem { const sample = this.pheromones.sampleDirection(bug.x, bug.y, BUG_TRAIL_FOLLOW_RADIUS) const enterFollowP = Math.min(1, BUG_TRAIL_FOLLOW_PROB * (dt / 0.016)) const breakFollowP = Math.min(1, BUG_TRAIL_BREAK_PROB * (dt / 0.016)) - if (!bug.followingTrail && sample.strength > BUG_PHEROMONE_MIN_DETECT && Math.random() < enterFollowP) { + const canFollowTrail = nCount >= 1 + if (!canFollowTrail) { + // Prevent single-bug self-tracking loops (circling around its own pheromone). + bug.followingTrail = false + } else if (!bug.followingTrail && sample.strength > BUG_PHEROMONE_MIN_DETECT && Math.random() < enterFollowP) { bug.followingTrail = true } else if (bug.followingTrail && Math.random() < breakFollowP) { bug.followingTrail = false @@ -558,7 +562,7 @@ export class BugSystem { } } - if (sample.strength > BUG_PHEROMONE_MIN_DETECT) { + if (canFollowTrail && sample.strength > BUG_PHEROMONE_MIN_DETECT) { const plen = Math.hypot(sample.x, sample.y) if (plen > 0.0001) { const followW = bug.followingTrail ? BUG_TRAIL_STEERING_WEIGHT : BUG_PHEROMONE_FOLLOW_WEIGHT