{"slug": "my-swift-terminal-games-play-themselves-press-an-arrow-key-to-take-over-in-your", "title": "My Swift terminal games play themselves. Press an arrow key to take over, in your browser", "summary": "A developer built NeNe Swarm and NeNe Bolt, two Swift terminal games with self-playing AI that hands control to a human on any arrow-key press and reclaims it after 30 seconds of inactivity, and shipped browser versions as TypeScript ports. To verify the ports, each replays the same seeds and scripted key presses as the Swift originals and compares per-frame hashes of characters and colors, matching on 240,008 frames for Swarm and 258,010 for Bolt. The games use Windows Terminal's win32-input-mode (ESC [ ? 9001 h) to detect key holds and releases, falling back to key-repeat timing elsewhere, and install via a one-line script for Linux x86_64 and WSL2.", "body_md": "NeNe Swarm is a fixed-screen shooter, and NeNe Bolt is a side-scrolling platformer. In both, an AI plays forever. Press an arrow key and the game is yours from that frame on; leave the keys alone for 30 seconds and the AI takes over again.\n\nThey are written in Swift for the Linux terminal, and both also run in the browser. Open [hideyuki-mori.com](https://hideyuki-mori.com/?utm_source=devto&utm_campaign=swift-terminal-games) on a computer with a keyboard (a phone has no arrow keys), click the **swarm** or **bolt** icon on the site's desktop, click inside the window and press an arrow key.\n\n|  | Swarm (fixed shooter) | Bolt (side-scroller) | \n|---|---|---|\n| Move | ← → | ← → | \n| Climb ladders | — | ↑ ↓ | \n| Jump | — | Z or Space (hold for higher) | \n| Fire | Space or Z | X (hold to charge) | \n| Theme / difficulty / quit | t / d / q | t / d / q | \n\nWhile you are playing, the HUD says so (`YOU AI IN 27` in Swarm, `PLAYER 30s` in Bolt) and counts down to the moment the AI takes the controls back.\n\nIn Bolt, hold → and the runner keeps running; let go and it stops on that frame. That isn't a given in a terminal. Hold → in most terminals and the program gets a stream of repeated arrow sequences; let go and it gets nothing.\n\nWindows Terminal has a mode for this. When the game writes `ESC [ ? 9001 h` at startup, the terminal switches to win32-input-mode, and every press and every release arrives as its own sequence, `ESC [ Vk ; Sc ; Uc ; Kd ; Cs ; Rc _`, where `Kd` says whether the key went down or up. These sequences pass through to programs running inside WSL, so the game knows exactly which keys are held on each frame. On exit it writes `ESC [ ? 9001 l` before restoring the screen.\n\nIn other terminals the games fall back to key repeats: a key counts as held for 0.6 seconds after it arrives and then for as long as the repeats keep coming, so the runner can overshoot a little. In the browser it's simple again, since `keydown` and `keyup` give the same information as win32-input-mode.\n\nThe game itself is a pure function: the current state, the buttons held on this frame and a seeded random source give the next state. Only the outermost layer reads the time, the keys and the seed. Your keys and the AI's decisions become the same set of buttons and go through the same function. Positions are integers (one cell is 16 units), and on screen the ships, runner, enemies, shots and terrain are blocks of color two terminal columns wide, so one \"pixel\" comes out roughly square.\n\nThat is what made the browser versions checkable. They are TypeScript ports, written with Claude Code like the Swift originals, and I don't take a port's word for it: each one replays the same seeds and the same scripted key presses as the Swift code, renders every frame at two terminal sizes, and compares a hash of each frame's characters and colors with what Swift produced. The random generator is the same SplitMix64 on both sides, done in exact integer arithmetic. Swarm's port matches on 240,008 frames, including a script where a human cuts in four times and lets the AI take back over four times. Bolt's matches on 258,010.\n\nSo when you take the controls on the site, you are playing the same game the Swift binary runs. [Try Swarm or Bolt at hideyuki-mori.com](https://hideyuki-mori.com/?utm_source=devto&utm_campaign=swift-terminal-games) and see how long you last before the AI gets them back.\n\nEach game has a one-line installer for Linux x86_64 (WSL2 on Windows works). For Swarm:\n\n```\ncurl -fsSL https://raw.githubusercontent.com/hideyukiMORI/nene-swarm/main/install.sh | bash\n```\n\nIt checks the 2.7 MB download against `SHA256SUMS` and installs one binary in `~/.local/bin`. The Swift standard library is linked in, so all you need is glibc 2.35 or newer. From PowerShell, `install.ps1` in the same repository runs it inside WSL.\n\nBolt and Swarm have six siblings, all in Swift and open source: [Gambit](https://github.com/hideyukiMORI/nene-gambit) (four AIs trade insults over chess), [Igo](https://github.com/hideyukiMORI/nene-igo) (the same on a 19×19 Go board), [Wire](https://github.com/hideyukiMORI/nene-wire) (a news ticker), [Reversi](https://github.com/hideyukiMORI/nene-reversi), [Poker](https://github.com/hideyukiMORI/nene-poker) and [Sand](https://github.com/hideyukiMORI/nene-sand) (pour sand with the mouse). Gambit, Igo and Wire run on the site too, to watch rather than play. The sources of the two you can play: [nene-swarm](https://github.com/hideyukiMORI/nene-swarm) and [nene-bolt](https://github.com/hideyukiMORI/nene-bolt).\n\n── Hideyuki Mori 🔗 [hideyuki-mori.com](https://hideyuki-mori.com/?utm_source=devto&utm_campaign=swift-terminal-games)", "url": "https://wpnews.pro/news/my-swift-terminal-games-play-themselves-press-an-arrow-key-to-take-over-in-your", "canonical_source": "https://dev.to/hideyukimori/my-swift-terminal-games-play-themselves-press-an-arrow-key-to-take-over-in-your-browser-2o46", "published_at": "2026-11-28 08:04:48+00:00", "updated_at": "2026-11-28 08:13:42.858111+00:00", "lang": "en", "topics": ["developer-tools", "ai-agents"], "entities": ["NeNe Swarm", "NeNe Bolt", "Swift", "TypeScript", "Claude Code", "Windows Terminal", "WSL2", "hideyuki-mori.com"], "also_reported_by": [], "takeaway": "Enabling win32-input-mode with ESC [ ? 9001 h gives a terminal game true key-down and key-up events, while other terminals need a 0.6-second hold heuristic that can overshoot.", "recommendation": {"advice": "Verify a port by replaying identical seeds and scripted inputs and comparing per-frame hashes of characters and colors against the original implementation.", "playbook": "output-verification", "playbook_url": "https://wpnews.pro/playbooks/output-verification"}, "alternates": {"html": "https://wpnews.pro/news/my-swift-terminal-games-play-themselves-press-an-arrow-key-to-take-over-in-your", "markdown": "https://wpnews.pro/news/my-swift-terminal-games-play-themselves-press-an-arrow-key-to-take-over-in-your.md", "text": "https://wpnews.pro/news/my-swift-terminal-games-play-themselves-press-an-arrow-key-to-take-over-in-your.txt", "jsonld": "https://wpnews.pro/news/my-swift-terminal-games-play-themselves-press-an-arrow-key-to-take-over-in-your.jsonld"}}