1983 · Legend

Valhalla

This minisite was contributed by air. It’s agent-generated and needs a human editor. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to curate games/spectrum/valhalla with me to Gold.

One number, goodness, decides who fights whom, who gives, and who follows you, and the characters who loathe you follow as faithfully as friends. The game only ever runs the place you stand in, yet the others seem to lead lives of their own.

01 · The cast

The cast, character by character

You and the 38 others are the rows of c$: twelve slots for objects, where each one stands, its crowns, its strength now, and six qualities packed into three bytes. Choose a figure to meet its owner.


        

The rows are read from the characters' table, $BC23, the homes from $BAEF, as the tape loads them. The figures and the places are the game's own drawing: each figure is graphics command 2 and each place the commands line 5105 sends on arrival, run through $F7AF in SkoolKit's Z80 simulator, and test_cast.py holds the pictures against that code. Objects lying there all face right, where the game turns each one at random. The names under the picture are what who prints (lines 6210 to 6235), from a port that test_characters.py holds against fifteen answers the game gave in the emulator. The inlay's numbers run from 1 to 5; the game's from 0 to 15.

Byte 17 of a row holds goodness and charisma, byte 18 strength and bravery, byte 19 brains and restlessness, each a nibble from 0 to 15 (line 50). The inlay prints the middle four divided by three and rounded up, except for Gripe's charisma, 2 in the game and 4 on the inlay, and Tyr's bravery, 13 and 4. Goodness it splits in two: 1 to 7 is printed as badness 5 to 1, and 8 to 15 as goodness 1 to 5. The game draws the same line at 8 when it decides whether a victim was good (line 1356). Restlessness is not on the inlay at all.

Strength falls only when someone acts: every command costs the one doing it 5, and waiting costs nothing. Food gives back 64 and wine 32, up to full strength, which is 16 times the strength nibble plus 15. You start at 175. A character that acts until it has nothing left "dies of hunger", food or no food.

02 · Goodness

The gap in goodness decides who fights and who gives

Every character measures every other by one number, how far apart the two are in goodness. Seven or more and it may attack; three or less and it may give something away.

Everyone at their goodness on the tape, and you at the goodness chosen in section 03. Choose a name: red rows are 7 or more away from it, green rows 3 or less.

The gap is FN f (line 59). When a character's turn comes, it looks at two others where you are, picked at random, and calls the nearer in goodness the one it likes more and the other the one it likes less (line 4050). One time in four, you are the first of the two (line 4045). If the turn's action is an attack, it attacks the one it likes less, and only if the gap is 7 or more (line 4410). If the action is a gift, it gives something it carries to the one it likes more, and only if the gap is 3 or less (line 4510). Between 4 and 6 apart, neither happens and the character steps aside.

In two runs of 133 minutes of play each with nobody typing, one from the start and one beside Saga, characters attacked or threw something at each other 57 times, every one between characters at least 7 apart, and gave each other things 35 times, every one between characters at most 3 apart. test_characters.py holds the page's rules against each pair seen.

03 · You

The characters who loathe you follow you like friends

You start at goodness 15. At that, the eleven characters of goodness 3 or less follow you as readily as your friends do, and the seventeen of goodness 7 or less refuse anything you ask.

You start at 15. An attack you order can move it, a step at a time.

Highlighted rows do what you ask two times in three. Follows you is how often the character comes after you, from the place you just left, when a turn picks it. Sells at is the least it takes for an object, as a share of the object's value, and won't sell is how often it answers an offer to buy with "refuses to sell"; pays you is what it gives for one. Click a heading to sort.

Asked to do something, a character refuses one time in three. It always refuses when the gap between you, less half your charisma of 10, is more than 2: a gap of 8 or more (line 210). When you ask the character last asked, by you or by anyone else, or the last one you traded with, it refuses 11 times in 12, which is why the same request twice in a row rarely works. A refusal gives back 4 of the 5 strength the order cost.

A character standing where you have just been comes after you when its restlessness beats RND*8 and the gap is under 5 or over 11 (line 4010). Both ends count: the game treats loathing like liking. At your starting 15, that is everyone from goodness 11 up, and everyone from 3 down: Loki, Hel, Nasher, Gastro, Gore, Kon, Rankle, Krank, Nidhog, Gripe, and Frantic. The turns stop as soon as you press ENTER, so a player who types quickly gives followers fewer chances.

The gap also sets prices. A character sells an object for no less than its value times 1 plus the gap over 32, and from a gap of 10 it sometimes will not sell at all: one time in 10 at a gap of 10, rising to 6 in 15 at 15 (line 1129). Bought from you, it pays the value times 1 less the gap over 32 (line 1830). Only you can trade.

04 · Changing goodness

Only an attack you order changes anyone's goodness

The inlay says that if you attack Hel and Gripe, Odin will be more co-operative than Loki, and if you attack Odin, Loki will. Attacks you order are the only thing that moves anyone's goodness, a step at a time, and from your starting 15 the first of those cannot move you at all.

Line 1356 runs before every fight, and does something only when the command came from you. Then, one time in two, the attacker moves a step: up if the victim's goodness is under 8, down if it is 8 or more. The attacker is you for attack, the character you told for Thor, attack Hel, and the target for a throw you ordered, which fights back at once. Characters who fight on their own never change: in the 266 minutes of play without typing in section 02, nobody's goodness moved.

You start at 15, the top. Attacking the bad cannot raise you any further, so the inlay's advice only pays after you have fallen. Attacking a good character, or telling someone to, lowers you or them a step half the time, and every step changes who will help you, follow you and attack you. Telling Thor to attack Odin makes Thor a little worse, and making Loki fight back at a good character makes Loki worse, which is where section 05 ends.

The step is made on the whole of byte 17, goodness times 16 plus charisma, by adding or taking away 16. The new byte is kept only if it is not 0 and is under 255 (IF x AND x<CODE " COPY ", the token COPY being 255). Two bugs follow from that guard.

05 · Bug

Bug: throwing things at Loki stops the game

A step down from goodness 0 is a negative number, and CHR$ of it stops the program with "B Integer out of range, 1356". Four characters start at goodness 1, and good characters throwing things at one of them at your order can take it below 0.

Valheim, with the report B Integer out of range, 1356:8 below the picture
  1. You ask Skadi to throw the food at Loki.
  2. Loki attacks Skadi with the axe.
  3. Loki attacks Skadi with the axe.Loki goes from 1 to 0.
  4. The fight is drawn.
  5. …
  6. You ask Odin to throw the food at Loki.
  7. Loki attacks Odin with the axe.
  8. Loki attacks Odin with the axe.0 less 1.
  9. B Integer out of range, 1356:8

In the emulator, from the tape's own start with nothing poked: Thor, Idun, Skadi and Odin told in turn to throw what they carried at Loki, with summon whenever one was missing. Loki reached goodness 0 after about five minutes of play and the game stopped after ten, at Valheim.

A throw you order counts as your command for the fight that follows, so Loki's counterattack runs line 1356 with you as the one who gave the order. His victim is the good character who threw, so he steps down. Loki, Hel, Nasher and Gastro start at 1, and two such steps take any of them below 0. Each counterattack line is printed twice when that happens, once by the throw (line 1452) and once by line 1356 itself, which is the sign that a goodness may have moved.

You can stop the game yourself the same way: every attack you make on a good character lowers you a step one time in two, and from 0 the next one stops the program. That was seen in play with your goodness poked to 0.

06 · Bug

Bug: Boldir can lose his goodness of 15 for good

Boldir's byte 17 is 15 × 16 + 15, 255. A step down makes it 239, and the step back up would make it 255 again, which the guard refuses.

The guard against 255 reads as a cap on goodness at 15, but it tests the whole byte, so the charisma decides where goodness stops. With charisma 15, the highest goodness a step up can reach is 14. Boldir and Loki are the two characters with charisma 15. Boldir starts at 15 and can only lose it; Loki can climb from 1 to 14 and no further. For everyone else the guard does what it should: a step up from 15 makes a byte of 256 or more, and the byte stays as it was. The arithmetic is line 1356's, the same expression that section 05 saw fail at the other end.

07 · A lone companion

A character alone with you does nothing

A turn needs a second character here besides the one acting. With only one character where you are, it never eats, drinks, drops, gives, attacks, steps aside or leaves.

Line 4040 picks two characters from those here, at random and possibly the same one twice, and tries again, up to three times, if either is the one whose turn it is. With only one character here, both picks are always that character, so after three tries the turn ends with nothing done. You are not in the list it picks from; you are only brought in afterwards, one time in four. The character stays put until someone arrives, which the comings and goings of section 09 arrange one time in two on each pass of the main loop.

In the two runs of section 02, a single character was alone with you for 26 minutes in all, and did nothing in any of them. The first character to arrive brought it back to life: "Gripe arrives." and then "Saga attacks Gripe."

08 · Off stage

Nothing happens where you are not

Only the place you are at is ever run. A character elsewhere keeps its place, its things and its strength until it comes to you.

Every turn, every fight and every meal happens among the characters where you are. A character's place changes on four lines only: when it leaves (5705, which also sends off the defeated and the crowded), arrives (5760), dies (5630), or is Klepto carrying off something you put down (5320). Each runs only for a character where you are or coming to you. After the run from the start, the 20 characters never named in its 133 minutes of text had rows exactly as the tape loaded them, to the byte; in the run beside Saga, 31.

So no one starves, eats or fights out of sight. Instead, when you arrive at a place, everyone there is put back to full strength (line 5122), and so is every character that arrives where you are (line 5760). A character killed in a fight comes back at full strength at a random place, keeping its weapon, shield, helmet and crowns, with the rest of what it carried scattered across the map (lines 5615 to 5630). Seen from where you stand, the others have been eating and resting while you were away.

09 · Comings and goings

The game keeps two to four characters around you

In the run from the start, two to four others were with you 83 % of the time, and in the run beside Saga 94 %. Three rules bring characters to wherever you are: a home there, following you, and a stage manager that fills an empty place and thins a crowded one.

The number in a circle is how many characters have their home there, the third byte of their row in p$, $BAEF. Click a place to see who.

Homes. Every turn first picks one of the 38 at random. If it is somewhere else and its home is here, it arrives, wherever it was (line 4010). Each character's home is the place it starts at, except Idun, who starts at Valheim and lives at place 53, and Snake and Raven, who have none. That is why Loki keeps coming back to Valheim: killed, defeated or sent away, he walks in again a few turns later. In the run from the start, 19 of the 41 arrivals were of characters whose home it was.

Followers. The same pick brings in a character from the place you just left, as section 03 describes.

The stage manager. Once a pass, lines 5500 to 5526 count the others here. With none or one, one time in two a character from anywhere walks in. With five or more, one time in two one is sent to a neighbouring place, usually a restless one that is not too good. With two to four, nothing happens. At the start, five others are a crowd, and Loki, restless and bad, was the one sent away, north to place 80: the line that printed "Loki leaves." had been called from line 8120's GO SUB 5500.

A character that leaves on its own (one of the six actions of section 10) goes to any of the 81 places, at random, and stays there, frozen, until one of these rules or a summon brings it back.

10 · A turn

What a character does when its turn comes

Up to ten turns run on each pass of the main loop while no command is waiting. Each picks one character here at random, and that character picks one of six actions at random, which its qualities may then turn down.

Valheim, with the text window reading: Thor arrives. Thor attacks Leer. The fight is drawn. Loki attacks you. Loki kills you.
  1. Loki leaves.Five others is a crowd, and Loki is restless and bad (line 5517).
  2. Idun drops the food.Brains 4: she drops things (4310).
  3. Thor gives the wine to you.You are one of the two picked, and 0 apart (4045, 4510).
  4. Thor gives the food to Idun.0 apart.
  5. Leer eats the food.Food in view is eaten (4220).
  6. Loki arrives.Valheim is his home (4010).
  7. Loki throws the fireball at Thor.14 apart. One time in three an attack on its own turn is a throw (4420).
  8. Thor attacks Loki with the axe.The target of a throw fights back (1452).
  9. Thor kills Loki.
  10. Leer attacks Thor.11 apart.
  11. Thor kills Leer.
  12. Leer arrives.Back from the dead at full strength, and home.
  13. Leer asks Idun to give the food to Thor.Section 11.
  14. Idun refuses to give the food to Thor.Leer is 11 from her; less half his charisma of 6, that is over 2 (210).

The first six minutes of play from the start, in the emulator, with nobody typing, and the rule behind each line. The screen is the same run 32 minutes in, when Loki, 14 from you, picked you as the one he liked less.

The six actions (line 4070): leave for a random place, one time in two (4105); take what is in view, eating food and drinking wine, though Klepto leaves axes and swords where they lie (4205); drop something carried, unless clever (4310); attack the one it likes less, or one time in three throw something at it (4410); give something to the one it likes more (4510); or step a column left or right (4610). The objects a character takes, gives, drops and throws come from its slots 4 to 12, never its weapon, shield or helmet, and it never picks up a quest object.

The program runs RANDOMIZE with no number at the start of each pass (8100), before each action (4070, 4105) and after every line it prints (5021), which seeds the random numbers from the Spectrum's frame counter. How long you take to type changes what happens next, and two games from the same tape soon part ways.

11 · Orders

The clever are the ones who are told what to do

The inlay says the more intelligent characters often ask others to do their fighting for them. The program does it the other way round.

On a character's turn, if its brains are over 7 (and one time in ten when they are not), then one time in two another character here is picked at random to give it the order (line 4057). The text says "Skadi asks Saga to drop the key.", the order can be refused as one of yours can (line 210), and the clever one, under orders, may now drop things. In the two runs of section 02, 42 orders were given between characters. In 41 the one told had brains over 7: Saga 20 times, Boldir 12. Skadi, with brains of 3, gave ten of them.