Cite as
coding-horror/basic-computer-games
Original
https://github.com/coding-horror/basic-computer-games
Pinned
coding-horror/basic-computer-games @ 5301155192d91d74d337899cecc59dbda59c4c17
Accessed
2026-10-20
Licence
The repository is under the Unlicense (public-domain dedication). The original BASIC listings come from BASIC Computer Games (© 1978 Creative Computing); the repository republishes them, and that dedication can't cover them. Quoted here a line at a time.
Credit
Jeff Atwood (Coding Horror) started the project. Lyle Kopnicky normalized the original listings to run under Vintage BASIC (vintage-basic.net, 2009). David H. Ahl edited the book and converted Hamurabi to BASIC; Steve North converted the 1978 edition to Microsoft BASIC.
Notes
Read: 43_Hammurabi/hammurabi.bas, the book's Hamurabi listing (pp. 78–79) with one statement per file line, so file line numbers differ from BASIC line numbers; locators give both. Checked against the 1978 book scan (ahl-1978-basic-computer-games): every rule and constant matches. The file corrects three slips in the printed listing: line 895 prints "IF IF", and line 541's REM and line 900's PRINT read HORROS and CHARLEMANGE here but HORROR and CHARLEMAGNE in the book. The date is the pinned commit's ("Merge pull request #941").

Cited on

Claims (21)

The first report shows 100 people (95 plus 5 arrivals), 1,000 acres, and 2,800 bushels in store, left from a harvest of 3,000 bushels at 3 bushels per acre after rats ate 200.43_Hammurabi/hammurabi.bas L6–20Code
The book's description starts the city with 3,000 bushels in storage, but the listing's first report shows 2,800, because rats ate 200 of a 3,000-bushel harvest.43_Hammurabi/hammurabi.bas L7Code
Each year land trades at 17+⌊10r⌋ bushels per acre for a random r in [0, 1), a whole number from 17 to 26.43_Hammurabi/hammurabi.bas L22–23Code
The player may buy land at the year's price if the store covers it, and buying any land skips the chance to sell that year.43_Hammurabi/hammurabi.bas L24–31Code
A sale pays the same price per acre into the store, and the city must keep at least 1 acre.43_Hammurabi/hammurabi.bas L32–37Code
Each person eats 20 bushels a year, so the number fed is the bushels given divided by 20, rounded down.43_Hammurabi/hammurabi.bas L74–75Code
Seed costs half a bushel per acre planted, rounded down, and must come from the store left after feeding.43_Hammurabi/hammurabi.bas L54–5543_Hammurabi/hammurabi.bas L62Code
One person can farm 10 acres, but Ahl's check is strict, so P people may plant at most 10P−1 acres, where Dyment's FOCAL allows 10P.43_Hammurabi/hammurabi.bas L58–60Code
The yield is a whole number of bushels per acre from 1 to 5, each equally likely, and the harvest is the yield times the acres planted.43_Hammurabi/hammurabi.bas L63–6543_Hammurabi/hammurabi.bas L92Code
A second roll of 1 to 5 sets the rats loose when it is even, 2 times in 5, and they eat the store divided by the roll (half on a 2, a quarter on a 4) before the harvest goes in.43_Hammurabi/hammurabi.bas L66–70Code
Arrivals are ⌊c(20A+S)/(100P)+1⌋, where c is a third roll of 1 to 5, A the acres, S the store after harvest and rats, and P the population before starvation.43_Hammurabi/hammurabi.bas L71–73Code
A plague halves the population when ⌊10(2r−0.3)⌋≤0, which holds for r<0.2, a 20% chance, though the remark beside it says 15%.43_Hammurabi/hammurabi.bas L76–7743_Hammurabi/hammurabi.bas L13–15Code
Everyone not fed dies, and the population becomes the number fed; a surplus kills no one and the population stays.43_Hammurabi/hammurabi.bas L78–82Code
Starving more than 45% of the population in one year gets the ruler impeached and ends the game.43_Hammurabi/hammurabi.bas L79–86Code
A year with food to spare skips the update of the average starvation rate P1, so the next update counts that year at the old average instead of 0%.43_Hammurabi/hammurabi.bas L78–81Code
A term is 10 years of decisions; the 11th report ends the game with the rating.43_Hammurabi/hammurabi.bas L1043_Hammurabi/hammurabi.bas L21Code
The final rating tests the average yearly share starved, P1, and the acres per person, L, against three pairs of limits, and the first pair the ruler fails sets the verdict.43_Hammurabi/hammurabi.bas L97–116Code
Ahl's BASIC still sets C to 0 after a land trade and to 1 after feeding, values nothing reads before the next dice roll overwrites C, because in Dyment's FOCAL those lines reset the steward's patience.43_Hammurabi/hammurabi.bas L3043_Hammurabi/hammurabi.bas L3743_Hammurabi/hammurabi.bas L46Code
Ahl's steward answers an impossible order with "THINK AGAIN" and asks again as often as needed, and only a negative number ends the game.43_Hammurabi/hammurabi.bas L24–2843_Hammurabi/hammurabi.bas L87–96Code
DEC's 1975 printing of the listing has the same rules and constants as the 1978 edition, except that its seed check, INT(D/2)<S, refuses a planting that would use the last bushel.43_Hammurabi/hammurabi.bas L55Publisher
Ahl's BASIC keeps Dyment's rules for seed, the harvest, rats, arrivals, and food, down to the arrivals formula c(20A+S)/P/100+1.43_Hammurabi/hammurabi.bas L62–75Code