1985 · Melbourne House

Way of the Exploding Fist

This minisite was contributed by chunkypixel. It’s agent-generated and needs a human editor. Clone https://github.com/gamesexplained/gamesexplained and follow kit/START.md to curate games/c64/way-of-the-exploding-fist with me to Gold.

A hit test that measures distance, not timing, and a computer opponent whose ten dans are the same player tuned by eight tables.

01 · Scoring

A blow scores by distance, not timing

The manual talks of well-executed and loosely timed blows. In the code a blow is tested once, on its striking frame, and the only question is how far apart the fighters stand.

A port of the hit test ($2B8E), checked against the game's own routine for every blow, every defender frame and every distance from -40 to 60, with the defender facing the attacker and facing the same way, and the attacker facing either way: 262,196 cases, no difference. The button turns the defender round. The picture shows the two frames the test compares: the attacker on the frame its blow is tested on ($1204), and the defender on the chosen frame, set at the distance where the blow lands squarely. Both stand on the floor, even for a jump, because the test compares only how far apart they are, never their height, and the attacker is drawn in front so the blow shows where it meets the defender. In the game either fighter can be in front: sprites 0-2, which the video chip draws over sprites 3-5, go to the fighter throwing a blow, or to the other fighter during a spinning kick, and fighter_update changes that only on a pass of the fight loop where sprites 0-2 have touched nothing ($24, $281A). Below, green is a whole point, amber a half, grey a miss, for every distance along the attacker's facing; a negative distance puts the defender behind the attacker. Distances are between the left edges of the two sprite grids, in units of two pixels, so they say where the grids stand, not how long a reach is.

Each blow has two reach profiles, one byte per frame the defender might be in: one for a defender facing the attacker ($121D) and one for a defender facing the same way ($124F), 22 profiles in all at $7200-$7711. The byte is the distance at which the blow lands squarely. At that distance, or closer by up to a margin the blow sets ($11BD), it is a whole point; closer still, by up to a second margin ($11D6), a half point. A profile byte of $80 means a defender in that frame cannot be hit, which is how jumps and somersaults evade.

The test picks the profile by comparing the two fighters' facings ($2B90). When they face the same way it takes the distance the other way round and swaps the forward and backward comparisons ($2C44-$2CA7), so the same margins apply from the other side. For a forward blow that means a defender with its back turned: every blow has a profile for hitting a back, and a defender can be caught in about as many frames from behind as from the front. For the back kick and the back sweep it is the other way about: they reach behind the attacker, so a defender facing the same way is one standing at the attacker's back, looking at it, and the blow lands on its front.

Which side the blow lands on decides what follows ($2CA8). A blow on the front knocks the defender backwards (animation $16), or for the middle and low punches and the middle kick doubles it over ($1B); a blow on the back pitches it forward onto its face ($1A). The automatic block only answers a blow coming at the front ($2D00): one on the back cannot be blocked at all, and neither can a sweep, which the block code leaves out ($2AF2).

Four half points win a bout. Points for the score come from a table in hundreds ($12A5), halved for a half point.

02 · The opponent

Ten dans of the same opponent, with faster reflexes

The computer plays by a player's rules. On each pass of the main loop ai_think ($22CF) writes a move into the slot the joystick fills for a player ($63), so the computer has the same moves, the same timing and the same hit test. Its rank changes only a set of eight masks that bound its random choices.

What it checks, in order

  1. Is the opponent reeling from a blow? Then it starts nothing new: it waits for a count set by its rank and stands, at once if it was in a flying kick ($22CF).
  2. Is a plan under way? A plan is a short script started in answer to a blow, below. While one runs, the plan decides every move ($2689).
  3. Is the opponent throwing a blow? A blow being drawn back does not count. Already blocking, the computer holds the block while it is the right one for the blow and drops a wrong one. Standing or walking, it answers the blow if the blow can reach it ($2D00), after a reaction delay. In the middle of a move of its own it carries on, but drops a move it is holding or drawing back, and drops any move that is not low when the blow is a sweep.
  4. Otherwise it measures the distance ($241A). Far ahead, it walks forward in bursts with pauses. Far behind, it turns round. Close, it stands for a random count ($249B) and then picks an attack from a table indexed by distance.

A held move is let go after a random time ($23E8). Every random choice comes from one 8-bit generator ($2589) that steps through all 255 non-zero values, so the odds below are exact: each is a count out of 255.

Answering a blow

The answer to each blow at the chosen rank: a port of $237D, checked against the game's own code for every rank, every blow and every one of the 255 states of the random number, together with the attack choice below: 9,348 cases, no difference. One random number is masked with the rank's defence mask ($9C). Its top bit counter-attacks, with an attack chosen as below. Any of the next three bits blocks with the right block for the blow ($118F), which against a sweep is a jump. A zero in all of them gives the forward somersault or the low kick, on a second number. Anything else starts the plan for that blow ($2788), or blocks when the blow has none.

The plans are nine short scripts ($2774). Most answer with one move: the foot sweep against the low punch, middle kick and spinning kick; the flying kick against the low kick; the forward somersault against the foot sweep and the back kick. Some wait. Plan 1 crouches until the opponent stands up, or from 7th dan until the opponent crouches to spring (frame $19, the start of a jump, a somersault and the flying kick), and then sweeps. Two plans have slips in their code, described on the Discoveries tab: plan 7 tests the wrong byte to choose between the two sweeps, and plan 8 writes the next plan into the first fighter's slot.

Choosing an attack

A port of $24B1, checked with the answers above. The strip is the attack table for the facing: 80 moves at $26D5 for fighters facing each other, 79 at $2725 for fighters facing the same way, read from the entry for the distance plus a random 0-7 (0-3 from 5th dan, $94). The window the computer can read is outlined. The distance is between the two sprite grids in units of two pixels, positive with the opponent ahead of the computer; outside the range shown the computer walks or turns instead. The bars give what the computer then does. With the fighters facing each other three adjustments apply: the flying kick becomes a walk from 7th dan ($2521), the foot sweep is skipped below 2nd dan ($252B), and the low punch starts with a crouch ($2539). In either facing the back kick and back sweep may turn into a turn, a step back or a backward somersault ($2567, mask $A3). Against a crouching opponent each blow is swapped for a low one ($12D0). Against a block it picks among the four blows that block does not stop ($27A1, $27A5), but only when the fighters face each other.

The ranks

The per-rank tables at $27A9-$27FC, as ai_level_setup ($2593) loads them, with the chosen rank outlined. Each is a mask the computer applies to a random number: for the timers (hold, wait, walk, pause and reaction) a smaller mask means shorter waits; the others narrow its choices. A pause mask of 0 means the computer never stops walking forward. The walking table has 11 entries for 12 levels, so level 11 reads the first byte of the next table. Level 11 is reached only in the attract mode, whose fighters take levels 3-11 at random.

The reaction-delay mask is zero from 4th dan, so from there the computer answers a blow at once. The defence mask shapes its temperament. Novice counter-attacks half the time. 4th dan and 6th dan upwards never counter-attack, and 4th dan blocks seven blows in eight. 7th dan never counter-attacks and starts a plan almost every time; it blocks only the high kick, which has no plan.

In a one-player game the computer's level is its rank: it starts at 0, Novice, and rises by one each time the player clears a rank with two bout wins ($1C2D); a lost bout ends the game. Past 10th dan the rank stays on screen as 10TH DAN while the opponent's level is drawn at random from 7 to 10 ($1C65).