Game Programming - Class Three
Notes on AI
AI - Some definitions
- Intelligence exhibited by an artificial (non-natural, man-made) entity
- An algorithm or set of algorithms that can make decisions in a logical way.
- The branch of computer science dealing with the reproduction or mimicking of human-level thought in computers
- The study and design of intelligent agents i.e systems that perceive their environment and take actions which maximize the chances of success
AI for game characters
- Usually involves sensing, reasoning and acting (and in some cases communicating)
- Such factors should be in levels similar to the player's (no all-knowing, super-mighty gods)
- Can be partitioned in different roles or moods, that can change for the same player
- Main goal - make it look human-like, believable: powerful, yet flawed.
AI for game characters
Some flaw examples:
- Sensing may have limitations such as occlusion, low range, uncertainty
- Reasoning may have errors e.g inaccurate calculations
- Communicating may suffer from missing or garbled messages
- Acting may be limited/influenced by factors such as low energy, injuries, etc.
Regular soccer
- Sensing: A player can see the ball and the players around him in a relatively close range in the direction he is facing
- Reasoning: Think of a series of rules to guide the reasoning
- “If my team does not have the ball and I am close to it, I should get it”
- “If I have the ball and a clear shot for the goal, kick”
- “If I have the ball, but I do not have a clear shot, I should pass to another player in better conditions”
- …
- Acting: Kick the ball. May be limited by the running speed and direction, the energy/fatigue, etc.
- More advanced: different roles to different players, inter-player communication, etc.
Table soccer
The AI player is not on the field, but controlling the knobs
- Sensing: It can see the whole field and the ball
- Reasoning:
- “If I don't have the ball, I should defend”
- “If I have the ball and a clear shot to the goal, kick”
- “If I have the ball, but not a clear shot, pass the ball to a player in better position”
- …
- Acting: Rotating the knobs is limited e.g. by the time to move hands from one knob to another.
Coding suggestions
- Wrap AI in an UpdateAI method in the relevant component(s), that is called from the Update method
- Sensing requires knowledge of the whole world and the generation of an (altered) subset of it.
- The Game class should help in providing this to specific components
- Avoid making tightly-coupled components
- Reasoning should take into account if the character is already performing an action. Don't jump between actions
- Actions may take some time. Make actions smooth whenever possible, even when you have to interrupt them.
Project suggestions
- Be aware of the whole
- Decompose problems
- Think of alternative solutions of different complexity
- Prioritize and select what to implement and in which order
- Set milestones