# WHAT THE HARNESS ALREADY KNOWS ABOUT THIS GAME

Handed over so you do not spend your budget rediscovering it. None of it is a diagnosis.

## WHAT THE GAME SAYS IT SHOULD DO (its own design document)

# GAME DESIGN DOCUMENT — Hajimi Defense: The Mung Bean Crisis

## 0. Technical Architecture

- **Archetype:** `tower_defense`
- **Physics Profile:** top-down path-following enemies, grid-constrained tower placement, no gravity.
- **Resolution:** 1152 x 768 (template standard; do not change).
- **Primary gameplay base class:** `BaseTDScene` via copied `_TemplateTDLevel.ts`.
- **Scene flow:** `TitleScreen -> LivingRoomDefenseScene -> GameCompleteUIScene`; `LivingRoomDefenseScene -> GameOverUIScene` when sanity reaches 0.
- **LevelManager.LEVEL_ORDER:** `["LivingRoomDefenseScene"]`
- **Registered scene keys:**
  - `TitleScreen`
  - `LivingRoomDefenseScene`
  - `UIScene`
  - `PauseUIScene`
  - `VictoryUIScene`
  - `GameOverUIScene`
  - `GameCompleteUIScene`

## 1. Visual Style & Asset Registry

**Style Anchor:** Cute saturated kawaii pixel art on a warm living-room floor: chubby meme cats, rounded household threats, bright candy-like projectiles, soft outlines, high readability, and playful absurdity.

| type | key | description | params |
|------|-----|-------------|--------|
| background | living_room_bg | Top-down cute pixel art wooden living-room floor with warm planks, small rugs, toy mice, yarn balls, and cozy scattered cat toys; no text; clear central space for path overlay | resolution: "1536*1024" |
| image | tower_slot | Round fluffy cushion tower placement marker, top-down, pastel cream with soft rim, highly readable on wood floor | - |
| image | defense_target | Golden tuna can treasure, shiny warm yellow can with fish motif but no readable text, front/top three-quarter pixel art, defended goal object | - |
| image | spawn_door | Open living-room door at top-left, top-down/angled pixel art, warm wood frame and dark doorway, enemy spawn marker | - |
| image | obstacle_box | Cute destructible cardboard box, taped and dented, rounded pixel art edges, no text | - |
| image | obstacle_shoe | Pile of soft colorful shoes, top-down clutter obstacle, rounded cartoon forms | - |
| image | cat_tabby | Orange tabby cat tower, front/top three-quarter view, cheeks puffed as if spitting mung beans, cute meme expression | - |
| image | cat_siamese | Elegant Siamese cat tower, front/top three-quarter view, squinting sniper focus, poised and dramatic | - |
| image | cat_fat | Chonky orange cat tower lying down holding a red bean bun, lazy funny expression, large rounded body | - |
| image | cat_calico | Calico cat tower drinking milk tea with boba straw, cute focused expression, crowd-control vibe | - |
| image | proj_mung | Tiny round green mung bean projectile, simple bright pixel art bead, distinct green | - |
| image | proj_bone | Elongated white fish bone projectile, clean readable silhouette, slightly cream highlight | - |
| image | proj_bun | Round brown-red bean bun projectile, chunky snack ball, warm red-brown color | - |
| image | proj_boba | Round black tapioca pearl projectile, glossy dark purple-black bubble with small highlight | - |
| image | enemy_cucumber | Small fast walking cucumber enemy, green rounded veggie with terrified/funny eyes, tiny feet | - |
| image | enemy_dust | Tiny grey dust bunny puffball enemy with eyes, soft fluffy pixel art, swarm unit | - |
| image | enemy_vacuum | Large round robot vacuum cleaner enemy with red light, cute menacing appliance, top-down | - |
| image | enemy_mailman | Giant comedic mailman boss figure, oversized cap and mailbag, rounded pixel art silhouette, no readable text | - |
| image | icon_kibble | Cat food bowl currency icon filled with golden kibble pellets, cute pixel art | - |
| audio | bgm_playful | Funny bouncy 8-bit chiptune living-room defense loop, playful chaos, light percussion | audioType: "bgm", duration: 20 |
| audio | sfx_tower_place | Soft cute plop sound for placing a cat on a cushion | audioType: "sfx" |
| audio | sfx_tower_sell | Quick soft whoosh sound for selling/removing a cat | audioType: "sfx" |
| audio | sfx_tower_upgrade | Sparkly chime for cat upgrade | audioType: "sfx" |
| audio | sfx_spit | Cute short pfft spit sound for cat firing | audioType: "sfx" |
| audio | sfx_bonk | Light bonk impact sound for projectile hitting enemy | audioType: "sfx" |
| audio | sfx_break | Cardboard/shoe clutter cracking break sound | audioType: "sfx" |
| audio | sfx_combo | Exciting quick combo chime | audioType: "sfx" |
| audio | sfx_wave_clear | Triumphant short wave-clear jingle | audioType: "sfx" |
| audio | sfx_enemy_death | Soft pop enemy defeated sound | audioType: "sfx" |

**Code-drawn infrastructure:** path overlay line, range circles, hit rings, floating reward text, panel rectangles, and transient particles should use `Shapes.*` or Phaser graphics, not generated images. Projectile assets are brand-identifiable because each cat type requires a dedicated recognizable projectile image.

## 2. Game Configuration

Merge the following game-specific configuration into the existing `src/gameConfig.json` without removing `screenSize`, `debugConfig`, `renderConfig`, or `difficultyConfig`.

- `difficultyConfig.nLevels`: 1
- `difficultyConfig.enemyCount`: 5 (minimum Wave 1 audit baseline; actual waves are defined in `towerDefenseConfig.waves`)
- `difficultyConfig.enemySpeedFactor`: 1
- `difficultyConfig.hazardCount`: 4 (obstacles)
- `difficultyConfig.healthPickups`: 0
- `difficultyConfig.timeLimitSec`: 0 (no hard timer; wave countdowns are separate)

**`towerDefenseConfig`:**
- `startingGold`: 120
- `startingLives`: 10
- `gridCellSize`: 64
- `gridWidth`: 16
- `gridHeight`: 10
- `timeBetweenWavesMs`: 12000
- `obstacleClicksToDestroy`: 5
- `obstacleReward`: 15
- `comboWindowMs`: 2000
- `comboBonusPerLevel`: 2
- `sellRefundRate`: 0.7
- `waves`:
  1. `{ wave: 1, enemies: [{ type: "cucumber", count: 5 }], spawnIntervalMs: 1200, reward: 20 }`
  2. `{ wave: 2, enemies: [{ type: "dust", count: 8 }, { type: "vacuum", count: 2 }], spawnIntervalMs: 800, reward: 30 }`
  3. `{ wave: 3, enemies: [{ type: "cucumber", count: 4 }, { type: "dust", c

## WHERE THE CODE IS

43 TypeScript files, largest first. `A -> B` means A extends B.

    843 lines  src/scenes/BaseTDScene.ts                            BaseTDScene -> Phaser.Scene
    794 lines  src/utils.ts                                         
    696 lines  src/scenes/LivingRoomDefenseScene.ts                 LivingRoomDefenseScene -> BaseTDScene
    404 lines  src/enemies/BaseTDEnemy.ts                           BaseTDEnemy -> Phaser.Physics.Arcade.Sprite
    373 lines  src/towers/BaseTower.ts                              BaseTower -> Phaser.GameObjects.Image
    312 lines  src/scenes/_TemplateTDLevel.ts                       _TemplateTDLevel -> BaseTDScene
    241 lines  src/scenes/TitleScreen.ts                            TitleScreen -> Phaser.Scene
    237 lines  src/shapes.ts                                        
    191 lines  src/systems/WaveManager.ts                           WaveManager
    179 lines  src/entities/BaseObstacle.ts                         BaseObstacle -> Phaser.GameObjects.Image
    176 lines  src/scenes/GameOverUIScene.ts                        GameOverUIScene -> Phaser.Scene
    169 lines  src/scenes/UIScene.ts                                UIScene -> Phaser.Scene
    153 lines  src/rlenv.ts                                         
    136 lines  src/scenes/VictoryUIScene.ts                         VictoryUIScene -> Phaser.Scene
    135 lines  src/StateMachine.ts                                  StateMachine
    132 lines  src/scenes/PauseUIScene.ts                           PauseUIScene -> Phaser.Scene
    119 lines  src/scenes/GameCompleteUIScene.ts                    GameCompleteUIScene -> Phaser.Scene
    117 lines  src/towers/_TemplateTower.ts                         _TemplateTower -> BaseTower
    109 lines  src/LevelManager.ts                                  LevelManager
     98 lines  src/test/helpers/phaser.ts                           
     92 lines  src/enemies/_TemplateTDEnemy.ts                      _TemplateTDEnemy -> BaseTDEnemy
     77 lines  src/towers/BobaTower.ts                              BobaTower -> BaseTower
     76 lines  src/main.ts                                          
     76 lines  src/systems/EconomyManager.ts                        EconomyManager
     73 lines  src/towers/ChonkyTower.ts                            ChonkyTower -> BaseTower
     68 lines  src/scenes/Preloader.ts                              Preloader -> Phaser.Scene
     60 lines  src/entities/_TemplateObstacle.ts                    _TemplateObstacle -> BaseObstacle
     56 lines  src/towers/SiameseTower.ts                           SiameseTower -> BaseTower
     53 lines  src/towers/TabbyTower.ts                             TabbyTower -> BaseTower
     49 lines  src/enemies/CucumberEnemy.ts                         CucumberEnemy -> BaseTDEnemy
     49 lines  src/enemies/MailmanBossEnemy.ts                      MailmanBossEnemy -> BaseTDEnemy
     46 lines  src/enemies/RobotVacuumEnemy.ts                      RobotVacuumEnemy -> BaseTDEnemy
     45 lines  src/enemies/DustBunnyEnemy.ts                        DustBunnyEnemy -> BaseTDEnemy
     40 lines  src/test/hajimi-smoke.test.ts                        
     34 lines  src/entities/ShoePileObstacle.ts                     ShoePileObstacle -> BaseObstacle
     33 lines  src/entities/CardboardBoxObstacle.ts                 CardboardBoxObstacle -> BaseObstacle
     25 lines  src/chrome/chrome.d.ts                               
     12 lines  src/test/setup.ts                                    
      7 lines  src/enemies/index.ts                                 
      7 lines  src/towers/index.ts                                  
      5 lines  src/entities/index.ts                                
      4 lines  src/scenes/index.ts                                  
      4 lines  src/systems/index.ts                                 

## CONTROLS (parsed from this game's own source)

  control   event          on <scope>              file:line

  pointer   pointerdown    on BaseObstacle           src/entities/BaseObstacle.ts:55
  esc       keydown-ESC    on BaseTDScene            src/scenes/BaseTDScene.ts:203
  space     keydown-SPACE  on BaseTDScene            src/scenes/BaseTDScene.ts:212
  pointer   pointermove    on BaseTDScene            src/scenes/BaseTDScene.ts:191
  pointer   pointerdown    on BaseTDScene            src/scenes/BaseTDScene.ts:195
  enter     Key(ENTER)     on GameCompleteUIScene    src/scenes/GameCompleteUIScene.ts:66
  space     Key(SPACE)     on GameCompleteUIScene    src/scenes/GameCompleteUIScene.ts:69
  pointer   pointerdown    on GameCompleteUIScene    src/scenes/GameCompleteUIScene.ts:74
  enter     Key(ENTER)     on GameOverUIScene        src/scenes/GameOverUIScene.ts:88
  space     Key(SPACE)     on GameOverUIScene        src/scenes/GameOverUIScene.ts:91
  pointer   pointerdown    on GameOverUIScene        src/scenes/GameOverUIScene.ts:85
  pointer   pointerdown    on LivingRoomDefenseScene src/scenes/LivingRoomDefenseScene.ts:369
  pointer   pointerdown    on LivingRoomDefenseScene src/scenes/LivingRoomDefenseScene.ts:396
  pointer   pointerdown    on LivingRoomDefenseScene src/scenes/LivingRoomDefenseScene.ts:574
  pointer   pointerdown    on LivingRoomDefenseScene src/scenes/LivingRoomDefenseScene.ts:575
  esc       keydown-ESC    on PauseUIScene           src/scenes/PauseUIScene.ts:86
  space     keydown-SPACE  on PauseUIScene           src/scenes/PauseUIScene.ts:91
  enter     keydown-ENTER  on PauseUIScene           src/scenes/PauseUIScene.ts:96
  esc       keydown-ESC    on UIScene                src/scenes/UIScene.ts:131
  pointer   pointerdown    on UIScene                src/scenes/UIScene.ts:122
  enter     Key(ENTER)     on VictoryUIScene         src/scenes/VictoryUIScene.ts:71
  space     Key(SPACE)     on VictoryUIScene         src/scenes/VictoryUIScene.ts:74
  pointer   pointerdown    on VictoryUIScene         src/scenes/VictoryUIScene.ts:79

## COORDINATES

  The game's own space is 1152x768; it is drawn into a canvas of 960x640. Click positions in the steps above are in the canvas space.

## THE STEPS THAT ARE THE EVIDENCE, VERBATIM

Taken from the session that found this. Not a summary -- what was sent and what came back.

  step 5: click {"x": 77, "y": 469}
      it expected: Exercise tower selection by clicking the visible Tabby buy card, then I will place it on a cushion.
      the game answered: null
      0.2% of the screen changed
  step 7: click {"x": 466, "y": 260}
      it expected: Try to place the selected Tabby on a visible cushion-like spot near the path to exercise tower placement.
      the game answered: null
  step 8: read_text {}
      it expected: Read HUD after attempted placement to see whether kibble changed or tower text/status changed.
      the game answered: {"hud_text": "PAUSE\nKIBBLE\n120\nSANITY\n6/10\nWAVE\n1/3\nSCORE\n0\nClick cat > click cushion | SPACE next wave | Upgrade/sell placed cats | Select a cat below\nTOWERS\nTabby\n35 K\nSiamese\n70 K\nChonkyOrange\n95 K\nBoba Calico\n55 K\nClick cat, then click a glowing cushion. Obstacles take 5 clicks and give +15 Kibble.\n-1 SANITY", "canvas_text": [{"scene": "LivingRoomDefenseScene", "text": "HAJ
      0.2% of the screen changed
  step 9: read_scene_fields {"fields": ["selectedTowerType", "selectedCatType", "selectedTower", "gold", "kibble", "lives", "sanity", "currentWaveIn
      it expected: I need live scene fields for selection, gold, lives, tower count, obstacle count, and terminal flags because the HUD did not show a placement cost cha
      the game answered: {"scenes": ["LivingRoomDefenseScene", "UIScene"], "fields": {"LivingRoomDefenseScene.lives": 5, "LivingRoomDefenseScene.towersGroup": "(initialize active=true getLength()=0)"}}
  step 10: click {"x": 127, "y": 146}
      it expected: Select Tabby using the upper tower palette card as a second route, since the first placement left towersGroup at 0.
      the game answered: null
      2.9% of the screen changed
  step 11: click {"x": 598, "y": 395}
      it expected: Click a clearly visible lower-right cushion/slot area after selecting from the upper palette to test placement again.
      the game answered: null
      2.9% of the screen changed
  step 12: read_scene_fields {"fields": ["lives", "gold", "kibble", "currentWave", "wave", "currentWaveIndex", "towersGroup", "gameOver", "waveInProg
      it expected: Read fields after second placement attempt to capture whether tower count/gold changed and wave state progressed.
      the game answered: {"scenes": ["LivingRoomDefenseScene", "UIScene"], "fields": {"LivingRoomDefenseScene.lives": 5, "LivingRoomDefenseScene.towersGroup": "(initialize active=true getLength()=0)"}}
      0.0% of the screen changed

## HOW TO RUN THE GAME, NOT JUST BUILD IT

Building is not the test. A build that compiles says nothing about whether the HUD appeared or whether a click places a tower, which is usually what is being reported. So drive it:

```
PYTHONPATH=/home/tiger/GameAgent/minghao/OpenGame_verify_fix/.claude/worktrees/negative-evidence-scope/agent-test \
python3 -m gamedoctor.evolve.play_cli . --steps '[
  {"action":"boot"},
  {"action":"read_text"},
  {"action":"press_key","key":"Enter"},
  {"action":"wait","ms":2000},
  {"action":"read_state"},
  {"action":"click","x":286,"y":181,"times":2},
  {"action":"read_scene_fields","fields":["towersGroup"]}]'
```

The two steps in the middle are not padding. These games open on a title screen and construct the scene asynchronously after the start key, so a `read_state` fired immediately comes back `ok:false` -- which means the reading could not be taken, NOT that the game is empty. Read the text first to see which screen you are on, press the key the game advertises, then give it a beat.

It prints JSON: one row per step, `observed` for readings and `frame` for a screenshot path you can open. Actions: boot, press_key, hold_key, click (with `times` for repeats), wait, read_state, read_text, read_scene_fields, read_bindings, screenshot. Run it from the game directory.

THE MOST USEFUL THING IT DOES is the matched interval: do nothing for N ms, read; then do the thing for the same N ms, read. A number that should differ and does not is the defect, and a number that moves on its own is a confound you would otherwise blame on your own change.

BEFORE YOU STOP, run the game and read back the same thing the evidence above measured. It is the only measurement of this property that exists -- a build that compiles and a test suite that passes do not observe it. If the reading has not moved, you have not finished.

Time spent driving the game is not charged against your reasoning budget. Inspect, edit, build, run and look as many times as you need.

## A TEST, IF ONE HELPS YOU ITERATE

The project runs vitest (`npm run test`) and ships headless Phaser helpers in `src/test/helpers/phaser.ts` -- `bootScene(SceneClass)` boots a scene with no browser. For a mechanism defect that is one assertion ("two clicks and `towersGroup.getLength()` is still 0"), that can be a faster loop than driving the whole game.

Optional, and not how your repair is judged -- that is still the session that plays the rebuilt game. A visual defect (contrast, a missing HUD) has no assertion that states it; use the screenshot.


======================================================================

A play session of this game found the following, and your job is to fix it.

WHAT WAS SEEN
  Tower placement did not produce a placed tower in the recorded attempts.

THE EVIDENCE FROM THAT SESSION
  The player attempted two select-then-place sequences. After the first attempt, HUD text still showed KIBBLE 120 and read_scene_fields reported LivingRoomDefenseScene.towersGroup getLength()=0. After the second attempt, read_scene_fields again reported LivingRoomDefenseScene.towersGroup getLength()=0.

THE SESSION WAS NOT SURE, AND SAID WHY
  The trace does not prove both clicks landed on valid interactive targets: the first Tabby-card click appears visually questionable, and the later placement click may not have been on a valid cushion/slot. The scene fields also did not expose a selected-tower field, so the trace cannot confirm whether selection succeeded before placement.
  Look into that before assuming where the fault is.

ALREADY TRIED ON AN EARLIER VERSION, AND DEMONSTRABLY DID NOT WORK

  - Tower placement/selection did not respond to the attempted visible placement/tower clicks.
      that attempt changed: src/scenes/BaseTDScene.ts, src/scenes/LivingRoomDefenseScene.ts
      the session then saw: The session reached the placement flow: it entered the playfield, selected a cat card, then clicked the field and a visible pale cushion while the card stayed highlighted. Neither click produced a visible placed cat or any placement/selection UI, matching the previously reported non-response.
  A session reached each of those afterwards and saw the same thing. Do not repeat that approach.

ATTEMPTED EARLIER, AND NOBODY COULD TELL EITHER WAY

  - The Game Over overlay has low-contrast text that is hard to read.
      that attempt changed: tmp_check_endcard.mjs
      the session then saw: The session entered gameplay and let enemies reduce hp, but it never reached the Game Over state or displayed the Game Over overlay. By the final observed wait, hp was still 3 and lost was still 0, so the low-contrast Game Over text was not exercised.
  - Keyboard retry returns to the playfield but leaves the LivingRoomDefenseScene internal game-over flag set.
      that attempt changed: src/scenes/GameOverUIScene.ts
      the session then saw: The session entered the playfield and observed waves/lives, but it never reached a Game Over overlay and never pressed Enter to retry from Game Over. The final internal read was during active play with lives still 5, so it did not exercise the previous keyboard retry flag path.
  Those sessions never reached the mechanic, so the attempt was neither confirmed nor refuted, and the change is NOT in this build. Treat it as untried rather than as failed -- but knowing where someone already looked may save you the search.

HOW THIS WILL BE JUDGED. Nobody reads your summary. The game is rebuilt and
played again by an agent sent to check this specific thing, and a reader decides
from THAT session whether it behaves now. A change that compiles and does not
alter what a player sees comes back as unfixed.

Fix the cause you can find, not the symptom you can reach. And do not break
what works -- your change will be combined with other repairs and the result is
played in full.

BEFORE YOU STOP, build the game. A repair that does not compile cannot be
played and cannot be judged.
