Skip to content

Add MAZE — generalized BFS / weighted shortest-path search#187

Merged
jimmytacks merged 3 commits into
mainfrom
lambda-maze
May 20, 2026
Merged

Add MAZE — generalized BFS / weighted shortest-path search#187
jimmytacks merged 3 commits into
mainfrom
lambda-maze

Conversation

@jimmytacks
Copy link
Copy Markdown
Collaborator

@jimmytacks jimmytacks commented May 20, 2026

Summary

  • Adds MAZE to the maps library, recreating the BFSMaze_2 body from issue verbatim
  • Coordinate-frame map range + optional Cost surface, walkability mask, custom direction set, and per-edge cost LAMBDA
  • 7 functional tests cover full-grid output, target-list lookup, walkability detour, custom cost surface, the step counter, and a diagonal-1.5× Mazelam

Per the issue's explicit request, the body is reproduced exactly — parameter names (mp, st, Cost, Targets, No_Diag, Allowmp, Show_Steps, Cus_Dir, Mazelam) are preserved as-written. A second commit will rename internal LET variables for readability and re-verify against the test suite.

Notes on the body's "step count"

Show_Steps=TRUE returns the body's internal st_ value, not pure BFS depth. st_ is built as SEQUENCE(ROWS(ft),,0) + SEQUENCE(,COUNTA(xRC),n+1,0) — so it adds the source cell's index within the current frontier to the iteration counter. Example: with 8-way moves, E5 reached from C3 (via D4 at frontier index 2 in iteration n=1) returns 2 + 2 = 4, not 2. The test case asserts the actual value so any future refactor preserves behaviour.

Test layout note

The full-distance-grid test seeds its map at G3:I5 rather than C3:E5 to avoid colliding with the 3×3 spill that originates at A1 in the harness.

Closes #184

Test plan

  • dotnet build addin/lambda-boss.slnx — succeeded
  • dotnet test addin/lambda-boss.Tests/lambda-boss.Tests.csproj --filter "FullyQualifiedName~LambdaFormatTests" — 432/432 passed
  • dotnet test addin/lambda-boss.AddinTests/lambda-boss.AddinTests.csproj --filter "FullyQualifiedName~LambdaHarnessTests.LambdaTest" — 459/459 passed (including 7 new MAZE tests)
  • Tim to spot-check in Excel: =MAZE(yourMap, "C3") should spill the full 8-way distance grid; =MAZE(yourMap, "C3", , "E5", TRUE) should return a 4-way Manhattan distance

🤖 Generated with Claude Code

jimmytacks and others added 3 commits May 20, 2026 13:07
Body recreated verbatim from issue #184 (BFSMaze_2 spec); parameter
names preserved as-written so the first commit faithfully matches the
source. Internal LET-variable renames for readability are deferred to
a follow-up commit.

Capabilities: coordinate-frame map range, optional Cost surface,
optional Targets list, 4-way / 8-way / custom direction sets, optional
walkability mask, and a user-supplied per-edge cost LAMBDA. With
Targets omitted the function returns the full distance grid spanning
the map; with Targets provided it returns a column of distances
(NA for unreachable).

Tests cover uniform-cost full-grid output, target-list lookup,
walkability detour, custom cost surface, the step counter, and a
diagonal-1.5x Mazelam. The full-grid case is laid out at G3:I5 so the
3x3 spill from A1 doesn't collide with seeded data.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
For lambdas whose output spills as a full-grid-shape array from A1, a
seeded input range that overlaps the spill rectangle produces #SPILL!
and surfaces in the harness as the same NullReferenceException at
Marshal.ReleaseComObject seen for scalar/error returns — easy to
misdiagnose. Captured the cause, the safe layout (data starting at
col output_cols+2), and the note that scalar-output cases are unaffected.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pure rename — every user-facing parameter (mp, st, Cost, Targets,
No_Diag, Allowmp, Show_Steps, Cus_Dir, Mazelam) is unchanged, and no
logic, ordering, or formula was modified.

Key renames inside the body:

  xRC    → moveSet      (active direction set)
  nv     → noRowCol     (mp is array constant, not real range)
  cn/rn  → colArr/rowArr
  rcn    → posGrid      (row*M + col encoded)
  ir/ic  → rowOffset/colOffset
  rcst   → startPos
  costG  → costGrid
  mpA    → walkMask
  fx/lfx → recurse/self (recursive helper + self-reference)
  ft/n   → frontier/iter
  fcl/fdist/fprev    → frontPos/frontDist/frontPrev
  cf/rf/clf          → fromPos/fromRow/fromCol
  ct/rt/clt          → toPos/toRow/toCol
  conf/cont          → costFrom/costTo
  df/dr/prev         → distFrom/dirDelta/prevDir
  pd                 → bestSoFar
  ift/al/nd/nft      → proposals/walkOK/stepCost/newFrontier
  au/a inside nft    → newKeys/merged
  b/bu inside npool  → poolSorted/poolKeys
  rs/end/z           → finalPool/output/outCol
  t in MAP           → tgt

The Mazelam call site now reads with names that match the documented
contract — Mazelam(costFrom, costTo, ..., distFrom, dirDelta, prevDir).

Verified with 432/432 format tests and 459/459 harness tests.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jimmytacks jimmytacks merged commit fc1b109 into main May 20, 2026
1 check passed
@jimmytacks jimmytacks deleted the lambda-maze branch May 20, 2026 13:43
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.

LAMBDA idea: BFSMaze (pathfinding)

1 participant