-
Notifications
You must be signed in to change notification settings - Fork 3
fix: carve gates into the two sealed city gardens (#5) #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
blippip69
wants to merge
1
commit into
Bitcoindefi:main
Choose a base branch
from
blippip69:fix/open-city-gardens
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| const { test } = require('brittle') | ||
| const M = require('../lib/map.js') | ||
|
|
||
| function walkableComponentFromSpawn(city) { | ||
| const seen = new Set() | ||
| const queue = [[city.spawn.x, city.spawn.y]] | ||
| while (queue.length) { | ||
| const [x, y] = queue.pop() | ||
| const key = x + ',' + y | ||
| if (seen.has(key)) continue | ||
| if (x < 0 || y < 0 || x >= city.width || y >= city.height) continue | ||
| if (M.isSolid(city, x, y)) continue | ||
| seen.add(key) | ||
| queue.push([x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]) | ||
| } | ||
| return seen | ||
| } | ||
|
|
||
| test('both city gardens open into the main walkable component (#5)', (t) => { | ||
| const city = M.MAPS.city | ||
| const reached = walkableComponentFromSpawn(city) | ||
|
|
||
| // The exact compounds the issue measured as sealed: interiors of | ||
| // garden(5, 5, 65, 43) and garden(250, 5, 65, 43). | ||
| const gardens = [ | ||
| { x: 5, y: 5, w: 65, h: 43 }, | ||
| { x: 250, y: 5, w: 65, h: 43 } | ||
| ] | ||
|
|
||
| for (const g of gardens) { | ||
| let reachedInside = 0 | ||
| for (let y = g.y + 1; y < g.y + g.h - 1; y++) { | ||
| for (let x = g.x + 1; x < g.x + g.w - 1; x++) { | ||
| if (!M.isSolid(city, x, y) && reached.has(x + ',' + y)) reachedInside++ | ||
| } | ||
| } | ||
| t.ok( | ||
| reachedInside > 1000, | ||
| `interior of garden at ${g.x},${g.y} joins the city (${reachedInside} cells reached)` | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| test('every garden side has a carved gate in the hedge (#5)', (t) => { | ||
| const city = M.MAPS.city | ||
| for (const gx of [5, 250]) { | ||
| const cxg = gx + 32 | ||
| const cyg = 5 + 21 | ||
| t.is(M.isSolid(city, cxg, 5), false, 'north gate open') | ||
| t.is(M.isSolid(city, cxg - 1, 5), false) | ||
| t.is(M.isSolid(city, cxg, 47), false, 'south gate open') | ||
| t.is(M.isSolid(city, gx, cyg), false, 'west gate open') | ||
| t.is(M.isSolid(city, gx + 64, cyg), false, 'east gate open') | ||
| } | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Quality: Connectivity test can't prove all four gates work
The first test only asserts that >1000 interior cells are reachable from spawn. Because a garden interior is one internally-connected region, this passes as soon as any single gate connects outward, so a gate that was mis-placed or opened onto a solid obstacle would go undetected — defeating the PR's stated goal of four open approaches. The second test checks gate cells are non-solid but never checks the cell just outside each gate is walkable. Consider asserting, per side, that both the gate cell and its immediate exterior neighbor are non-solid (e.g. for the north gate also check (cxg,y-1)), so each of the four approaches is independently verified.
Was this helpful? React with 👍 / 👎