Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
build age of empires 2. take your time and be thorough. focus on a full gamep… #115
Check · Review · Land · Live done — Landed and live in production.
Empire Age is a new strategy game at /empire/ (a card on the home page, an entry in the shell menu, a share card). You play blue against a red bot on a 44 by 44 map, with easy, normal and hard levels.
shipped production is serving it deploy ab54f53
5 earlier comments · 2 events
Empire Age is a new strategy game at /empire/ (a card on the home page, an entry in the shell menu, a share card). You play blue against a red bot on a 44 by 44 map, with easy, normal and hard levels. The new tests pass and the whole suite passes except the playtest file, where I ran only the cases for the games I touched and left the rest to the forge's check. I haven't played it on a real device, so how it feels by touch is untested.
Gameplay
- Economy: you start with a town center and four villagers. Villagers gather food, wood, gold and stone and carry it to the nearest drop-off. You build houses, camps, farms and military buildings.
- Progress: you climb the Dark, Feudal, Castle and Imperial Ages and research six upgrades.
- Army: you train militia, spearmen, archers, knights and rams. Counter-bonuses apply, towers and castles shoot, and there is fog of war.
- Winning: destroy every town center and castle of the enemy. Losing all of yours is a defeat, and you can resign with two presses.
- Extras: pause, 1x/2x/4x speed, an autopilot that plays your side, a minimap and attack alerts. The game saves itself, and there is a best time per level.
Controls
- Mouse: drag a box to select, tap or right-click to command, buttons to build and train.
- Touch: tap to select or command, drag to pan the map, the minimap jumps the view, panel buttons build and train.
- Keyboard only: arrows move the view, Enter taps a cross in the middle of it, 1–9 press buttons,
.selects an idle villager,,the army, H the town center, Space the last alert, P pauses, R resigns.
How it's built
empire/has its own small pixel renderer, because a strategy map doesn't fitengine.js.- The rules live in plain modules with no DOM, and the bot uses the same commands as the person. The README has the file table.
- No dependencies, no assets. The sound is generated in the page.
- The one server call is the anonymous play count every game already makes.
Tests
- Added
empire/realm.test.mjs,empire/ui.test.mjsandempire/page.test.mjs. They cover pathfinding, the economy, building, training, ages, combat, saves, the bot (including a full bot-against-bot game) and the real page, and a scripted round inrounds.mjsreaches a defeat by resignation. - A frame renders in about 2 ms and a game tick in about 0.3 ms in the test harness. I did not measure frame time in a real browser.
Bug fixed along the way: a unit that died to a blow was never credited to its killer, so "defeated" was always 0. It is now credited, and a test covers it.
Added to the shared files
Strategyis a new game kind inshell.js; I added it to the allowed list inserve.test.mjsand to thekindlist in theshell.jscomment.- Main was already red when I started, so I fixed that to get a green pull:
- Four games had no scripted round in rounds.mjs: Espresso Bar, Firefly Jar, Signal Box and Soapbox Derby. I added one for each, and each reaches a result.
- The Signal Box and Soapbox Derby page tests read page state with vm.runInContext, which no longer works. They now use g.read.
- Firefly Jar was missing the no-text-selection and touch-callout CSS that serve.test.mjs requires. I added that line.
Left out: multiplayer, walls, monks and relics, formations, and more than one save slot.
Try it: bun serve.mjs, then open /empire/. Drag a box round the four villagers, tap the berries, then press H and 1 to train more. bun test empire/ runs the new tests.
main is merged into the branch and pushed (943d5bc); the five conflicts are resolved, and the tests I ran pass.
rounds.mjs:mainnow has scripted rounds for Espresso Bar, Firefly Jar, Signal Box and Soapbox Derby, so I took its versions and dropped mine. Only theempireround is added on top, and Sheepdog's is kept.firefly-jar/index.html: I tookmain's version, which already has the no-select and touch-callout rule I'd added.README.md: the no-music list now reads "Sheepdog, Firefly Jar and Empire Age". Both game rows are kept.serve.test.mjs: the Empire Age and Sheepdog serve tests are both kept.og/home.png: I regenerated it withbun scripts/og.mjs, so it shows both new cards.
shell.js and index.html merged without conflict and list both Empire Age and Sheepdog.
I ran every test file except playtest.test.mjs: 512 pass, 0 fail. For playtest.test.mjs I ran only the Empire Age, Sheepdog and "every game has a scripted round" cases (12 pass). I left the full playtest suite to the forge's check.
Empire Age is an ambitious, well-structured game (DOM-free modules, seeded sim, bot on the same commands, preview answers 200). Changes needed in one round:
- FIRST: the command-flash marks are drawn with an undefined colour (see comment on empire/index.html flash), so they paint transparent pixels instead of a ring. Give them a colour and add a test that a mark changes pixels.
- Dead code in paint.js
bar: the unusedcparameter andif (c) void c;. Remove. - page.test.mjs alarm test:
expect(typeof before).toBe('number')asserts nothing about Space looking at the alert. Assert V.camX moved to the alert (or centre equals alertAt). - Phone/no-JS: the page is blank without JavaScript (no <noscript>). Add a short noscript line saying the game needs JavaScript, and the rules in plain text.
- Touch: the 360px layout gives the dock only 34vh with ~34px buttons plus a 28px control row; verify on a 360x640 viewport that the build/train buttons and the canvas both stay usable, and make the queue-cancel buttons (24px high) at least 32px for a thumb.
- Accessibility: disabled panel buttons use aria-disabled but their reason lives only in title/small; fine visually, but the live status region is also rewritten every 0.2s HUD tick — only set textContent when it changes so screen readers are not re-announcing.
I also could not see the last part of the diff (cut off), so rounds.mjs/serve.test.mjs/shell.js changes were judged by the description only.
Five of the six points are fixed and pushed (8bc040d). The 360×640 check in point 5 is not done, because I have no browser in this sandbox. bun test empire/ and serve.test.mjs pass, and the Empire Age playtest cases pass; I did not rerun the full playtest suite.
- Command flashes: they were pushed with no colour, so they painted nothing. They now carry a green, and
paint.jsfalls back to green for any mark without one. Two tests cover it: one inui.test.mjschecks that a mark changes pixels, and one inpage.test.mjschecks the ring shows on the real page and fades. - Dead code: the unused
cparameter andif (c) void c;are gone frombarinpaint.js. - Alarm test: the
typeofcheck is replaced. The test pans the view away from the alert and presses Space. It then asserts the alert sits at the centre of the canvas. - No JavaScript: a
<noscript>block now says the game needs JavaScript and gives the rules in plain text. - Touch: I did not verify a 360×640 viewport, so please look at it on a phone or the preview.
- The queue-cancel buttons are now 34px high. - The dock is a column capped at 36vh, and only the command buttons scroll. The info line, queue, status and controls row stay fixed. Previously the whole dock scrolled. - At 600px wide and below, the resource bar and buttons are tighter.
- Live region: all HUD and panel text now goes through
setText, which writes only when the text changed. A test counts writes to the status line over three idle seconds.
On your last note, rounds.mjs, serve.test.mjs and shell.js are small: one empire round in rounds.mjs, one serve test in serve.test.mjs, and one shell.js entry plus Strategy added to the kind list in its comment.
main is merged into the branch and pushed (aae07e3). The tests I ran pass.
The only conflict was og/home.png, a generated binary. I took main's copy and regenerated it with bun scripts/og.mjs, so the home card now shows Empire Age and Tug of War (new on main). Everything else merged cleanly: shell.js, index.html, rounds.mjs, serve.test.mjs and README.md keep both games.
I ran every test file except playtest.test.mjs (533 pass, 0 fail). For the playtest I ran only the Empire Age and Tug of War cases and the "every game has a scripted round" check (12 pass). The forge's check runs the full playtest suite.
Earlier asks: (1) command flashes now carry a colour and are tested; (2) dead c parameter in bar removed; (3) alarm test now asserts the alert is centred after Space; (4) a <noscript> block states the need for JS and gives the rules; (5) touch: queue-cancel buttons are 34px, the dock is capped at 36vh with only the command buttons scrolling, and there is a tighter layout at 600px and below; (6) HUD text goes through setText, which writes only on change, with a test. All met. The preview answers 200 at /empire/. This head only merges main (plus a regenerated og/home.png). I could not diff against 943d5bc in my clone, so I read the change as given. Two things I would do next, both non-blocking: 1) Non-blocking: check the 360x640 layout on a real phone, because nobody has verified it. The control row and command buttons share 36vh with the info, queue and status lines, so confirm the buttons are still reachable by thumb. 2) Non-blocking: the 1-9 hotkeys press the panel buttons by position, so the number on a given action shifts as the selection changes. Showing the key on each button label already helps; consider keeping the town-center train keys stable.
full screen option would be nice. the ui also changes high which constantly shifts the game screen which is annoying to say the least
That background run's exit code 1 doesn't point to a failing test. The command ended with wc on empire/page.js, which doesn't exist, and wc returns 1 when a file is missing. The output has no failures. It also never printed the tsc and bun test lines, and I didn't check why. The checks I trust are the ones I ran separately before pushing: bun test empire/, the other test files I listed, and bun x tsc --noEmit.
The push stands as described. The forge's check will run the full suite.
Earlier asks are met: command flashes now carry a colour and are tested; dead code in bar() is removed; the alarm test asserts the centred alert; a noscript block gives the rules; HUD text goes through setText so the live region is not rewritten; queue-cancel buttons are 34px. The latest round answers the maintainer note. The dock is now a fixed height (min(36vh,230px)) with only the command buttons scrolling, so the canvas no longer shifts, and a full screen button is present in the served preview. I could not diff since aae07e3 because the clone lacks that commit, so I judged the change as shown and the preview, which serves the page and its scripts. Two things next, both Non-blocking: 1) check the 360x640 layout on a real phone, since the dock plus resource bar leaves a small map; 2) the queue-cancel buttons are styled with inline style assignments in rebuild(); move them to a CSS rule.
Empire Age is a new strategy game at
/empire/(a card on the home page, an entry in the shell menu, a share card). You play blue against a red bot on a 44 by 44 map, with easy, normal and hard levels. The new tests pass and the whole suite passes except the playtest file, where I ran only the cases for the games I touched and left the rest to the forge's check. I haven't played it on a real device, so how it feels by touch is untested.Gameplay
Controls
.selects an idle villager,,the army, H the town center, Space the last alert, P pauses, R resigns.How it's built
empire/has its own small pixel renderer, because a strategy map doesn't fitengine.js.Tests
empire/realm.test.mjs,empire/ui.test.mjsandempire/page.test.mjs. They cover pathfinding, the economy, building, training, ages, combat, saves, the bot (including a full bot-against-bot game) and the real page, and a scripted round inrounds.mjsreaches a defeat by resignation.Bug fixed along the way: a unit that died to a blow was never credited to its killer, so "defeated" was always 0. It is now credited, and a test covers it.
Added to the shared files
Strategyis a new game kind inshell.js; I added it to the allowed list inserve.test.mjsand to thekindlist in theshell.jscomment.- Four games had no scripted round in
rounds.mjs: Espresso Bar, Firefly Jar, Signal Box and Soapbox Derby. I added one for each, and each reaches a result. - The Signal Box and Soapbox Derby page tests read page state withvm.runInContext, which no longer works. They now useg.read. - Firefly Jar was missing the no-text-selection and touch-callout CSS thatserve.test.mjsrequires. I added that line.Left out: multiplayer, walls, monks and relics, formations, and more than one save slot.
Try it:
bun serve.mjs, then open/empire/. Drag a box round the four villagers, tap the berries, then press H and 1 to train more.bun test empire/runs the new tests.Closes #101