Skip to content

fix(pathfinding): added circular path detection and bail for wallhug#4603

Draft
cerwym wants to merge 1 commit intodkfans:masterfrom
cerwym:master
Draft

fix(pathfinding): added circular path detection and bail for wallhug#4603
cerwym wants to merge 1 commit intodkfans:masterfrom
cerwym:master

Conversation

@cerwym
Copy link
Contributor

@cerwym cerwym commented Mar 4, 2026

Adds history and removes old 90 degree wallhug state logic with proper circular loop check

Copilot AI review requested due to automatic review settings March 4, 2026 21:33
@cerwym cerwym linked an issue Mar 4, 2026 that may be closed by this pull request
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the wallhug pathfinding logic to detect circular movement patterns (loops) using a short position history, replacing the previous “90-degree retry” wallhug state handling.

Changes:

  • Add an 8-sample position history + counters to struct Navigation for loop detection.
  • Introduce update_position_history() and check_for_circular_path() helpers in ariadne_wallhug.c.
  • Replace the old wallhug retry/state logic with a “circular loop detected → flip wallhug side” bailout.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/ariadne_wallhug.c Adds position-history tracking and loop detection; swaps out previous retry-based wallhug logic for loop-based bailout.
src/ariadne.h Extends struct Navigation with loop-detection state (history buffer + indices/counters).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Position history for circle detection
struct Coord3d position_history[8];
unsigned char history_index;
unsigned char loop_counter;
Copy link

Copilot AI Mar 4, 2026

Choose a reason for hiding this comment

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

Adding fields to struct Navigation changes sizeof(struct CreatureControl) and therefore sizeof(struct Game) (since game_legacy.h embeds cctrl_data[]). The save loader (load_game_chunks) rejects saves when hdr.len != sizeof(struct Game), so this will make existing savegames incompatible. If preserving save compatibility matters, the save chunk needs a version bump and backward-compatible load path (or this needs to be explicitly documented as a breaking change).

Suggested change
unsigned char loop_counter;

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Working on prevention of save game breaks

@cerwym
Copy link
Contributor Author

cerwym commented Mar 4, 2026

Put back in draft while working on avoiding save break

@cerwym cerwym marked this pull request as draft March 4, 2026 22:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/ariadne_wallhug.c:134

  • The doc comment says this function detects a "circular path", but the current implementation only checks whether the creature is within a fixed distance of any previous sample and increments a counter. That logic can also trigger for backtracking, small jitter, or being stationary, which isn't necessarily a circle. Either tighten the detection to match the comment (eg, detect repeated cycles with sufficient displacement), or update the comment to accurately describe the heuristic being used.
/// @brief Checks if the creature is moving in a circular path.
/// @param creatng The creature to check.
/// @return True if a circular path is detected, false otherwise.
static TbBool check_for_circular_path(struct Thing *creatng)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Imps run around incircles sometimes, often around pillars

2 participants