Appearance
Lesson 02 — Give the arena an authoritative model
Where this lesson fits: the host draws a frame. Now give the arena a stable representation that gameplay systems can query without relying on pixels.
Time: 2–3 hours
Prerequisites and outcomes
Complete lesson 01. By the end, you can explain tile ownership, convert between world and grid coordinates, and apply a result to the arena.
Prepare and run
- From your learner project's solution folder, follow tutorial chapter 02 steps 1–5. Step 1 copies files and overwrites matching files in your project; replace
<course-repo>with your repository path. - Open
Source\Systems\ArenaSystem.csandTests\Systems\ArenaSystemTests.csin your project. Run the focused command below from the same solution folder, then use the tutorial's checkpoint.
Code anchors
last-perimeter/Source/Data/GameConfig.cslast-perimeter/Source/Data/Enums.cslast-perimeter/Source/Systems/ArenaSystem.cslast-perimeter/Tests/Systems/ArenaSystemTests.cs
Concept: coordinate spaces
GameConfig defines screen size, HUD reserves, arena margin, and tile size. ArenaSystem owns the grid and the conversions between game-world positions and tile coordinates. Rendering may draw a tile as a rectangle, but simulation asks which state owns that tile.
Guided operations
- Calculate the arena bounds from the configured screen and HUD reserves.
- Follow a world position into
TryWorldToGrid; inspect the behavior at the top-left, bottom-right, and just outside the arena. - Inspect the tile-state enum and identify which state means traversable unclaimed interior, permanent claim, and boundary.
- Clone the grid and compare it with the authoritative grid. Explain why the clone is useful for a solver.
- In
ArenaSystemTests.cs, find the claim-application test. Read its fixture and assertions, then run it with the focused command below; compare the asserted tile count and percentage with your prediction.
Run the focused tests from the project directory:
powershell
dotnet test --filter FullyQualifiedName~ArenaSystemTestsCheckpoint
The focused tests pass. You can predict the grid coordinate for a point and explain which component should change when a claim is committed.
Common mistakes
- Mixing world-space pixels and grid-space cells in one calculation.
- Treating a visual fill as the authoritative claim record.
- Mutating the live grid while exploring a possible claim.
Questions and extension
Which coordinate conversion edge cases could cause a trail to leave a one-cell gap? Add a boundary-focused test using the existing test fixture.

