Wireframe - #35 - 2020

(Joyce) #1
wfmag.cc \ 35

Substitute Soccer

Toolbox


cosine functions which work with those angles, as
opposed to degrees and radians.


COUNTING THE COST
When a computer player has the ball, there are
two decisions it has to make each frame – which
direction to run in, and whether to kick the ball.
These decisions are made with the help of the
cost function. Given a position on the pitch
and a team number, it calculates the number
representing how good or bad it would be for
the ball to move to that position – the lower, the
better. The cost value is calculated based on the
distance to our own goal (further away is better),
the proximity of the position to players on the
opposing team, a quadratic equation (don’t
panic too much!) causing the player to favour
the centre of the pitch and their opponents’
goal, and a ‘handicap’ value.
The cost function is called in two places. First,
when a player with the ball is deciding where
to run, cost is called five times, each time being
past a position indicating where the player
would be if they were to move slightly forward in
a particular direction – the five directions being
straight ahead, left or right 45°, and left or right
90°. cost’s optional third parameter, handicap,


is used to slightly discourage the player from
making turns – this ensures that the player
doesn’t exhibit unrealistic behaviour such as
repeatedly turning left and right within the space
of a fraction of a second.
cost is also called when a player is deciding
whether to pass the ball to a teammate. A piece
of code in Ball.update tries to find a suitable
player to pass to, but the pass only goes ahead
if the cost value for the target player’s location
is less than the cost value for the current
player’s location.

I AM VERY
INTELLIGENT
Substitute Soccer’s AI has a
computer-controlled player
deciding their next action each
frame, based on a series of
conditions. The first is whether
anyone currently has the ball.
If so, it must be owned by
either that player, someone on
their team, or someone on the
opposite team. Each scenario
has its own corresponding
behaviour. Alternatively, it might
be that no one has the ball.
This could be because kick-off
is about to take place, in which
case no players are allowed to
move, other than the player who
is about to take the kick-off.
Otherwise, all players currently
considered ‘active’ (i.e. are
within 400 pixels of the ball
on the Y-axis) will attempt to
intercept the ball by looking at its
trajectory and calculating where
to run to have the best chance of
obtaining it.
 The pitch – only part
of it is shown on
screen at one time.

 The ‘game over’ screen shows
the winning team and score.

Free download pdf