diff --git a/lambdas/maps/MAZE.tests.yaml b/lambdas/maps/MAZE.tests.yaml index 1f18726..e9b4fe9 100644 --- a/lambdas/maps/MAZE.tests.yaml +++ b/lambdas/maps/MAZE.tests.yaml @@ -76,7 +76,7 @@ tests: args: ["=theMap", '="C3"', "=costArr", '="E5"', "=FALSE", "=", "=TRUE"] expected: 4 - - name: custom Mazelam — diagonals cost 1.5x + - name: custom Mazelam — inline LAMBDA, diagonals cost 1.5x setup: cells: - address: "C3:E5" @@ -89,6 +89,19 @@ tests: args: ["=theMap", '="C3"', "=", '="E5"', "=FALSE", "=", "=", "=", "=LAMBDA(costFrom,costTo,rowFrom,colFrom,rowTo,colTo,distFrom,dirDelta,prevDir,IF((rowFrom<>rowTo)*(colFrom<>colTo)=1,costTo*1.5,costTo))"] expected: 3 + - name: stock MAZELAM_DIAG passed by name gives same result as the inline LAMBDA + setup: + cells: + - address: "C3:E5" + values: + - [0, 0, 0] + - [0, 0, 0] + - [0, 0, 0] + names: + - { name: "theMap", refers_to: "C3:E5" } + args: ["=theMap", '="C3"', "=", '="E5"', "=FALSE", "=", "=", "=", "=MAZELAM_DIAG"] + expected: 3 + - name: help text args: [] expected_type: array diff --git a/lambdas/maps/MAZELAM_DIAG.lambda b/lambdas/maps/MAZELAM_DIAG.lambda new file mode 100644 index 0000000..5fd4f05 --- /dev/null +++ b/lambdas/maps/MAZELAM_DIAG.lambda @@ -0,0 +1,44 @@ +/* FUNCTION NAME: MAZELAM_DIAG + DESCRIPTION:*//**Stock Mazelam for MAZE: diagonal steps cost 1.5x the destination cell's Cost; cardinal steps cost 1x. Produces realistic Euclidean-ish distance over a uniform map.*/ +/* REVISIONS: Date Developer Description + 2026-05-20 Claude Initial version +*/ +MAZELAM_DIAG = LAMBDA( +// Parameter Declarations + [costFrom], + [costTo], + [rowFrom], + [colFrom], + [rowTo], + [colTo], + [distFrom], + [dirDelta], + [prevDir], +// Help + LET(Help, TEXTSPLIT( + "FUNCTION: →MAZELAM_DIAG(costFrom, costTo, rowFrom, colFrom, rowTo, colTo, distFrom, dirDelta, prevDir)¶" & + "DESCRIPTION: →Stock Mazelam for MAZE: diagonal steps cost 1.5x the destination cell's Cost; cardinal steps cost 1x. Pass by name to MAZE: =MAZE(mp, ""C3"", , , , , , , MAZELAM_DIAG).¶" & + "VERSION: →May 20 2026¶" & + "PARAMETERS: →¶" & + " costFrom →(Required) Cost at the source cell. (Unused by this Mazelam.)¶" & + " costTo →(Required) Cost at the destination cell. Multiplied by 1.5 on diagonals.¶" & + " rowFrom →(Required) Absolute row of source cell.¶" & + " colFrom →(Required) Absolute column of source cell.¶" & + " rowTo →(Required) Absolute row of destination cell.¶" & + " colTo →(Required) Absolute column of destination cell.¶" & + " distFrom →(Required) Cumulative cost to reach source. (Unused by this Mazelam.)¶" & + " dirDelta →(Required) This step's direction, encoded row*100000+col. (Unused.)¶" & + " prevDir →(Required) Previous direction. (Unused.)¶" & + "EXAMPLE: →¶" & + "Formula →=MAZE(myMap, ""A1"", , , , , , , MAZELAM_DIAG)¶" & + "Result →Distance grid where diagonal moves cost 1.5x and cardinals cost 1x", + "→", "¶" + ), + // Check inputs + Help?, ISOMITTED(costFrom), + // Procedure + diagonal, (rowFrom <> rowTo) * (colFrom <> colTo), + result, IF(diagonal = 1, costTo * 1.5, costTo), + IF(Help?, Help, result) +) +); diff --git a/lambdas/maps/MAZELAM_DIAG.tests.yaml b/lambdas/maps/MAZELAM_DIAG.tests.yaml new file mode 100644 index 0000000..1d23d81 --- /dev/null +++ b/lambdas/maps/MAZELAM_DIAG.tests.yaml @@ -0,0 +1,24 @@ +tests: + - name: diagonal step costs 1.5x destination + args: ["=1", "=2", "=3", "=3", "=4", "=4", "=0", "=100001", "=0"] + expected: 3 + + - name: horizontal step costs 1x destination + args: ["=1", "=2", "=3", "=3", "=3", "=4", "=0", "=1", "=0"] + expected: 2 + + - name: vertical step costs 1x destination + args: ["=1", "=2", "=3", "=3", "=4", "=3", "=0", "=100000", "=0"] + expected: 2 + + - name: anti-diagonal step also costs 1.5x destination + args: ["=1", "=4", "=5", "=5", "=4", "=6", "=0", "=-99999", "=0"] + expected: 6 + + - name: array of destination costs lifts element-wise (vertical) + args: ['=1', '={1;2;3}', "=3", "=3", "=4", "=4", "=0", "=100001", "=0"] + expected: [[1.5], [3], [4.5]] + + - name: help text + args: [] + expected_type: array diff --git a/lambdas/maps/MAZELAM_ELEV.lambda b/lambdas/maps/MAZELAM_ELEV.lambda new file mode 100644 index 0000000..95c34c1 --- /dev/null +++ b/lambdas/maps/MAZELAM_ELEV.lambda @@ -0,0 +1,44 @@ +/* FUNCTION NAME: MAZELAM_ELEV + DESCRIPTION:*//**Stock Mazelam for MAZE: treats Cost as elevation. Uphill steps cost 1 + 2x the rise; downhill steps cost 1 + 0.5x the drop (negative); flat steps cost 1.*/ +/* REVISIONS: Date Developer Description + 2026-05-20 Claude Initial version +*/ +MAZELAM_ELEV = LAMBDA( +// Parameter Declarations + [costFrom], + [costTo], + [rowFrom], + [colFrom], + [rowTo], + [colTo], + [distFrom], + [dirDelta], + [prevDir], +// Help + LET(Help, TEXTSPLIT( + "FUNCTION: →MAZELAM_ELEV(costFrom, costTo, rowFrom, colFrom, rowTo, colTo, distFrom, dirDelta, prevDir)¶" & + "DESCRIPTION: →Stock Mazelam for MAZE that treats Cost as elevation. Cost of a step = 1 + 2*rise for uphill, 1 + 0.5*drop for downhill (drop is negative, so the step is cheaper than 1), and 1 for flat.¶" & + "VERSION: →May 20 2026¶" & + "PARAMETERS: →¶" & + " costFrom →(Required) Elevation at source cell.¶" & + " costTo →(Required) Elevation at destination cell.¶" & + " rowFrom →(Required) Absolute row of source. (Unused by this Mazelam.)¶" & + " colFrom →(Required) Absolute column of source. (Unused.)¶" & + " rowTo →(Required) Absolute row of destination. (Unused.)¶" & + " colTo →(Required) Absolute column of destination. (Unused.)¶" & + " distFrom →(Required) Cumulative cost to reach source. (Unused.)¶" & + " dirDelta →(Required) This step's direction. (Unused.)¶" & + " prevDir →(Required) Previous direction. (Unused.)¶" & + "EXAMPLE: →¶" & + "Formula →=MAZE(elevationMap, ""A1"", elevationMap, , , , , , MAZELAM_ELEV)¶" & + "Result →Distance grid where uphill is penalised 2x and downhill is rewarded 0.5x", + "→", "¶" + ), + // Check inputs + Help?, ISOMITTED(costFrom), + // Procedure + delta, costTo - costFrom, + result, 1 + IF(delta > 0, delta * 2, delta * 0.5), + IF(Help?, Help, result) +) +); diff --git a/lambdas/maps/MAZELAM_ELEV.tests.yaml b/lambdas/maps/MAZELAM_ELEV.tests.yaml new file mode 100644 index 0000000..8336cdc --- /dev/null +++ b/lambdas/maps/MAZELAM_ELEV.tests.yaml @@ -0,0 +1,24 @@ +tests: + - name: uphill +3 elevation costs 1 + 3*2 = 7 + args: ["=5", "=8", "=3", "=3", "=4", "=4", "=0", "=100001", "=0"] + expected: 7 + + - name: downhill -3 elevation costs 1 + (-3)*0.5 = -0.5 + args: ["=8", "=5", "=3", "=3", "=4", "=4", "=0", "=100001", "=0"] + expected: -0.5 + + - name: flat step costs 1 + args: ["=5", "=5", "=3", "=3", "=3", "=4", "=0", "=1", "=0"] + expected: 1 + + - name: small uphill +0.5 costs 1 + 0.5*2 = 2 + args: ["=2", "=2.5", "=3", "=3", "=4", "=4", "=0", "=100001", "=0"] + expected: 2 + + - name: array of destination elevations lifts element-wise + args: ['=5', '={2;5;10}', "=3", "=3", "=4", "=4", "=0", "=100001", "=0"] + expected: [[-0.5], [1], [11]] + + - name: help text + args: [] + expected_type: array