ИСКУСТВЕННЫЙ ИНТЕЛЕКТ /волчьи мысли/ ═══════════════════════════════ (С) WOLF/RAGE (W) SERGEY STURM/LGN --------------------- Про искуственный интелект уже сказано довольно много. Особенно выделяется в этом ZX-FORMAT 5 & 6. Но оба метода предложен- ные там, обладают некоторыми недостатка- ми. Волновая трассировка работает довольно медленно /это признает сам В.Медноногов/. А метод расчета лучшего хода по оценочной формуле годится практически толькоfor lo- gical games such as chess and reversi. But what - the same thing to do if you are writing dynamic a game where you need quick intelligence? Yes several methods... First, let's define: We are not making a thinking character, but a persona nazh, which only seems to be thinking. K for example, if you saw Monstrland Level 4 (and you haven’t seen it), then the characters are there They hang around you, periodically shooting. If you try to approach him, he will dit from direct combat. And if you rush to wall, then only then will he rush to attack. And on top of everything else, they make it quite difficult get off. In short, they create the impression "thinking". And this is achieved quite simple methods. The most necessary thing is to determine board to point. Let's say the coordinates your character xp, lvl. Coordinates to where he has to go: ho, wo. Encoding direction expressed by number: If 4, then go ^ / nowhere. We already do so | /уже здесь. | / 0 1 2 {---3 4 5---} 6 7 8 / | / | / V Алгоритм вычисления направления -------------------------------- 1. р=хр-хо 2. Если р<128, то sx=-1 ; xр-xо>0? sx=#ff 3. Если р>128, тоsx=1 ; хр-хо<0? sx=1 4. Если р=0, то sx=0 ; хр-хо=0? sx=0 5. р=ур-уо 6. Если р<128, то sy=-1 ; yр-yо>0? sy=#ff 7. Если р>128, то sy=1 ; ур-уо<0? sy=1 8. Если р=0, то sy=0 ; ур-уо=0? sy=0 Выборка -------- 9. Если sx=-1, то n=[0,3,6] 10.Если sx=1, то н=[2,5,8] 11.Если sx=0, то n=[1,4,7] 12.Если sy=-1, то р=n1 /первое число из n/ 13.Если sy=0, то р=n2 /второе число из n/ 14.Если sy=1, то р=n3 /третье число из n/ That's all! After working out this algorithm ma in r you have a direction code. By the way- Please note that this algorithm is not optimal. timized. More or less experienced programmer the mist has probably already seen where it is possible to shorten checks, etc. But that's just one thing. Let's say the code is we have boards. But how to do it code move? Elementary! I'm in Monsterland made a table of displacements by coordinates, where the offset number was the direction code nia. It should look something like this: (-1=#FF) We believe that the 1st element is the displacement offset in X, the second element is the offset in y. Now we make a selection from the table. ;C - direction code ; the TAB table is located in a “round” HEX address LD A,С ADD A,A LD Н, ТАВ /ст. байт адреса таблицы/ LD С,A LD A,(HL) INC L LD Н,(HL) LD L,A Теперь у нас в HL смещения относите- льно координат. Делаем так: ХР+L ; УР+Н и это будут наши новые координаты. Можно сделать еще проще и без таблицы. Посмотри- те вверх. Ведь мы, по-сути, уже вычисляли смещения т.е. SX и SY. Достаточно там их сохранить и использовать здесь. Но так де- лать я вам не советую, иначе потом могут появиться лишние сложности. ARTIFICIAL INTELLIGENCE (PART II) So, we have learned to choose a direction tion and make a move in this direction. As you understand, this is clearly not enough for writing really strong in- llekta. We need a tool that allows which controls the direction of travel. Such there is a tool. This is the mechanism that carries the name is "finite state machine". Despite ease of implementation, it allows you to get pretty good results. So, what is a finite state machine? This is a set of states, i.e. actions that things your object can do. Let's say you have decided what the character can go to to the player. If he is heavily armed, he runs away from him. If the distance is not too great - Shoe, then he unleashes a hurricane on the player fire. That's all for now. So we have states: 1. Go to the player 2. Run away from him 3. Shoot the player In the object description we create a cos byte storage in which the current state is stored tion of the object at the moment. Next, create we define the rules for transition from one state to other. THOSE. Current state 1. Rules: If the player is armed, then go to the co- standing 2 If the player is close, then go into the state 3 Current state 2. If the player is far away, then go to the state 1 Current state 3. If the player is out of shot range, go to state 1 In short, in assembly language this is writing is easier than words. For each suck- When you write a processing program and you- take them depending on the status byte ny. Each such program must include transition rules, otherwise the character will never will not come out of this state. What we already have is enough for up to loosely “smart” intelligence. What I'm talking about talking further is considered aerobatics in programming intelligence. I'll go- talk about emotions. Imagine that the choice of state is not strictly controlled established rules of transition, and emotions, action acting on the principles of implicit logic. That is, co- the “retreat” state is caused by a combination tion of two emotions: “panic” and “fear”. Feel- "hunger" forces you to look for food/food may well be the main character or same object/. Emotion "caution" indicates that one must move carefully, using shelters, etc. This is really cool! You can come up with a bunch of different ones emotions and assign them different priorities. But just don't overdo it. Otherwise the movement your subject's performances will resemble a dance crazy... So I told you about my thoughts in the field of high-speed I.I. I didn't purposely I didn’t drive a single program, but showed only the methodology. All implementation methods you develop it yourself, if, of course, you want to those After all, my story is very superficial and You'll have to figure out a lot of things yourself. But in That's the fun of writing games. Usually, just a small amount is enough push, sometimes one word, to be born IDEA...------------------------------------------
Share your thoughts about the article