Skip to content

v0.41.0 — six games, no menus

Choose a tag to compare

@ralyodio ralyodio released this 11 Aug 10:49
e3947e9

The pit has an arcade in it now.

/games — six games, no menus

/games                 # the cabinet
/games tetris          # play one
  moshcode arcade — 6 games, no menus, no options screens

  tetris     stack the bricks, clear the lines, outrun gravity
  snake      eat, grow, and try not to eat yourself
  pacman     eat the dots, dodge the ghosts, ✳ makes them edible
  tictactoe  three in a row against a perfect opponent
  chess      full rules, real opponent, pawns auto-queen
  hangman    six wrong letters and you are done for

Also moshcode games from a shell, and moshcode games --json for the roster.

One arcade, not six weekend projects

Every game shares one frame, one key decoder and one driver, so they look alike by construction: a title, a status, a boxed board, and one line of keys along the bottom.

  TETRIS       score 1200 · lines 12
  ┌────────────────────────────────┐
  │ · · · · ████· · · ·   NEXT     │
  │ · · · · ████· · · ·            │
  │ · · · · · · · · · ·   ████████ │
  │ · · · ████· · · · ·   LVL 2    │
  │ ████████████· ██████           │
  └────────────────────────────────┘
  ← → move · ↑ rotate · ↓ drop one · space slam · q quit

There is no menu, no options screen and no difficulty prompt. /games tetris is already playing by the time the frame lands, and the controls are written along the bottom of the game itself rather than on a screen you have to leave. Arrows move, q quits, r starts another — in all six.

They draw in place rather than on the alternate screen, so the board you finished on stays in your scrollback next to the prompt, and a frame identical to the one already there is not repainted at all.

Chess plays the real game

Castling — refused through an attacked square — en passant, promotion, check, checkmate and stalemate. The opponent is an alpha-beta search that takes what you leave hanging.

Its reply runs on the clock rather than inside your keypress, which is the difference between a board that answers and a terminal that freezes: your own move is on the board and drawn before the machine starts thinking about it.

Why the games are testable at all

Each game is pure — create a state, hand it a key, hand it a tick, ask it for rows — and everything that touches a terminal lives in one driver. So the tests play real games with no TTY anywhere near them: a tetris well filled until it stacks out, pac-man walked around until the maze is cleared, hangman won and lost, and the driver itself driven through a fake stdin.

Two of those are the kind you cannot do by hand. The tic-tac-toe opponent is played forty games of random moves and must never lose — a minimax that is subtly wrong looks fine to a human who is not trying to prove it. And pac-man's maze is flood-filled from where pac starts, with every dot required to be reachable: a walled-off pocket is a game that cannot be won, and nobody would reliably find the pocket by playing.

Install

curl -fsSL https://raw.githubusercontent.com/moshcoder/moshcode/main/install.sh | bash

or npm i -g moshcode@0.41.0