Game logic

In this section, I will describe the mechanics of the game and the logic that has been used for individual parts of simple game logic. The logic are write using Cython.

Map

In GUI are render part of the map from WorldMorClass which documentation are in WoldMor. It is possible to get part of the map which needs a render. This part of the map is always based on the position of the player. The player is in the middle.

All items and players are represented by a 64-bit integer. The decimal code is as follows: GGDBBBHHHVCC. C represents the code of field as player, wall, enemy, etc. The range of code is 0 - 99. Get this from integer is easy using modulo and add is only sum. The V is the code of visibility in the map. This tag is defined for each field. The flag is determined by the view range. There get the value two operations, first, divide by 100 and then modulo 10. For add only multiply by 100. This logic is used for all codes. H is for health. Health has a player and walls. Walls can be destroyed, but give no points. B is the number of bullets. D is the direction of the move, but this is used only for the player as direction. The enemy uses this as the flag for the level (wait time) describe in enemy logic. G is code for the gun.

The whole map is generated by the map generator which is created with a lot of probabilities, which can generated map based on distance from the start position. The map generator is described in the next section.

Map generator

Map generator is based on a lot of constants which determine the probability of the items on the map. All useful constants are described in WoldMor. There are some more constants defined in the begin of the Cython module, but these are important and are not suitable to change them easily. The constants in constants.py can be changed to change the behavior of the generator and the game at its discretion.

The map is created dynamic and it is endless theoretically (based on memory). You need to generate the following items in the map: walls, enemies, bullets, pharmacies. Item are placed if the random value between 0 and 1 is smaller the the counted probability.

At the beginning or after reaching the map edge, each field is generated based on the following probabilities.

Walls:

The formula for calculating the probability of the wall.

\[W_\text{p} = \frac{\text{wall base probability}}{\text{wall divider base}^{abs(\text{walls}-1)}}\]

The probability that the field will be the largest is just when it has only one neighbor, it is an attempt to make a wall and not a clump of walls, and of course, there is very little likelihood of closing circuits or forming blocks of walls. This constants are specific in Cython module.

Guns, bullets and pharmacies:

The formula for calculating the probability of the guns, bullets and pharmacies.

\[B_\text{p} = min(\text{max probability}, \text{multiply} \cdot \frac{1}{\text{distance}^\text{exponent}})\]

This probability goes smaller with distance from start. On the Euclidean distance is more than 200 there are not items almost. The exponent determines the deceleration rate and the multiplication factor as much as I want. All have specified the maximum probability.

Enemies probability:

The formula for calculating the probability of the enemies.

\[E_\text{p} = min(\text{max probability}, \text{enemy start probability} \cdot \frac{\text{distance}}{\text{enemy divider}})\]

This probability goes bigger with distance from start. On the Euclidean distance is more than 200 there are a lot of enemies. Start probability is probability which wants on the near of start. Standard is very small. But the distance divided by some constant increasing the probability to some maximum which can be specific too somehow.

Game simulation

For the game, simulation is in the WorldMor class some methods. There are methods up, left, right, down and shot. These methods set the flag for this action. The move actions are exclusive. Next, there is the method for doing one time moment. The class does move or shoot based on set tag, recalculate visibility range and make AI move.

So for game simulation, the main window catches the key signal and after that set the flags. The time moment does the daemon thread in specific time moments. For example in every 0.1 seconds. The one-time moment methods also return the score and signalize the end of the game.

Enemies

There are several visually different enemies in the game, but they all have the same logic of movement. Their appearance is randomly generated when generating. Their goal is clear, and it’s destroying you. If they see you, you are their primary goal, and if they can shoot (you are in the range of their gun), they burn, otherwise they move in the direction of the player. The view range is critical and is one of the two elements that determine the game level. Level 1 small surveillance of enemies and level 3 have similar supervision to you.

The second part of the difficulty is the speed of the enemy, which is given by the number of steps that are waiting (the number of time segments). At a small level, this value is close to 9, and for a high level, they can move the theme as fast as a player, but with the difference that they can quickly decide.

If the enemy does not see you or has no bullets, then his action is based on calculated probabilities. He may want to pick up a gun, a pharmacy, bullets, go for you (supervised direction), or move randomly. There are some set constants: go_for_player_ai_prob, go_for_gun_ai_prob, go_for_health_ai_prob, go_for_bullets_ai_prob.

The constant go_for_player_ai_prob and go_for_gun_ai_prob are use directly and tested. Next two are computed as follows:

\[ \begin{align}\begin{aligned}\text{HEALTH}_\text{p} = \textbf{go_for_health_ai_prob} \cdot ( 1 - \frac{\text{HEALTH}}{\text{MAX_HEALTH}})\\\text{BULLETS}_\text{p} = \textbf{go_for_bullets_ai_prob} \cdot ( 1 - \frac{\text{BULLETS}}{\text{MAX_BULLETS}})\end{aligned}\end{align} \]

If the enemy has low life, he will try to find the nearest pharmacy in their view range. Similarly to the bullets. If there is not one option, a random number and a number from -1 to 1 are generated randomly from 2/3 to some random motion.