Skip to content

Tile knowledge duplicates - #1114

Open
mikes-wandering wants to merge 2 commits into
C7-Game:Developmentfrom
mikes-wandering:tile-knowledge-duplicates
Open

mikes-wandering wants to merge 2 commits into
C7-Game:Developmentfrom
mikes-wandering:tile-knowledge-duplicates

Conversation

@mikes-wandering

Copy link
Copy Markdown

TileKnowedge GetTilesVisibleToUnit returns duplicate tiles. It finds outer ring tiles by looking at the neighbors of all the inner ring tiles, many of which overlap. This can cause wasted effort when callers process the duplicates.

@ajhalme

ajhalme commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Thanks - I think I can see the duplication, and the fix seems reasonable.

Three things:

  1. We can let the relevant data structure worry about deduplication. A Hashset<T> (in place of a List<T>) can keep track of unique tiles in the result collection. It should a bit cleaner than adding a check before a list operation. UnionWith can be used in place of AddRange.

  2. Let's initialise the GameData state for the test with the below, to keep things consistent with others:

EngineStorage.InitializeGameDataForTests(new C7GameData.GameData());
  1. The test's map generator is quite elaborate. I'm struggling to map the string-based tile templates ("00000") and the indexing to the tile IDs. I get it that the string refers to heights, but I can't easily tell if the test assertions are correct, in that they capture the behaviour we want. The indexing logic in MakeTiles is also more complicated than I think it needs to be.
    In short, I think we need either A) more documentation around the test tiles, or, and preferably, B) another, more intuitive approach to tile test scenario generation.

Creating tile tests is tricky. I've thought about a template scheme a number of times, and many of our current tests have various ad hoc tile gen implementations. We really should come up with a proper string-based tile generation scheme.

C# of course supports multiline strings, so we could have something like:

var map = @"
	.....
    ...M.
    ..MM.
    ..M..
";
MapGen.Parse(map);

@mikes-wandering

Copy link
Copy Markdown
Author

Thanks. I've just started working with this code base and there's many things I don't understand yet. I started by writing some tests to help build my knowledge, and was surprised to see 59 tiles returned from GetTilesVisibleToUnit!

  1. I'll use HashSet
  2. I'll add this.
  3. I'd like to eventually have a more generic test map generator, but I don't know enough yet. I'll try to document and clarify the current code, and hopefully it can evolve into something more widely useful.

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.

3 participants