ZX Format #06
29 июля 1997

Programmers - Artificial Intelligence. Continuation of a series of articles about "AI". General basis for finding the way to goal.

<b>Programmers</b> - Artificial Intelligence. Continuation of a series of articles about
Artificial Intelligence

     In computer games

        (Continued)

music by DNK
(C) vortices STAS 1996.
_______________________________


  Recently, while playing "SPACE CRUSADE", I discovered a 
strange detail: one of levels necessary to destroy airborne unit

chaos that marks time in one place
unclear goals, instead of trying to attack a squad player. Such
stupidity I do not understand: being able to use
modern weapons, not to guess
close to the enemy.

   That is the problem is reduced to writing
procedures that would determine the direction in which we must 
take a step that would closer to the desired object (to 
labirinata any difficulty). 

   Suppose we have an array A (100,100)
elements of which correspond to cells
maze: 1-wall, 0-empty, 2-cell to
which need to get (to play SP.CRUSIDE the cells from which we 
can make a shot at the enemy), a maze surrounded by a wall, for 
ease of travel You can only vertically and horizontally.


Input procedure - X, Y - current
   ing coordinates.

   Imprint - X, Y - coordinates

   after the move.

 100 IF A (X, Y) = 2 THEN RETURN
/ 105 IF A (X-1, Y) = 2 THEN LET X = X-1: RETURN
/ 110 IF A (X +1, Y) = 2 THEN LET X = X +1: RETURN
/ 120 IF A (X, Y-1) = 2 THEN LET Y = Y-1: RETURN
/ 130 IF A (X, Y +1) = 2 THEN LET Y = Y +1: RETURN
 140 LET N = 0
 150 FOR X1 = 2 TO 99
 160 FOR Y1 = 2 TO 99
 170 IF A (X1, Y1) <> 0 THEN GO TO 220
9180 IF A (X1-1, Y1) = 2 THEN LET A (X1, Y1) = 2: LET N = N +1
9190 IF A (X1 +1, Y1) = 2 THEN LET A (X1, Y1) = 2: LET N = N +1
9200 IF A (X1, Y1-1) = 2 THEN LET A (X1, Y1) = 2: LET N = N +1
9210 IF A (X1, Y1 +1) = 2 THEN LET A (X1, Y1) = 2: LET N = N +1
 220 NEXT Y1
 230 NEXT X1

   240 IF N = 0 THEN RETURN
 250 GO TO 100

This procedure works as follows:
Line 100 - 130 check the neighboring
by commando cells, and if they are equal to 2
a move is made in their direction,
Line 150 - 230 are responsible for "spreading" of deuces on the 
labyrinth, by value variable N is determined by how many pairs

were added during this cycle, if the twos are not
increased, it means that sprawl deuce at the bottom and get to
desired object paratrooper fail
(Line 240). (A similar procedure
can be done using recursion, but
then it will be slower to work and takes more memory for the 
stack). 

   For the game SP.CRUSADE can write a program displacement 
Chaos Marines: 


  05 LET HOD = 5

  10 to update the screen: UPDATE ARRAY
June 1920 IF A (X, Y) = 2 THEN SHOOT: DEVIATES: RETURN

  30 GO SUB 100

  40 LET HOD = HOD-1

   50 IF HOD> 0 THEN GO TO 10

  60 RETURN


  Of course for dynamic games this way is not suitable, but for 
strategic (After translation to assembler) performance is quite 
enough. 

But it was, so to speak, lyric
digression from the main themes raised in
the last issue of the magazine.

   Thus, we extract the basic building blocks for AI
games such as chess: First, in any
AI programs should be the formula for determining the position 
of force, the verification procedure compliance with the rules 
of the game, a program that iterates through all possible moves 
to the desired number of plies in depth and put the forces of 
all possible positions in an array, a program that provides 
processing of the array and the basis of danyh determining the 
best move. Particular attention should be paid formula for 
determining the position of force, it must be make the most 
accurate and rapid, so as if it will even and fast but not

accurate, it would not make sense to bust
moves to a greater depth (because
error formula will increase each ply), and eventually on the 
basis of such a formula will not be able to make strong AI. 
Preferable to a slow and exact formula, but with little depth

busting.

   Further, one of the most important moments
Made of AI - is the way in which
determined the best move based on the resulting array 
containing the data obtained with the brute positions. There 
may be many ways for each logic game. For example (for a 
starting position in the puzzle game), after iterate vesh 
possible positions for two ply in depth and calculate their 
forces from the using a formula fills the array A (n, n) (to 
reverse n = 64 = 8 * 8) in which the element A (x, y) contains 
a power position; position obtained after the move of "white" in

cell fields marked with x and stroke "black" in the field of 
the cell labeled y (it is clear that to reverse most of the 
elements array will be filled with zeros, because they do not

all possible moves in accordance with regulations). Select the 
"best move" from a given array in several ways (and for 
different ways to "best move" will usually be different).'s 
neskolno such ways:

, 1.Nayti in the array and take the largest number of "best 
move" the first coordinate Eetogo numbers.

2.Nayti in each column, the smallest number
(Zero is not taken into account) and make a "best
progress "number of the column where the smallest
the greatest number.
3. Taken as the "best move" the number of
column whose sum of elements of the greatest.

   As you can see ways to determine the best move you can think 
of quite a lot (for more than two-dimensional array of all even 
more difficult). And for different logic games are better and 
different ways, in zavismosti on the features of this game.

So I can only advise to compile their program a little more 
experimenting with different ways to determine the best course 
and choose the strongest. 

   We write a program of artificial intelligence in general. 
(The computer plays "White", the calculation is carried out at 
a depth of 4 ply) 


  10 DIM A (N, N, N, N); N-maximum number of moves
, 20, FOR A1 = 1 TO N; that can be done from a position
: 21 IF PROGRESS "white" on the cells A1 SOOTV.PRAVILAM NOT THEN

      GOTO 131

  22 SAVES position in the array B1

  23 We go "white" on the cells A1.


  30 FOR A2 = 1 TO N
<31 IF PROGRESS "Black" on the cells of A2 is not 
SOOTV.PRAVILAM THEN 

      GOTO 121

  32 SAVES position in the array B2

  33 We go "Black" on the cells of A2.


  40 FOR A3 = 1 TO N
<41 IF PROGRESS "white" on the cells A3 SOOTV.PRAVILAM THEN

      GOTO 111

  42 SAVES position in the array B3

  43 We go "white" on the cells A1.


  50 FOR A4 = 1 TO N
<51 IF PROGRESS "Black" on the cells A4 SOOTV.PRAVILAM NOT THEN

      GOTO 101

  52 SAVES position in the array B4

  53 We go "Black" on the cells of the A4.


  60 LET A (A1, A2, A3, A4) = POWER POSITIONS

 100 extracts the position SOLID B4
 101 NEXT A4

 110 extracts the position SOLID B3
 111 NEXT A3

 120 extracts the position SOLID B2
 121 NEXT A2

 130 extracts the position SOLID B1
 131 NEXT A1

At the moment we have an array of
A (N, N, N, N), which contains all the forces
possible positions on the depth of 4 ply
from this.

200 programs array handling and determines the best move.


  According to this principle, with some differences, most 
programs are constructed using artificial intelligence, these 
differences are mainly are in various ways to save memory or 
time of calculation, for example, due to incomplete enumeration 
of positions. 

 (To be continued)
_______________________________





Other articles:

Today in the room - the contents of the magazine.

Authors - The authors of the journal ZX-Format No.6

From the authors - the long awaited event finally happened ...

Toys - The last iron (short story on the game 48 irons).

Toys - Many Adventures of Winnie the Pooh. Part Two.

Toys - the game description The Crypt (Castle Master 2).

Toys - description editor Adeventyur - PAW (Part 1).

Toys - description editor Adeventyur - PAW (Part 2).

Toys - description editor Adeventyur - PAW (Part 3).

Toys - description editor Adeventyur - PAW (part 4).

Toys - description editor Adeventyur - PAW (Part 5).

Programmers - Beta Basic: continued talking about BASIC (Part 2).

Programmers - General Sound: Programming Guide.

Programmers - MMD - the driver. Description of the structure of the modem driver for the terminal program MMD.

Programmers - AI on B. Mednonogova. A detailed description of the "wave of the algorithm" trace (automatic calculation of optimal) path, with an example implementation at Basic.

Programmers - Artificial Intelligence. Continuation of a series of articles about "AI". General basis for finding the way to goal.

Programmers - Tr-Dos for programmers. Max Petrov concludes his story about nontraditional methods of work with the disk.

Programmers - sharing experiences: "3-colour". Description of the effect of colors on 8-point ", help to the viewer, and how many words on the conversion of images in format "3-colour".

Programmers - sharing experiences: "3-colour". A few words about converting images in the format of RGB.

Programmers - the exchange of experience: programming Multicolor effects.

IS-DOS - users: how to personalize your system IS-DOS on a specific model of ZX Spectrum-compatible PC and to perform your tasks.

IS-DOS - users: how to copy the system disk IS-DOS and stay with the dead.

IS-DOS - the programmer: a short course - programming in IS-DOS.

IS-DOS - news: new software IS-DOS.

Iron - A short story about the capabilities of the processor Z-180.

Iron - Multiviewer. Description dorabotochki allowing to measure the speed of programs to curb without climbing in the codes - an easy push of a button.

Iron - A new project the firm Peters - "Sprinter". New Spectrum-compatible PC with a new generation of Speccy.

Iron - Opinions about skorpionovskom controller IDE HDD - SMUC.

Iron - SuperSpectrum: one project Spectrum-compatible machines. Its feature is compatible with the PC.

Iron - X-Trade FAQ. Answers to frequently asked questions on the GS and XTR-modem.

Premiere - Flash tracker. Description 4-channel editor of digital music, working with SoundDrive, from the author SoundDrive - Flash Inc.

Premiere - Description of the latest version of the universal terminal program used in SpbZxNet.

Premiere - Mortal Kombat: what awaits you in the full version of the game and some comments to the demo version.

Premiere - XReversy: presentation of a new toy from the popular family of "Solve puzzle - see the picture."

Interview - An interview with one of the most famous spektrumistov - Andrew Larchenko.

It was you - The story "Absolute Power".

It was you - The story "The Road".

It was you - Lord of the teeth: a parody of a popular trilogy ...

Mail - Contact us: an e-mail Alex'a from Nizhny Tagil, exhibited in the last room at the Corner of lamer. "

Mail - Letters from readers: Andrei Yakovlev, Denis Tokarchuk, Alex Garkulim, Alexander Gordeev, Evgenii Shumilov Nitochkin Vadim, Michael Larkin.

Mail - free advertising and announcements.

Miscellaneous - Scarecrow.: Nemo talks about the place of the PC and Spectrum in the modern Russia.

Miscellaneous - Review of Nemo in the book on digital circuitry. For anyone who has ever ever been tempted to turn on the soldering iron and ...

Miscellaneous - Questionnaire: Results of our poll spektrumistov.

Miscellaneous - Competition. A brief account of our contests.

Miscellaneous - The problems of the software market: when zagnetsya Spectrum. All over whether to blame hackers?

Miscellaneous - Outlook software. A brief overview of the forthcoming software: Fast Tracker, Pro Sound Creator, Black Crow.

Miscellaneous - Outlook software. Adventyura From Beyond or outside. "

Miscellaneous - A Memoir of the Peter modem network for ZX Spectrum - SPbZXNet.

Amiga Club - Between Us, by users: a comparison of characteristics of the Amiga 1200 with the IBM PC.

Amiga Club - compare the performance of Amigo and PC. As far as Amiga relevant in today's games?


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:
new com. Edition - A new computer magazine "ZX-Magazine".
Category X - Coming Apocalypse, or is it all the tricks of "enemies of the Spectrum?
B.B.S. News - The work B.B.S. 'ca.
Nove - A list of new software, which appeared in Brest in December.

В этот день...   2 May