X_eTaL Games

Small games written in X_eTaL, a typed array language: each one is written around one array idea and happens to be playable.

Start here

  1. What you are looking at. Small games written in X_eTaL, each running in your browser. A game's page plays it in a terminal (type and press Enter), runs its scripted program as a notebook, and shows its source: everything on the page is X_eTaL's own output. Every game also runs at the command line (the README says how).
  2. Why an array language. These games are about whole boards, all the pieces or every possible move at once, and X_eTaL says them that way, with no loop over squares or pieces:
    p + r̲oll! 5 r̲eshape 3
    Every horse moves at once: one roll per horse, added to the vector of positions (horse race).
    ('+ r̲/₁₂ -1 0 1 o̲-₁₂ p) − p
    Every square's count of neighboring mines at once: the board rotated by every offset and summed, less itself (minesweeper).
    (r̲ange 9) '+ '× i̲nner 2 2 2 2 2 2 2 2 2 e̲ncode o̲ffsets 512
    Every set of tiles at once: the 512 subsets of 1 to 9 as bits, and all their sums by one inner product (shut the box).
  3. Try one. Pick a game below; the table says which array idea each one is written around. A title links to the game's history.
  4. Read the code. The cross-reference, written by xetal doc: every program and library of every game and the shared libraries, each definition with its type, its documentation and examples (run by the gate), its source, and every place it is used.

One array idea per game

Different games, the same few array ideas: each game is written around one.

The array idiomGame
a vector of racers moved by one expression; the leaders by a forkHorse race
every candidate against every guess by one table; all games played at onceGuess the number
a coordinate matrix moving at once; collisions as an inner productRobot chase
text as a table of rows picked by masks; refusals as dataTrek adventure
a galaxy of planes; paths as tables of steps; windows by selectionStar Trek
lines by indexing; ratings as one inner product; minimax as negamaxTic-tac-toe
masks over all 512 subsets at once; sums by one inner productShut the box
neighborhoods by rotate and reduce; flood fill to a fixed pointMinesweeper
compress, merge, compress as a train; turning by powers of 0 or 12048
a candidate tensor; every single at once by sums over units; rounds to a fixed pointSudoku
a press as a matrix; a board of presses as one product mod 2; Gaussian elimination over GF(2)Lights out
every distance at once, nearest by grade; a map drawn as SVG text; clicks as events; data from TOMLCapitals
brightness bands as a table; every star placed at once; the sky drawn as SVG text; clicks as events; data from TOMLStargazer
an entity-component system as arrays: entities as rows, components as columns, systems as whole-column expressionsDungeon
a maze carved in one go (runs by a running sum, one way north per run by a table), distances by a flood to a fixed point, the view as lookups at every depth at onceMaze
systems over every body at once: gravity, movement and collision with the ground as whole-column expressions, ticked by the clockSide-scroller
a piece turned by reversing and transposing; full rows by a row-wise and, cleared by keeping the others; a computer player that tries every turn and column at onceFalling blocks
laps and places as systems: every car against every segment of the track, every pair of cars compared at once, ticked by the clockRacer
every tower against every creep in one table; shots against creeps in another (splash, armor, chill); the road found by a flood; an isometric board by one linear map and clicks by its inverseTower defense
entities that come and go: spawning and despawning by masks, every shot against every rock at once, ticked by the clockAsteroids
ray casting as arrays: a ray per column, all stepped through the grid together to a fixed point; walls as tall as they are nearRaycaster

Action

Side-scroller

systems over every body at once: gravity, movement and collision with the ground as whole-column expressions, ticked by the clock

Run and jump to the flag with the arrow keys: land on walkers, jump the pits, pick up coins. The game moves with the clock, twenty ticks a second. Built on lib/Ecs: you and the walkers are bodies, and gravity, movement and collision with the ground are each one expression over every body at once.

Ecs.xtlm macrotuples[]E_VENT ticks and keysmasks as numberst_ableSVG
Falling blocks

a piece turned by reversing and transposing; full rows by a row-wise and, cleared by keeping the others; a computer player that tries every turn and column at once

Fill whole rows to clear them as the pieces fall faster: move, turn and drop with the arrow keys and the space bar, or let the computer player place a piece. The well is a matrix and a piece a small square of 0s and 1s: it turns by reversing its rows and transposing, and full rows are found by a row-wise and and cleared by keeping the others.

o_\ transposer_evr_/_2 row-wiser_eplicate rowss_\ scanstuples[]E_VENT ticks and keysSVG
Racer
Live

Racer

laps and places as systems: every car against every segment of the track, every pair of cars compared at once, ticked by the clock

Three laps against three rivals with the arrow keys: steer, keep off the grass, finish first. The race moves with the clock, twenty ticks a second. Built on lib/Ecs: your car and the rivals are rows of one matrix, and driving, the grass, bumping, laps and places are each one expression over every car at once.

Ecs.xtlm macrotuples[]E_VENT ticks and keyst_ableranks by comparisonSVG
Tower defense

every tower against every creep in one table; shots against creeps in another (splash, armor, chill); the road found by a flood; an isometric board by one linear map and clicks by its inverse

Build and upgrade towers to stop six waves of creeps on the road, on an isometric board: click to build, click to upgrade, and open the grimoire to see every tower and creep turning. Built on lib/Ecs: every tower against every creep in one table, shots spawned and despawned, splash, armor and slowing as one table of shots against creeps; the board drawn in 2.5D by one linear map.

Ecs.xtlm macrotuples[]E_VENT ticks, clicks and keyst_ablefixed pointSVG
Asteroids

entities that come and go: spawning and despawning by masks, every shot against every rock at once, ticked by the clock

Break every rock, three waves of them, with the arrow keys and the space bar: big rocks break into medium ones, medium into small. The game moves with the clock, twenty ticks a second. Built on lib/Ecs: shots and rocks are spawned and despawned all the time, in the slots a mask says are free, and every rule is one expression over every entity at once.

Ecs.xtlm macrotuples[]E_VENT ticks and keyss_pawn and d_espawnt_ableSVG

Chance and strategy

Horse race
Live

Horse race

Horse races were among the first games people wrote for computers: a row of horses, each moved forward by a random amount every round, until one crosses the finish line. They were natural programs for the time-sharing terminals of the 1970s, in BASIC and in APL, where the whole field fits in one vector. Here five horses run to 15, each moving 1, 2 or 3 a round; at the terminal you start with 10 coins, back a horse for a coin each race, and win 4 back if it wins.

a vector of racers moved by one expression; the leaders by a fork

Five horses race to 15, each running 1, 2 or 3 a round, all at once. The field is one vector of positions and a round is one expression; the track is a character matrix drawn by a table. Bet on a horse at the terminal.

vectorsr_oll!reducew_heret_ablelibraries
Guess the number Live

Guess the number

Guess the number is one of the oldest computer games and often the first program a beginner writes: the computer thinks of a number from 1 to 100 and answers each guess with higher or lower. It is also the classic first lesson in searching: always guessing the middle of what is still possible (a binary search) finds any number in at most seven guesses. Type a number and press Enter.

every candidate against every guess by one table; all games played at once

The smallest COR24 BASIC game, at a terminal: higher or lower until you have it. Its scripted game checks every candidate from 1 to 100 against every guess at once, and plays all 100 games in lockstep.

r_oll!t_ablereducemasks[]R_EADlibraries
Tic-tac-toe Live

Tic-tac-toe

lines by indexing; ratings as one inner product; minimax as negamax

Three in a row against the computer. The eight lines are a table of square numbers: used as indices into the board it gives every line at once, and a reduce gives every line's sum. The computer rates every empty square at once; a minimax player searches by recursion.

index tablesreducem_ember?t_ablerecursione_achlibraries

Puzzles

Shut the box Live

Shut the box

masks over all 512 subsets at once; sums by one inner product

Roll the dice and shut tiles adding up to the roll; shut all nine to win. All 512 subsets of the tiles are one 9 by 512 matrix of bits, their sums one inner product, and the legal moves are the columns that fit the open tiles and add up to the roll.

e_ncodei_nnermaskso_\ transposes_elect_2libraries
Minesweeper Live

Minesweeper

neighborhoods by rotate and reduce; flood fill to a fixed point

Open a 9 by 9 field without touching its 10 mines. Every square's count of neighboring mines is computed at once, as Life counts neighbors, and opening an empty square floods: the opened region grows ring by ring until it stops.

o_-_12 rotationsreducemasksfixed pointg_rade[]G_RIDlibraries
2048 Live

2048

compress, merge, compress as a train; turning by powers of 0 or 1

Slide the tiles of a 4 by 4 board; equal tiles merge; make 2048. A move left slides and merges every row at once: compress by running counts and a table, merge by each tile's place in its run, found by a max-scan; the other moves turn the board with reverse and transpose.

s_\ scanst_ablemaskso_\ transposer_ev_2m_atchlibraries
Sudoku Live

Sudoku

a candidate tensor; every single at once by sums over units; rounds to a fixed point

Fill the 9 by 9 grid so every row, column and box holds 1 to 9. X_eTaL keeps every cell's candidates as one 81 by 9 array, finds every single at once by summing over the 27 units, repeats until nothing changes, and searches only when that stalls: Arto Inkala's "hardest" puzzle in under a second.

t_ables_elect with a tabler_/_2one-hotfixed pointsearchlibraries
Lights out Live

Lights out

a press as a matrix; a board of presses as one product mod 2; Gaussian elimination over GF(2)

A 5 by 5 board you click: a press toggles a light and its four neighbors; turn every light off. Every puzzle can be solved, and Hint rings a square of a solution X_eTaL works out by Gaussian elimination over GF(2): a press is a row of a matrix, a board of presses one product with it, mod 2.

t_ablei_nnerm_od[]E_VENTSVGlibraries

Quizzes

Capitals
Live

Capitals

every distance at once, nearest by grade; a map drawn as SVG text; clicks as events; data from TOML

A map you click: each red dot is a national capital inside its unlabeled country; click it, then its name among four nearby cities; choose a region or the whole world. X_eTaL reads the countries, capitals and cities from TOML, finds the nearest cities by computing every distance at once, and draws the map, its menus and the score as SVG; the page passes your clicks to the program as events.

[]T_ABLE[]L_IST[]E_VENTs_in c_osg_radef_ormat<SVGlibraries
Stargazer

brightness bands as a table; every star placed at once; the sky drawn as SVG text; clicks as events; data from TOML

A sky you click: five named stars ringed, mixed bright, middling and faint; click one, then its name among four (one star from each brightness band besides it); choose a part of the sky or all of it. X_eTaL reads the Bright Star Catalog and the IAU's star names from TOML, draws the whole sky as SVG, and the page passes your clicks to the program as events.

[]T_ABLE[]L_IST[]E_VENTt_ableg_radef_ormat<SVGlibraries

Retro

Robot chase Live

Robot chase

a coordinate matrix moving at once; collisions as an inner product

Twelve robots chase you across a 16 by 16 board and you make them crash. Every robot steps at once: the robots are one 2 by 12 matrix and a turn adds the sign of the difference; crashes are found by a table of every robot against every other.

matricessign by comparisonst_abler_eplicatereduce on rank 4g_radelibraries
Trek adventure
Live

Trek adventure

Star Trek: Decaying Orbit is a short text adventure in the style of the type-in listings that computer magazines printed for home computers: rooms, a few items and a clock, played by picking numbered commands. You wake alone on the bridge of the Enterprise with the ship falling out of orbit; find the toolkit and the engine coupler, prep the relay in engineering and install the coupler within 30 turns, while Klingon boarders roam the ship. Pick a command by number (8 is help); GO, TAKE and USE then ask for a room or an item.

text as a table of rows picked by masks; refusals as data

Star Trek: Decaying Orbit, a text adventure: restore the Enterprise's engines before its orbit decays, past a locked armory and Klingon boarders. No branching code for the story: every line is a row of a table with a key and a condition, a room is one mask, a turn updates the state vector.

string tablesmasksw_herem_ember?t_ablefunctional updatelibraries
Star Trek Live

Star Trek

a galaxy of planes; paths as tables of steps; windows by selection

The classic: destroy every Klingon in an 8 by 8 galaxy of 8 by 8 sectors before the stardate runs out, with warp, impulse, phasers, torpedoes and shields. The galaxy is three planes made at once, a course is a whole path at once, and phasers hit every Klingon in one subtraction.

8 by 8 planest_able pathsw_here first hitwindows by indexg_rade permutationsr_avel_2libraries
Dungeon
Live

Dungeon

an entity-component system as arrays: entities as rows, components as columns, systems as whole-column expressions

Find the way out with the arrow keys: fight rats and goblins, pick up potions and gold. Built on lib/Ecs, an entity-component system as arrays: you, the monsters and the items are rows of one matrix, what each is comes from its components (a new kind is a table in dungeon.toml, not new code), and every rule is one expression over all of them.

Ecs.xtlm macrotuples[]E_VENT keysw_here maskst_ableSVGlibraries
Maze
Live

Maze

a maze carved in one go (runs by a running sum, one way north per run by a table), distances by a flood to a fixed point, the view as lookups at every depth at once

Find the way out of a maze seen from inside: step and turn with the arrow keys, m for a mini map of what you have seen. A new maze every game, carved from its seed with whole-array operations; the way out is put at the farthest point by a flood, and the corridors ahead are looked up at every depth at once and drawn as SVG.

s_\ scanst_ablefixed pointtuples[]E_VENT keysSVG
Raycaster

ray casting as arrays: a ray per column, all stepped through the grid together to a fixed point; walls as tall as they are near

Find the way out of the walls, seen from inside, as the first 3D games drew it: one ray for every column of the picture, every ray stepped through the grid at once until all of them hit a wall. Walk and turn with the arrow keys; a mini map shows where you are.

fixed pointmasks as numberstuples[]E_VENT ticks and keysSVG