-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix growable structure grids for multiple children with negative coor…
…dinates (#2127) Fixes a bug from #1826. ## Background Structure definitions can be nested, in that a structure can reference and place multiple "substructures", each with an "offset", to compose something more complicated. Each placement onto a particular "base" structure is a "child". Multiple child placements atop the same base structure are "siblings". It so happened that if a child placement with a "negative" horizontal offset preceded a sibling with non-negative offset, this would result in miscalculated placements. This had to do with the fact that "growing" the "base grid" in the negative direction means that the original "origin" (that the "offset" of subsequent placements are made with respect to) of the base grid must be shifted further right (to somewhere in the middle of the grid), rather than lying on the left edge. Conversely, if negative offsets occurred as later siblings, then the placement would be correct (the bug would not be triggered). ## The fix This fix ensures that sibling placements can be re-ordered without affecting the end result. There were actually two bugs: * changes to the origin offset were not propagated between sibling placements (i.e. across iterations of [`foldlM`](https://github.com/swarm-game/swarm/blob/ab13170f4c3d47e6fb3e44d3ec1c86aa91451575/src/swarm-topography/Swarm/Game/Scenario/Topography/Structure/Assembly.hs#L84)) * the math for computing combined offset (`originDelta` in the `Semigroup` instance of `PositionedGrid`) was incorrect. ## Other changes Also implements a `--refresh` option to the `standalone-topography` test for updating image-based test fixtures. ## Bug repro ``` scripts/play.sh -i data/scenarios/Testing/1780-structure-merge-expansion/sequential-placement.yaml ``` | Before (incorrect) | After (correct) | | --- | --- | | ![broken](https://github.com/user-attachments/assets/47952f83-b877-4fc2-b6b7-8ceb495e8ba0)| ![fixed](https://github.com/user-attachments/assets/907d8872-bff0-4c41-b1c4-8561bf206b4a) | # Refreshing test images ``` scripts/test/run-tests.sh standalone-topography --test-options '--refresh' ```
- Loading branch information
Showing
11 changed files
with
172 additions
and
45 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
data/scenarios/Testing/1780-structure-merge-expansion/00-ORDER.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
nonoverlapping-structure-merge.yaml | ||
root-map-expansion.yaml | ||
structure-composition.yaml | ||
structure-composition.yaml | ||
sequential-placement.yaml |
95 changes: 95 additions & 0 deletions
95
data/scenarios/Testing/1780-structure-merge-expansion/sequential-placement.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
version: 1 | ||
name: Flipped structure placement | ||
author: Karl Ostmo | ||
description: | | ||
Sequentially place structures that are larger than the map | ||
with flipped orientation. | ||
robots: | ||
- name: base | ||
dir: north | ||
creative: true | ||
objectives: | ||
- goal: | ||
- Must have 3 of each color visible | ||
condition: | | ||
def countColor = \e. | ||
resonate e ((0, 0), (10, -5)); | ||
end; | ||
as base { | ||
r <- countColor "pixel (R)"; | ||
g <- countColor "pixel (G)"; | ||
b <- countColor "pixel (B)"; | ||
y <- countColor "gold"; | ||
return $ r == 3 && g == 3 && b == 3 && y == 3; | ||
} | ||
solution: | | ||
noop | ||
known: [boulder, log, pixel (R), pixel (G), pixel (B), gold] | ||
world: | ||
structures: | ||
- name: reddish | ||
structure: | ||
mask: '.' | ||
palette: | ||
'x': [stone, pixel (R)] | ||
map: | | ||
xx | ||
x. | ||
- name: greenish | ||
structure: | ||
mask: '.' | ||
palette: | ||
'x': [stone, pixel (G)] | ||
map: | | ||
xx | ||
x. | ||
- name: bluish | ||
structure: | ||
mask: '.' | ||
palette: | ||
'x': [stone, pixel (B)] | ||
map: | | ||
xx | ||
x. | ||
- name: goldish | ||
structure: | ||
mask: '.' | ||
palette: | ||
'x': [stone, gold] | ||
map: | | ||
xx | ||
x. | ||
- name: block | ||
structure: | ||
mask: '.' | ||
palette: | ||
'x': [ice, log] | ||
placements: | ||
- src: greenish | ||
orient: | ||
flip: true | ||
offset: [-3, 2] | ||
- src: reddish | ||
offset: [-6, 0] | ||
- src: goldish | ||
orient: | ||
flip: true | ||
offset: [3, -1] | ||
- src: bluish | ||
offset: [0, 1] | ||
map: | | ||
xxx | ||
xx. | ||
x.. | ||
palette: | ||
'Ω': [grass, erase, base] | ||
mask: '.' | ||
placements: | ||
- src: block | ||
offset: [0, -1] | ||
upperleft: [0, 0] | ||
dsl: | | ||
{grass} | ||
map: | | ||
Ω |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters