Write AIs to play football
This project is maintained by richard shepherd nick pollard
The order makes no difference. The game-engine waits for both responses before processing them. So there is no advantage to being the first to reply. That said, I’m thinking of timing the request-response, and having a secondary prize for the most time-efficient AI.
Facing the right direction is most useful for kicking accuracy. But it can be good for moving as well. For example, in the BootAndShoot sample, the players don’t make any attempt to face the right direction. So when they need to start moving, they often are facing in a random direction and pay a time cost to turn before moving.
The time cost is proportional to the amount you need to turn. Internally, there is a calculation loop that runs ten times for every 100ms AI update, ie every 10ms of game-time. If you need to turn, you will always pay at least one of these 10ms penalties before you start moving, but you might pay more depending on how far you have to turn. Players turn at 600 degrees/second.
You can’t overshoot, even if moving at full speed.
No. The game-engine will prevent players moving into the goal area, or the goalkeeper moving out of it. There is no penalty for trying to do so, the game will just prevent you from doing it.
No.
Players can only move in the direction they are facing. When you move, you set a desired point on the pitch where you want to end up. If you are not facing in the right direction, the game-engine will first turn you to this direction. This takes a small amount of time. Players turn at 600 degrees / second.
There are no player collisions. Players can run through each other and can occupy the same space.
The ball does not collide with the players. So it can go through them. Players will only interact with the ball is they issue the TAKE_POSSESSION action.
The physics 'engine' in the game runs ten times faster than the AI updates, to give greater precision to ball-handling. In addition to this, when you issue the TAKE_POSSESSION action, your player is on "autopilot" to intercept the ball (as long as you are within 5m of it). This means that you do not need to do manoeuvres that would be smaller than the 100ms precision of the AI updates.
No. You can only kick once.
The game-engine has an algorithm to choose between multiple players who try to take possession (either of a free ball, or when tackling). This is based on the relative skill of the players, and there is a random element as well. For kicking, see below.
Yes.
There is a small amount of documentation in the API reference.
Here is a quick summary of the actions:
MOVE: You set a desired destination (x, y) and a speed (0-100). The player will first turn towards the destination and then move towards it. The player moves at speed/100*playerMaxSpeed. (Note: there was going to be a concept of energy in the game, but this will most likely not be implemented. In the absence of energy, there is very little reason not to always move at speed=100.)
TURN: You set a direction, where 0 degrees is straight up, 90 degrees is facing right. So actions, such as kicking, are more accurate if you are facing the right direction.
TAKE_POSSESSION: This can only be issued if you are within 5m of the ball. It will first move you towards the ball. When you are within 0.5m of it, it will attempt to take possession, including tackling another player if necessary. Whether you are successful depends on the speed of the ball and on the player's abilities (see below).
KICK: You set a destination (x, y) and a speed. Kicking is more accurate if you are facing in the direction you are kicking. Speed is a percentage of the ball's maximum speed which is 30m/s. When passing to a player, you may want to kick at less than full speed, to give them a better chance of taking possession.
All abilities are between 0 (low ability) and 100 (high ability). The abilities are:
kickingAbility: How accurately you kick. When facing in the direction you are kicking, 100 will kick completely accurately, 0 will kick completely randomly. Accuracy drops off the further away from straight you kick, even with 100% ability.
runningAbility: Affects the maximum speed you can run.
ballControlAbility: Taking possession of a free ball is affected by the speed of the ball and the player's ballControlAbility.
tacklingAbility: Tackling is decided by looking at the relative tacklingAbility of the player and the player with the ball. This produces a probability of getting the ball. A random element then decides whether you get it or not, based on this probability.
You can move when you have possession, but you will only move at 40% of your normal running speed.
There is no event raised when possession changes, but you can look at the controllingPlayerNumber of the ball object. Or you can check the hasBall field on the dynamicState of a player.
Player numbers are ints, all other values are floats. Values are rounded to 3dp (ie, 1mm) when passed to the AIs, to keep the JSON a bit smaller than it would otherwise be.
There is some randomness in kicking (see above). But once the ball is moving, there is no further noise in its movement.