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
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
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
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
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
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
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 Live

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