|
- <# Verifies the generated C64 tile world captured by tools/smoke.ps1. #>
- [CmdletBinding()]
- param(
- [string]$Path = (Join-Path $PSScriptRoot '../build/smoke/c64/world.bin'),
- [switch]$ShowMap
- )
-
- $ErrorActionPreference = 'Stop'
- $width = 80
- $height = 50
- $tiles = [IO.File]::ReadAllBytes((Resolve-Path -LiteralPath $Path).Path)
- if ($tiles.Length -ne $width * $height) {
- throw "Expected an 80x50 tile map, got $($tiles.Length) bytes."
- }
-
- # Tile IDs from src/tiles.inc. M1.2 uses straight roads and four-way crossings.
- $roadH = 13
- $roadV = 14
- $roadCross = 19
- $glyphs = '.gT#~~~~~~~~~-|+++++'
- $counts = [int[]]::new($glyphs.Length)
- foreach ($tile in $tiles) {
- if ($tile -ge $glyphs.Length) { throw "Invalid terrain tile ID $tile." }
- $counts[$tile]++
- }
- foreach ($tile in 0..12) {
- if ($counts[$tile] -eq 0) { throw "Missing terrain tile ID $tile." }
- }
-
- # Find the road columns and rows from their endpoints on the world edges.
- $roadColumns = @(0..($width - 1) | Where-Object { $tiles[$_] -eq $roadV })
- $roadRows = @(0..($height - 1) | Where-Object { $tiles[($_ * $width)] -eq $roadH })
- if ($roadColumns.Count -ne 2 -or $roadRows.Count -ne 2) {
- throw "Expected two east-west and two north-south roads."
- }
-
- for ($y = 0; $y -lt $height; $y++) {
- for ($x = 0; $x -lt $width; $x++) {
- $tile = $tiles[$y * $width + $x]
- $horizontal = $y -in $roadRows
- $vertical = $x -in $roadColumns
- if ($horizontal -or $vertical) {
- $expected = if ($horizontal -and $vertical) { $roadCross }
- elseif ($horizontal) { $roadH }
- else { $roadV }
- if ($tile -ne $expected) {
- throw "Broken road at ($x,$y): expected tile $expected, got $tile."
- }
- } elseif ($tile -ge $roadH) {
- throw "Disconnected road tile at ($x,$y)."
- }
- }
- if ($ShowMap) {
- $start = $y * $width
- -join ($tiles[$start..($start + $width - 1)] | ForEach-Object { $glyphs[$_] })
- }
- }
-
- Write-Output '[PASS] 80x50 world has all terrain types and four connected road crossings.'
|