AI Interface

Started by
4 comments, last by Cacks 9 years, 3 months ago
Hi,

I have basically a player, network and ai class which make inputs to the game.

- The player class basically translates (g)ui input into usable commands

Now AIs are simulating human players but I wonder how I should possibly implement the ai into the code?
- Should I make the AI use the player UI to simulate player behaviour or should the AI use direct commands but simulate as if it would be limited to the same UI restrictions as the player?

I guess the first attempt using the UI would result in a lot of computations as I had to calculate first what to do and how I achieve it by using the player UI, however I would get an AI behavour like an actual player. For example the UI limits the player not be able to shoot while running, the AI would be limited to the same.

On the other hand just calculating directly what to do and simulating then the limits by the player ui might be way more straight forward but maybe result in errors as the player for example can't turn the hero in a certain situation while the ai behaviour was never adjusted to simulate the same behaviour which might led then to the ai cheating and frustration of the players.

So, what do you think?
Advertisement

For most games, the AI never has unfair control over its unit. The unit accepts the same inputs through the same interface, whether those inputs come from an AI controller or a human controller.

“But the math is hard…”, is never a good excuse to a player. You do the extra math to figure out how to work the input interface to get the result you desire.

There are other times when it simply doesn’t matter.

If your goal is simply to move from [0,0] to [1,2], the player isn’t going to be offended if the computer moves in a line straighter than the best the player could achieve, and if the player has to wait for the AI to move then the player will definitely prefer the AI not to screw around moving “human-like”.

You need to decide based on the game and the situation within the game.

L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Now AIs are simulating human players but I wonder how I should possibly implement the ai into the code?
- Should I make the AI use the player UI to simulate player behaviour or should the AI use direct commands but simulate as if it would be limited to the same UI restrictions as the player?

The unit (regardless of PC or NPC) should be controlled by an API on top of the unit's state. The interface allows for triggering actions and influencing variables like desired movement speed. This is in total what defines what the unit is able to do and how it is controlled. The player gets a player controller that translates (G)UI input into invocations of the unit control. The AI (how ever it is implemented) also invokes the unit control interface in the end. This way both the player as well as an AI is able to request for actions to be performed by the respective unit.

One advantage of the above approach is the clear distinction between layers of functionality. Regardless of the unit, if you have a controller that is able to support all actions provides by the unit, then it can be used to control it. Further, the underlying system like locomotion, animation, and physics are independent on how exactly the unit is controlled. Benefitting side effects: Want to take over control of another character, e.g. to check for its animation clips correctness during development? No problem (if you have a suitable controller, of course). Want to make the UI for the PC configurable? The unit's API tells you what is possible. Want to try out another AI method? You just need to go down to the level of actions (which belongs to AI anyway) but no further.

Notice that with the above the AI does not suffer from "the same UI restrictions as the player". Otherwise it would make no sense, IMHO. The (G)UI is what is named the interface for the human to control the machine. It is one of your tasks to implement a (G)UI and controller in the best foreseeable way to feed the unit's API. On the other hand, the unit's abilities are provided in a defined and consistent way and are the same for the player as well as for the AI (in the margins of a given game mechanics). The restrictions being inherent there are the same for players as well as for AI.


I guess the first attempt using the UI would result in a lot of computations as I had to calculate first what to do and how I achieve it by using the player UI, however I would get an AI behavour like an actual player. For example the UI limits the player not be able to shoot while running, the AI would be limited to the same.

On the other hand just calculating directly what to do and simulating then the limits by the player ui might be way more straight forward but maybe result in errors as the player for example can't turn the hero in a certain situation while the ai behaviour was never adjusted to simulate the same behaviour which might led then to the ai cheating and frustration of the players.

things like:

"can't shoot while running"

"can't turn under certain conditions"

are the RULES of the game. folks often loose sight of the fact that we're making games - and games of all kinds: computer, tabletop, card, etc - have things like rules and objectives / goals / victory conditions.

right now, you enforce the rules in the UI. you'll need to do the same in the AI. and no, you don't want to send the AI input thru the UI interface. the AI should decide what to do -WITHIN THE RULES OF THE GAME - then do it. UI is not used. its just another place you must enforce the rules of the game. this of course leads to the possible creation of some sort of generic move_is_legal() checker used by both input and AI - IE code sharing.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Okay that is 2vs1

The reason this question came up was because of steering a car by an AI or a player.

While the player either presses left or right to turn its car left or right. The UI translates those button presses then in appropriate data like degrees to determine the turn rate per calculation around the x axis.

An AI now hasn't the capabilities of examining the situation visually as fast as we do. At least as long as standard gaming computers doesn't come with ANN-Processing Units.
So an AI has to determine the situation based on data it gets for example from path finding algorithms to get the car from A to B.
- Using the UI would mean the AI uses left() and right() as the player does.
That would of course head to calculating if the car should turn left or right or not at all every turn
- On the other hand this could also be accomplished by just using the data already available and just turn the car in the wanted direction and move forward.

The last case maybe leads to programming errors
i.e. the AI just turns its car by 180° immeadiatly because of an unexpected behaviour or data.

Long story short: AI and player might behavebdifferently because of UI limitations.

Would it be best for the AI to fire the same Events as the User input would generate?

If so what would these Events encapsulate? The Forces applied to the characters?

Cheers

Reject the basic asumption of civialisation especially the importance of material possessions

This topic is closed to new replies.

Advertisement