Artificial intelligence production in computer games

xiaoxiao2021-03-06  69

Computer games have greatly improved hardware execution efficiency and display resolution, and many computer games that have many impossible or very difficult or very difficult-to-realization have been successfully completed. Although the presentation of computer games is diversified, but the theme of our discussion today, artificial intelligence has almost unpryunated relationships.

In the role playing game, the programmer and the planner need to accurately create a so-called "monster" in the computer, so that the half-orc people are seriously injured and know how to escape, the Master knows how to show the attack .

It is currently able to immediately think of two games with close relationships with artificial intelligence:

One is the so-called war / strategy to simulate game, two is a chess game. The specific gravity of artificial intelligence is different, and there are different in different game types. Some computer games are not marigned with high artificial intelligence. Otherwise no one is buying; some is almost embarrassing to make players can't feel any artificial intelligence.

Guided thinking

The way Ai is most likely, and it is also the main direction of early game Ai development is the rules orientation or called hypothesis orientation. In some simple computer games, programmers can do not difficult to convert rules in the game with settings into a rule, and then write them into computer programs. Let us play a role playing game as an example. Most of the plans to set the so-called computer monsters, the settings are usually the following:

Life attack power defensive force attribute

The last "attribute" is one of the items I like to increase during setting. Through this attribute setting, I can set the monster into "fear of death", or set the soldiers to "deceiving". With the information we have mastered, the outline in the battle system is born:

Rule one

IF (health <10) // is there?

{IF (attribute == greed is afraid of death)

Result = tried to escape

IF (there is any item or spell that restores your life)

Result = Use or to display related items or spells

}

Rule two

IF (can attacked aerodynamic && has enough mana)

{

Result = Show attacks

}

The most basic AI is established by the above series of "if-" rules set. Saying such a method can only establish basic AI is actually not correct. As long as there is sufficient and accurate rules, this way still has a certain level of performance.

The biggest advantage of rules orientation is easy to learn. Without the premise of the theoretical concept of the Olympics, there is still a large number of uses. Therefore, many old players often don't touch the enemy's attack strategy, mobile methods, and so on.

Inference thinking

I believe that friends who have come into contact with computer language or self-study have heard a famous procedure, which is a well-known program. Using a well-word game as a introductory textbook that discusses AI, I personally feel the most appropriate example. Maybe someone still doesn't know how to play in the well. As long as any party, first, first, first, first, first, first line. We can also derive the field here in the previously talked.

If any line of IF has, we have two sons && seasonal, still empty // is it coming to a line?

Result = This space

If any one of the IF has an enemy, two sons && is still empty / / prevents the enemy from making a line

Result = This space

If any one of the IF has, we have a son && seasonal, still empty //

Result = This space

Once I was on a computer book, I also saw some examples introduced in a well-known game. Different, I can't see any rule-oriented shadow. But after careful analysis of the program code, I got a great inspiration. It turns out that AI can be made without so many rules. It is used by the method in the computer AI course: the great ministerial method. I only explain the concept of this law here. Continue to take a well-known game as an example, the computer will take a certain place, followed by a hypothetical manner, of course, must assume that the other party is the best position, otherwise everything is meaningless. In the process of assumed the other party, naturally need to suppress our next step in response, so that it is until the full bureau game. Under the bottom of the program fragment: Bestmove (int P, int * v)

{INT I;

Int lasttie;

Int lastmove;

int SUBV;

/ * First, Check for a TIE * /

IF (ISTIE ()) {

* v = 0;

Return (0);

}

/ * If not a TIE, TRY Each Potential Move * /

FOR (* v = -1, lasttie = lastmove = -1, i = 0; i <9; i )

{

/ * If this isn't a possible, skip it * /

IF (Board [i]! = 0) Continue;

/ * Make the move. * /

Lastmove = i;

Board [i] = p;

/ * DID IT WIN? * /

IF (Haswon (P)) * V = 1;

Else {

/ * If not, Find Out How Good The Other Side Can do * /

Bestmove (-P, & SUBV);

/ * If They can only Lose, this is stock a win. * /

IF (SUBV == - 1) * v = 1;

/ * OR, IF IT'S A TIE, Remember it. * /

Else IF (SUBV == 0) {

* v = 0;

Lasttie = i;

}

}

/ * Take back the move. * /

Board [i] = 0;

/ * If We found a win, returnimmediately

(can't do any better than That * /

IF (* v == 1) Return (i);

/ * If We Didn't Find Any Wins, Return A TIE MOVE. * /

IF (* v == 0) Return (Lasttie);

/ * If there at't Even Any Ties, Return a LOOSIME. * /

Else Return (Lastmove);

}

Some of the foreign forums have held 256 bytes of game design competitions. There are a lot of works, one of which is just a well-known game. The author used more than two hundred lines in the district, and the same work is exactly the same as the above program, and the visible skills are indeed. In addition, I also hope that similar activities can be launched in China. By the way, in such a chance limit, there is almost no other choice in addition to assembly language. .386C

Code segment byte public use6

Assume CS: Code, DS: Code

ORG 100H

Tictac Proc Far

Start:

Push CS

POP DS

MOV AX, 0B800H; Clear Screen MOV ES, AX;

XOR DI, DI;

MOV CX, 7D0H;

MOV AX, 0F20H;

Rep Stosw;

XOR CX, CX;

MOV DL, 5

LOC_1:

Call Printboard

LOC_2:

MOV AH, 8; Waiting button

Int 21h

Movzx BX, Al

SUB BL, 31H; if not 1..9

JC LOC_2;

CMP BL, 8

JA LOC_2

CMP Data_1 [BX], Al

JNE LOC_2

MOV BYTE PTR DATA_1 [BX], 'X'

DEC DL

JZ Short Loc_3

MOV Al, 'o'

Call bestmove

MOV [Si], Al

Call iswin; judgment if it has been victorious

JNC LOC_1

LOC_3:

Call Printboard

MOV AX, 4C00H

Int 21h

Data_1 DB '12'

DATA_2 DB '3456789'

DATA_3 DB 0

Tictac ENDP

Printboard Proc Near

MOV SI, Offset Data_1

MOV DI, 548H

MOV CL, 3

LOCLOOP_4:

Movsb

Add di, 5

Movsb

Add di, 5

Movsb

Add di, 133h

LOOP LOCLOOP_4

Retn

Printboard endp

Iswin proc near

MOV BX, 1

MOV BP, 3

Call Sub_3; Check if the horizontal is completed

Inc BX

Inc BX

Dec BP

Dec BP

Call Sub_3; Check if the longitudinal direction is completed

Call Sub_4; check if the oblique is completed

CLC

Retn

Iswin endp

LOC_5:

STC

Retn

SUB_3 Proc Near

Mov AH, 3

MOV SI, Offset Data_1

LOC_6:

MOV Di, Si

Call Sub_5

Add Si, BP

Dec ah

JNZ LOC_6

Retn

SUB_3 ENDP

SUB_4 Proc Near

MOV DI, OFFSET DATA_1

Inc BX

Call Sub_5

MOV DI, OFFSET DATA_2

Dec BX

Dec BX

Call Sub_5

Retn

SUB_4 ENDP

SUB_5 Proc Near

MOV CL, 3

LOCLOOP_7:

CMP [DI], Al

JNE Short Loc_ret_8

Add di, BX

LOOP LOCLOOP_7

Add SP, 4

JMP Short Loc_5

LOC_RET_8:

Retn

SUB_5 ENDP

Bestmove Proc Near

MOV BX, 31FEH

MOV CL, 9

MOV DI, OFFSET DATA_1

LOCLOOP_9:

CMP [DI], BH; #empty?

JNE Short Loc_12; #no, Skip

MOV [DI], Al

Pusha

Call iswin; #cy: winpopa;

JNC Short Loc_10;

MOV BL, 1

Mov Si, Di

MOV [Di], BH

Retn

LOC_10:

Pusha

XOR Al, 17h; Good! Toggle 'O' / 'x'

Call bestmove

Mov Data_3, BL

POPA

MOV AH, DATA_3

NEG AH

CMP AH, BL

Jle Short Loc_11

MOV BL, AH

Mov Si, Di

LOC_11:

MOV [Di], BH

LOC_12:

Inc BH

INC DI

LOOP LOCLOOP_9

CMP BL, 0FEH

JNE Short Loc_ret_13

XOR BL, BL

LOC_RET_13:

Retn

Bestmove Endp

Code ends

End Start

转载请注明原文地址:https://www.9cbs.com/read-119856.html

New Post(0)