The Fighty Engine


This article is part of an ongoing series about profiling Python programs that starts here. You may skip this article if you are only interested in profiling, and not in the game details.

The player character of a typical RPG has a set of attributes which describe her stats and abilities, like strength, speed, luck, dexterity, strength of armour and weapon etc. In the context of fighty, however, we are interested only in attributes that directly influence a fight. These are:

  • Initiative: Used to determine the order in which the fighters can act
  • Attack: A fighter makes an attack roll to determine whether he managed to attack or not, i.e. he fumbled.
  • Defense: If a fighter is attacked, she makes a defense roll to see if she could avert the attack
  • Damage: If an attack has been successful, the defendant suffers damage
  • Hit Points: This is the life energy of a fighter; if it falls below 1, he dies

For our objective to profile a python program, we assume fighty is embedded in a bigger game that somehow calculates these fight-relevant attributes from those that are presented to the players.

All fighters listed in the roster will participate in the next fight.


A fight takes place in an arena, which is a rectangular area, where each fighter occupies a certain location. Only fighters in adjacient locations can be chosen as opponent:

| 1 | 2 | 3 |
| 4 | 5 | 6 |
| 7 | 8 | 9 |

A fighter at location 5 may attack, or be attacked by, fighters at locations 1, 2, 3, 4, 6, 7, 8, 9. A fighter at location 9 may only attack 5, 6, 8; but also can only be attacked by 5, 6, 8. Following this rule, the opponent is chosen randomly. If not all locations of the arena are occupied (e.g. if we have only 8 fighters, location 9 is empty) and that location was picked as opponent, the attack automatically misses.

The size of the arena is calculated automatically in each round so that at least all fighters may get a location. Initially, the fighters from the roster are randomly distributed. But during the course of a fight, they maintain their relative position as dead bodies are removed and the arena shrinks.

Dice Rolls

Each attributes consists of two values, a minimum and a maximum. The actual attribute value is a random number from inside this interval. For example, if a fighter has an initiative attribute of [5, 11], her initiative value in a certain round is randomly picked between 5 and 11 inclusive.


A fight comprises one or more rounds. In each round, all fighters roll their initiative, and in order of this value, they attack, defend and deal damage. The defender’s hit points are reduced by the amount of damage recieved.

At the end of each round, the fallen fighters are removed from the arena, and the arena shrinks to have as few unoccupied locations as possible.

If more than one fighter remains in the arena, a new round starts.