Translations/Project X — различия между версиями

Материал из SpeccyWiki
Перейти к: навигация, поиск
(Новая страница: «Konstantin Dronov on AI in Project X, excerpt from Inferno #2 [http://zxpress.ru/article.php?…»)
 
 
Строка 19: Строка 19:
 
3. That's all !!!
 
3. That's all !!!
  
Не правда  ли просто? Но все гениальное
+
Isn't this simple? To program the behaviour of monsters in PROJECT X, I used just 15 commands and one register (one byte of memory!). The monsters are simple there, of course, although even these 15 commands are enough for modelling a very complex behaviour.
просто! Что бы задать поведение монстров
+
в  PROJECT X мне потребовалось всего 15
+
таких  команд и всего один регистр (один
+
байт  памяти  !). Конечно поведение мон-
+
стров там очень простое, но даже на этих
+
15 командах возможно моделирование пове-
+
дения достаточно сложного .
+
  
Вот эти команды :
+
Here are the commands used:
  
00 RANGE - находиться ли игрок в зоне
+
*00 RANGE - check if the player is in sight. Returns 0 (yes) or 1 (no). This command was used in the game to check if the monster is on screen.
видимости. Выдает: 0-да / 1-нет (в игре
+
*01 MOVE - move one step forward.
применялось для проверки монстр в преде-
+
*02 TURN LEFT - turn left by certain angle
лах экрана или нет)
+
*03 TURN RIGHT - turn right
 +
*04 SEARCH - check if the way ahead is blocked. Returns 0 (yes) or 1 (no).
 +
*05 SEARCH LEFT - the same for the way to the left
 +
*06 SEARCH RIGHT - the same for the way to the right
 +
*07 FIRE - shoot (not used in the game)
 +
*08 HALT - tells the interpreter that he must interrupt and return to the main program.
 +
*09 VERIFY L - check if the player is to the left (or else to the right) of the monster. Returns 0 (yes) or 1 (no).
 +
*10 VERIFY F - the same but ahead or behind
 +
*11 TYPE - checks if the player and the monster are on one line that is along the player's movement (?). Returns 0 (ahead) or 1 (behind).
 +
*12 JUMPIF 0 adress - checks the register. If it is 0, jump to adress.
 +
*13 JUMPIF 1 adress - the same, but 1.
 +
*14 JUMP adress - unconditional jump.
  
01 MOVE - двинуться вперед на шаг
+
That's all!!!
  
02 TURN  LEFT  -  повернуть  налево  на
+
An example of a program written using this code:
определенный угол
+
  
03 TURN RIGHT - повернуть направо
+
     the adress
 
+
04 SEARCH  -  проверить есть ли впереди
+
преграда. Выдает : 0-да / 1-нет
+
 
+
05 SEARCH LEFT - то же слева
+
 
+
06 SEARCH RIGHT - то же справа
+
 
+
07 FIRE - стрелять (в игре не использо-
+
валось)
+
 
+
08 HALT - указывает интерпритатору, что
+
он  должен закончить свою работу на этот
+
раз и передать управление основной прог-
+
рамме
+
 
+
09 VERIFY  L  - проверить находиться ли
+
игрок  слева или справа от монстра . Вы-
+
дает : 0-да / 1-нет
+
 
+
10 VERIFY  F  -  то  же, но спереди или
+
сзади
+
 
+
11 TYPE  -  проверяет,  если  игрок  и
+
монстр  на одной линии по ходу движения,
+
где находиться игрок. Выдает : 0-спереди
+
/ 1-сзади
+
 
+
12 JUMPIF 0 adress - проверяет содержи-
+
мое  регистра.  Если он 0, то перейти на
+
адрес adress
+
 
+
13 JUMPIF 1 adress - то же, но для 1
+
 
+
14 JUMP adress - безусловный переход
+
 
+
Все !!!
+
 
+
Для примера программа в этих кодах :
+
 
+
     тот самый adress
+
 
  ┌──────────────────
 
  ┌──────────────────
 
  │
 
  │
Строка 106: Строка 68:
 
  21 JUMP 1
 
  21 JUMP 1
  
Это только  тестовая  программа  и  на
+
This is just a test program practically unusable because it returns once, by HALT at line 20. To work in normal conditions you should use HALT before every JUMP or JUMPIF.
практике  она  не  применима из-за того,
+
что выход из нее совершиться один раз по
+
HALT в строке 20. Для нормальной работы
+
перед  каждым JUMP или JUMPIF нужно пос-
+
тавить HALT .
+
  
Вобщем, подумайте  какие  команды  вам
+
So, think of commands you need and add them to the list. You can even write self-learning monsters, this only needs writing new commands by the monster's program.
понадобятся  и  дополните  список. Можно
+
даже  написать  самообучающихся монстров
+
для этого надо лишь добавить возможность
+
записи  новых  команд  самой  программой
+
монстра.
+

Текущая версия на 15:01, 17 ноября 2014

Konstantin Dronov on AI in Project X, excerpt from Inferno #2 [1]

Some words about AI

Artificial intelligence is an important part of a game, be it a typical action game or nerdy strategy, and its design haven't changed highly since 80's. The cause is that it's very hard to do. For example, make a monster turn a corner, that seems simple. But what's a corner? How to describe it? How to describe an enemy for a monster? Regular way that is called "artificial intelligence" will take too much time to do. You should write an enormous subroutine in which you understand all the actions. I can't even imagine everything needed for this, because humans evolutioned for tens thousands, maybe hundreds thousands years. How you can repeat this in a few days? However, the nature itself suggests the way - from simple to complex. An alternative to artificial intelligence is developed now actively - artificial life (AL). What life, you will ask? Here it is, its approach:

1. Instead of writing a cumbersome routine, we write several little routines, each of them to accomplish just one task. Enumerate them, for example:

  • 0 - NOP, no command
  • 1 - MOVE, move forward
  • 2 - STEP LEFT, one step to the left
  • 3 - STEP RIGHT, one step to the right
  • 4 - TURN LEFT, turn left 90 degrees
  • 5 - TURN RIGHT, turn right 90 degrees

etc.

2. Write a routine, an interpreter, that will interpret codes under a pointer and move the pointer in memory. Interpreting a code is calling a subroutine for that specific code. The routine must contain variables to exchange data between subroutines. This is a programming language, in fact.

3. That's all !!!

Isn't this simple? To program the behaviour of monsters in PROJECT X, I used just 15 commands and one register (one byte of memory!). The monsters are simple there, of course, although even these 15 commands are enough for modelling a very complex behaviour.

Here are the commands used:

  • 00 RANGE - check if the player is in sight. Returns 0 (yes) or 1 (no). This command was used in the game to check if the monster is on screen.
  • 01 MOVE - move one step forward.
  • 02 TURN LEFT - turn left by certain angle
  • 03 TURN RIGHT - turn right
  • 04 SEARCH - check if the way ahead is blocked. Returns 0 (yes) or 1 (no).
  • 05 SEARCH LEFT - the same for the way to the left
  • 06 SEARCH RIGHT - the same for the way to the right
  • 07 FIRE - shoot (not used in the game)
  • 08 HALT - tells the interpreter that he must interrupt and return to the main program.
  • 09 VERIFY L - check if the player is to the left (or else to the right) of the monster. Returns 0 (yes) or 1 (no).
  • 10 VERIFY F - the same but ahead or behind
  • 11 TYPE - checks if the player and the monster are on one line that is along the player's movement (?). Returns 0 (ahead) or 1 (behind).
  • 12 JUMPIF 0 adress - checks the register. If it is 0, jump to adress.
  • 13 JUMPIF 1 adress - the same, but 1.
  • 14 JUMP adress - unconditional jump.

That's all!!!

An example of a program written using this code:

   the adress
┌──────────────────
│
01 SEARCH
02 JUMPIF 1 4
03 TURN LEFT
04 VERIFY L
05 JUMPIF 0 9
06 VERIFY F
07 JUMPIF 0 15
08 JUMP 19
09 TYPE
10 JUMPIF 0 13
11 TURN RIGHT
12 JUMP 19
13 TURN LEFT
14 JUMP 1
15 TYPE
16 JUMPIF 0 19
17 TURN LEFT
18 TURN LEFT
19 MOVE
20 HALT
21 JUMP 1

This is just a test program practically unusable because it returns once, by HALT at line 20. To work in normal conditions you should use HALT before every JUMP or JUMPIF.

So, think of commands you need and add them to the list. You can even write self-learning monsters, this only needs writing new commands by the monster's program.