▀██▀ ▀██▀ ▐▌ ▀██▀█▄ ▄█▀▄▄ ▐▌ ▀█▄ ▄█▀ ███▀▀█
▐▓ ▓▌ ██ ▓█ █ ▐▓ ▀ ██ ▓█▓█▓ ▐▓▌
▒ ▒ ░▌▐░ ▒█ ▓ ▒░ ▄▄▄ ░▌▐░ ▒▐▒▌▒ ▐▒▀▀
░ ░ ░ ▒▓█▒ ░█▄█▀ █ █ ▒▓█▒ ░ ░ ░ ░
▒ ▒ ▒ ▐▓▌▐▓▌ ▒█ █▌ ▒░ ██ ▐▓▌▐▓▌ ▒ ▒ ▐▒ a$h
▐▓▐▓▌▓▌ ▐█ █▌ ▓█ ▐█ ▓▒░▒▓█ ▐█ █▌ ▐▓▌ ▐▓▌ ▐▓▌
▄███▀███▄ ██▌▐██ ▄██ ▐█ ▐▓▒▓▀█ ██▌▐██ ███ ███ ███▄▄█▄
▀ ▀ ▀ ▀ ▀ ▓ ▀▀▀ █ ▀ ▀ ▀ ▀ ▀
(C) Sergei Bobrovsky
WAR GAMES - WARGAMES
Today we will look at programming techniques quite
popular genre of war games all over the world. Of course, many of
they have very significant algorithmic differences, but
most are quite similar. Let's remember the legendary Lords of War
(~WarLords~), or the recently released arcade-strategy
option ~Wing Commander -~ ~Armada~, rich
technical and tactical characteristics of combat starships ~When
Two Worlds War~ or the space version of "Civilization" ~Master of
Orion~, somewhat similar to ~SimCity~ and ~Warlords~ ~UFO~ program
and multiplayer ~VGA Planets~ - they all have one thing in common
gaming ideology. Yes, this is no wonder, because wargames have their own
Our parents play board games that we all know from childhood. And
Today, the board game business around the world is very
profitable, onlynow new hits if they are successful
are also implemented on computers. Thus, many well-known computer
the programs are versions of board games. This is ~Harpoon~ Larry
Bond and Tom Clancy, ~Second Front~ Harry Grigsby and many
others.
Unfortunately, military computer games are not ranked first
(and even second) places among computer games that bring
maximum profit. Yes, here, as in the puzzle genre or in
traditional games, you have to think a lot, which is essential
affects demand. No wonder, “as one of the heroes said
V. Suvorova, any military action is much more complex in its own way
strategic design of any game invented by mankind, in
including chess" (magazine "CD-ROM games"). Therefore, firms
you have to resort to various tricks such as three-dimensional design,
original script and complicating the plot with arcade inserts,
but sometimes the pure classic line of board games brings out
computer program into relative leaders, as was the case with
~WarLords II~.
So, first we formulate the main components of the algorithm
war games, having previously agreed on terminology.
Let's call a single figure a Combat Unit (CU), be it
infantryman, dragon, starship or missile cruiser. Each of the BU
has a number of technical and tactical characteristics, such as speed
travel across varioustypes of soil, probability of damage
various types of enemy units, etc. Company code groups may (or may not)
can) unite into a Combat Squad (CD), characterized by
the maximum permissible number of BU. The BOs themselves are capable
unite with each other subject to restrictions on the number
BE. A BC can contain only one BU, so in the game
There will be no BU, but only BO.
The game map is a rectangle of size M x N conventional units.
Each cell can contain no more than one CP of any
sides. The value of each cell describes the soil in a given
point of the playing space. For example, 0 - normal soil, 1 -
country road, 2 - highway, 3 - mountains, 4 - sand, etc. How
already mentioned, the card does not necessarily have to be
rectangular, its cells can be hexagonal, and it itself
can be constructed in graph form, as in ~Armada~ or ~Master
of Orion~. For clarity, we will choose the ~WarLords~ version.
Let's assume the Number of Parties (players) is greater than or equal to 2.
Initially, the map contains a certain amount
CITIES (of course, in a real game these could be planets or
naval bases), most of which are neutral, that is, not
belong to neither party. Each of the cities has
such characteristics as Income per game cycle and
Current productiondescribing what is currently being produced in
BU city and the time remaining until its “publication”.
We also allow the possibility of participating in the Transport game
Means capable of moving biological weapons through certain types of soils
(let's say by water). Vehicles are characterized by their
Load capacity and speed of movement.
And, of course, each of the playing sides has some
stock of Credits - funds necessary for
produced by BE.
Now let's describe the main elements of the gaming algorithm.
Initially, a game Map is created. For more
For realism, it is advisable to create it not by chance, but by hand
for greater consistency with authenticity. Placed on it
Cities, initially neutral, and in accordance with
the number of players in one city, apparently in different
ends of the card are declared to belong to the corresponding
side. Initially, the number of Credits for each party
is taken equal to zero. Then the game itself begins.
The side whose turn it is to move gives an order to everyone (or not
each) to his own BO either to move or to attack an enemy
BO, or to attack the City. Some of the Cities belonging to
this party may be ordered to produce
a certain company code, of course, subject to the availability of Credits. Calculatedunits destroyed, new units produced and the game continues,
usually until the complete destruction of all parties except one
(as in “Highlander” - only one of the immortals will remain).
Most war games fit this pattern. Remove
cities - and you will get a model of local combat, as in skirmishes
XCom squad with aliens in "UFO"; replace cities with planets
- get "Master of Orion" or "Armada". For more
dynamism, some games introduce imitation of development into the plot,
when new, more powerful types of weapons become available
not immediately, but as the player’s side “matures”. B
in the general description given above, this is easily achieved by controlling
beyond the level of Credits, which is very strongly correlated with
the size of the empire built. New types of weapons can
be very expensive, and once the player has accumulated enough
number of Credits, which is impossible without active expansion and
capturing new cities that generate profit, a message is displayed
about the player reaching a new technological level, and to the list
types of weapons available for production include a new
view Diplomatic contacts are also easily included in this scheme,
when some of the parties agree not to attack each other
friend.
A certain problem is presented by computer
modeling the behavior of the parties,for which it is not a person who plays, but
program. So far, despite the loud statements of many companies
about “unique artificial intelligence algorithms”, serious
scientific developments are practically not used here, and
the behavior of simulated BOs upon close examination is very
It's kind of stupid. They act quite similar to the Terminator, which,
despite outwardly identical appearance and behavior to humans,
was guided by a primitive program for searching for the desired object with
using a small list of standard features. So in
games, outwardly complex behavior inside turns out to be a simple mixture
various primitive alternatives, this is a kind of
Academician Kolmogorov’s statement “complex is like
random" on the contrary. Basically all war games are based on
sets of fairly simple rules similar to those that
used by the middle class player. The problem is that it usually doesn't
It is possible to precisely formulate these rules and a number of
reservations, reservations to reservations, etc. The difficulty of the game
higher levels do not depend on any new algorithms
imitation of behavior, but from a more or less obvious handicap for
computer armies, such as a high initial supply of Credits,
more favorable location of cities, higher probabilities
winning fights, etc. In general, the topic of artificialintelligence and its use in computer games is very
is interesting, and we will definitely touch on it in upcoming issues.
Now let's move on to a detailed description of the military algorithm
computer games. Let's start with data structures.
The map is an array of N x M cells. On the screen may
displayed either as a whole or as a separate part. Every cell
has a fixed value corresponding to the soil type.
Combat-Unit type is a structure with the following fields:
- weapon type from 1 to MAX_NUMBER_VOOR;
- current X and Y coordinates.
In the array of performance characteristics (technical and tactical characteristics) from 1 to
MAX_NUMBER_VOOR performance characteristics are stored for each type of weapon. B
they include:
- speed of movement on each type of soil in
conventional units (distance of movement in squares, according to
horizontal and vertical and maybe diagonal) or 0 if
the ground is impassable;
- probability of destruction of each type of weapon in
fight as a percentage in the form of a table MAX_NUMBER_BOOR x
MAX_NUMBER_BOOR, where the (i,j)th element corresponds to the probability
lesions of the jth type of the i-th BE;
- production cost.
In addition, there is a table of size (MAX_NUMBER_BOOR x
MAX_PROTECTION_LEVEL), containing the probabilities of capture by the i-th type
weapons city with the jth degree of protection.
Type Combat-Squad - array of structures(maximum quantity
- MAX_NUMBER_TREAMS >= 1) from BU. If MAX_NUMBER OF TROODS
takes the value 1, this means that BUs cannot
unite into teams. The Combat-Team type also has a field
"current number of business units" >= 1 and the coordinates of the end point on
map to which you need to move, or a moving target -
for example, the number of the pursued enemy combat unit from the ARMY array. BE
within the BO should be ordered according to the principle “from weakest to
strongest" so that the weakest BUs enter the fray first.
Cities - an array of 'Number_Cities' structures, each of
which contains the following fields:
- coordinates on the map X and Y, - belonging to side i >=1
or 0 in case of neutrality of the city, - protection level from 1 to
MAX_PROTECTION_LEVEL, - type of weapon produced T >= 1 or 0,
if nothing is produced, - the number of game cycles,
which remained until the construction of the T-type produced
weapons, - the amount of income per cycle.
Dynamic array of ARMY from (Number_of Troops,
variable value) of BO type structures describes all BOs,
currently existing in the game. It is necessary for
correct screen rendering and for some internal
calculations.
1. Initialization. Load the Map, initialize
list of Cities, checkneutral and belonging to one or the other
on the other side, in the ARMY enter the initial CP of each side
(usually one for each player).
2. Choose the next side whose turn it is to move. For her:
- increase Credits depending on the number of cities,
belonging to a given player and the income of each of these cities;
- check the list of Cities, if in any of them
BU was built, then release it to the public in or near the City,
if possible, attach to existing nearby BOs, with
the need to add a new BO to the ARMY list;
- start, if desired and have the means, the construction of a business unit in
different Cities of the player, subtract the cost of BU from Credits;
- give orders to each (or not each) player’s CP on
movement, and make this movement. If in the end
point has its own BO, then merge them;
- give orders to certain BOs to attack some
Cities. In this case, the attack of the City occurs as follows:
- if there are BOs in the city, then first fight with
each of the city's BOs (this process is described below). When everything is BO
enemy destroyed, move on to the next point, otherwise (our
BO destroyed) delete BO from the ARMY list;
- in a cycle for each BU of the attacking BO (from the minimum
type):
- take from the table the probability of capturing the city's BU fromcurrent level of protection, using a random number sensor
determine the result;
- either the city is captured and the cycle ends, or
The BE dies, the BO shrinks, and the cycle continues. If all BE from
The BO was destroyed, then the city remained impregnable, and the BO died. When
In this case, he must be deleted from the ARMY;
- if the city is captured, then make it belong to
current side;
- give orders to some BOs to attack enemy BOs.
In this case, the attack of the enemy BO occurs like this:
- in a cycle for each BU of the attacking BO: in a cycle for each
BE of the attacked BO: take the probability of destruction from the table
attacking CU attacked CU in accordance with their types, with
using a random number sensor to determine the result - dies
either our BC or the enemy's CU corresponding to the BC
shrinks and the cycle continues. If all BU are from our BO
destroyed, then the enemy’s BO remained intact, and our BO died. When
In this case, he must be deleted from the ARMY.
Accordingly, if all the enemy units are destroyed first
BO, then we won the battle, and is deleted from the ARMY
Enemy BE.
3. End of game check. If all Cities of some
parties are destroyed (this is achieved by scanning the list of Cities
in search of at least one City belonging tothe one under consideration
side), and he has no more units (similar check
ARMY list), then the side is considered lost. If in game
There is only one player left, he is declared the winner. Otherwise
there is a return to step 2.
* * *
This is the algorithm of a typical war game. It's easy if you want
can be expanded and create a good commercial game.
The only thing we haven't touched on yet is the intellectual
behavior of computer-controlled parties, in particular BOs.
Let us briefly consider four possible options for their behavior (not
quite intellectual in the full sense of the word, but
more or less satisfactorily imitating the behavior of stupid people
sergeants). All the above methods work either until they are
execution, or until the destruction of the BO itself or its target.
1. "Hit everything that moves." The nearest BO is determined
enemy, is selected as a target and pursued until either
he or the pursuing BO himself will not die due to attacks from other BOs.
By itself, this tactic is not capable of bringing real victory in
game, but can cause a lot of problems for other parties. Doesn't have
it makes no sense to use it only for one of the sides, since without
After capturing cities, it will be impossible to build new BUs.
2. "Capture enemy cities." The nearest one is determined
city owned byany side of the enemy, and
chosen for the target of the attack. This method is designed to combat
enemies somewhere in the middle of the game.
3. "Seize free cities." The nearest one is determined
a city that does not belong to either party and is chosen for
attack targets. It is advisable to use this method at the beginning of the game to
to capture as many cities as possible as quickly as possible and obtain
maximum profit for the construction of powerful business units, which
decide, in principle, the outcome of war games.
4. "Attack passers-by." While moving towards the target, the BO can
meet enemy BOs on your way. They usually pass by
but sometimes you can attack them, especially if they knowingly
weaker. Depending on the character of the party, the probability of attack
accidentally passing by the enemy's CP can fluctuate in the most
within wide limits - from “do not waste your energy in vain, never attack”,
which is useful in the debut of the game when capturing new cities before
give no one a pass" in the middlegame, when the main emphasis
usually done to destroy enemy forces.
Note: in the concept of "nearest object (Squad, City)"
it is most correct to include not just “closest”, but “closest
from those not chosen by other BOs of their side."
When choosing a goal, it is advisable to take into account its commensurability with
capabilities of your own BO. If the enemy City has
high degree of protection andis guarded by a strong BO, and our BO
contains only one low-rank BU, then obviously it does not have
there is no point in choosing this City as a target, dooming yourself in advance
to defeat.
The problem is very important
algorithmization of decisions about what to build and where to build. Here
The following options are possible:
1. Increase the City's defense. This makes sense for key
Cities located in the center of the map, which allows
BU produced in it quickly get to any point in the game
fields.
2. Save money to build powerful types of weapons.
Suitable for the middle of the game, when the spheres of influence have already been determined,
and stronger forces are needed to overcome the enemy
resistance.
3. Immediately build affordable minimal BUs
levels and quickly send them to capture no one's or someone else's
unguarded cities with weak protection. A useful method in the beginning
games.
Of course, the most valuable from a strategic point of view
are the central cities, but behind them it always turns around
serious struggle, so do not neglect the outlying
cities that can provide constant income. Overall
the distribution of choice probabilities rests entirely with
programmer, but, as practice shows, it does not require too much
serious balancing, even taken from generalconsiderations
values provide outwardly quite "intelligent"
behavior."
Programming complexity rating - 6-7 out of 10, basic
the problem here is control, display and management
a large number (up to several hundred) dynamic objects
and their correct relationship.
Share your thoughts about the article