O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

By the time you’ve finished this chapter you will have the ability to cre
-
ate AI agents capable of playing most team games. Ice hockey, rugby,
cricket, American football, and even capture-the-flag — you name it,
you’ll be able to code an entertaining AI for it.
The Simple Soccer Environment and Rules
The rules of the game are uncomplicated. There are two teams: red and
blue. Each team contains four field players and one goalkeeper. The objec
-
tive of the game is to score as many goals as possible. A goal is scored by
kicking the ball over the opposing team’s goal line.
The sides of a Simple Soccer playing area (called a “pitch”) are walled
in (like ice hockey) so the ball cannot travel outside the playing area, but
simply rebounds off the walls. This means that unlike normal soccer, there
are no corners or throw-ins. Oh, and there’s definitely no offside rule! Fig
-
ure 4.1 shows the setup at the start of a typical game.
The game environment consists of the following items:
n
A soccer pitch
n
Two goals
n
One ball
n
Two teams
n
Eight field players
n
Two goalkeepers
Each item type is encapsulated as an object. You can see how they are all
related to each other by studying the simplified UML class diagram shown
in Figure 4.2.
134 | Chapter 4
The Simple Soccer Environment and Rules
Figure 4.1. Kick-off positions (players are shown at increased scale for clarity)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required