• Advertisement
Sign in to follow this  

Soccer AI

This topic is 1245 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,
 
I want to make a retro-ish soccer game. I want to keep it as simple as possible. I thought about basing it on 'Exciting Soccer' (video) or 'Nintendo World Cup' (video).
 
The only problem is making the AI. The ideal scenerio would be that I can first make the game AI only (so it basically plays itself) and later add an option for the user to take control of one player.
 
I'm not aiming for a super intelligent AI, but rather for a 'kind of interesting to watch' AI. 
 
I am aware of the book 'Programming AI by Example' wich has a whole chapter on this topic. And I don't own the book, but I have seen videos of the result and I'm not really impressed. If you look at this video you might understand what I mean. It seems like only the players closest to the ball are doing anything. Also note what players 4 and 7 are doing at 0:14. 

 

I find the AI of Exciting Soccer way more interesting, although it's actually very stupid. I just like how all the players are moving along with the ball and the game.

 

So my question is: Does anybody have any advice on how to make this? How do I make a fun-to-watch game of (seven a side) soccer where all players in the team seem to be playing together?

 

Many thanks!

 

Freek

Share this post


Link to post
Share on other sites
Advertisement

If you've never implemented 'boids'/'flocking' before, I would start there. This is just a simple combination of 3 simple behavioral rules, from which the group behavior of a flock or birds emerges. If you add a rule that says "move toward the ball" it will probably produce 8yr old soccer players laugh.png

From the basics of flocking, you can continue to add more behaviors, and use a priority system so some override others.
e.g. One behavior might say "if you are close to an opposition player, try to stand between him and the ball", but another behavior might say "If a team mate has said they are passing to you, run in a direction sub that you will intercept the ball". You would want the latter behavior to override the first -- once you receive a message saying "I'm passing to you", that second behavior should kick in, and it should be so high priority that the player no longer attempts to block opposing player, he only runs into position to receive the pass.

From enough simple behaviors and messages between players, some decent soccer play could emerge.


Then, as a completely different task, I would make an AI for the team itself (the coach/manager if you like). This would contain a database of plays/formations/positions - where the players should be in different situations. A soccer fan/expert would create this database from their knowledge of the game. You might have to make a "formation editor" tool so that you can create this database of knowledge.
Then periodically during the match (once a second, or whenever an event occurs like a change of possession), the "team AI" looks at the current position of every player plus the ball and picks an appropriate formation / position for each player.

The player AI then will have a behavior telling it to try and go to the position that the team AI wants it to be in, as well as fulfil all it's other behaviors, such as following the ball, staying onside, moving toward the goal, etc. The priority of each behaviour can change dynamically depending on what's going on. Blocking a player is low priority if no one is near you, but gets higher if someone is right next to you. Moving to your position is low priority if you're already there, or within 1m of it, but becomes a higher priority if you're 50m away from where the 'team AI' wants you to be. 

Edited by Hodgman

Share this post


Link to post
Share on other sites

I like Hodgman's answer, but I also feel like there should be a level somewhere in the middle regarding clear paths. If a player doesn't have a good shot at goal, I would suggest keeping an eye on how many team members they could kick it to, and how many opposition members are nearby. That way they can make a decent judgement of when to pass the ball.

 

At the higher end I would suggest individual team member preferences and abilities, so they have some flavour. So some of them are offense/defense oriented, some focus on assists, some do long kicks, etc.

Share this post


Link to post
Share on other sites

Thanks for your reply!

 

I have heard about flocking before, but never thought that it could be usefull for something like this. I will definately have a look at it.

 

The formation database system would be the most complicated part by far, since the players should find a balance between keeping to their formation, and wandering off to mark an opponent, or to get to the ball or wathever. (And of course to keep in more interesting)

 

Passing is indeed also a problem. I think I'm going to do that by looping through all teammates and giving each of them a 'score' for how good it is to pass the ball to them. Then pass to the one with the highest score. I was also thinking about using this system for positioning the players in some ocasions.

 

Player spesific skills and characteristics is something for later. I first want to focus on making some identical players play a game of soccer, then I'll make different players/teams.

Share this post


Link to post
Share on other sites

I think that optimal play (for some metric of optimal) is a good start. But later down the track remember to allow sub-optimal choices, e.g. pass to the second best option, because optimal play is predictable play.

Share this post


Link to post
Share on other sites

You may want to search for the term robocup, it's a tournament that's held, i think every year, that pits different AI soccer teams against each other.  Mostly done by universities.  You might look at some example AIs that you like and use similar strategies.

Share this post


Link to post
Share on other sites

Thank you.

 

I have been observing many different soccer AI's, including RoboCup. Although I've noticed that RoboCup AI's are way more complex than most (retro) game AI's. For what I'm planning to do, I'd like to keep it as simple as possible.

 

The system I've used in my first prototype is the one I told about earlier. Only a few players on the field are 'active': The ones from each team that are closest to the ball, and a player that is about to receive a pass. For the rest I loop through many positions on the field placed in a grid, and apply points to them based on many different factors.

 

For example some of these factors are:

 - Can I receive a pass from the player with the ball from this position

 - Is this position close to my home position (So that not all players will go to the same position)

 - Can I shoot on goal from here?

 - Are there no opponents to close to this position?

 - Isn't there a teammate already at this position?

 

These are all for the team that has the ball, the defending team of couse has other factors, wich I still need to work on a bit more.

 

A similair strategy is also used to find the best player to pass to.

 

I like how it looks so far, but it still needs a lot of tweaking. I've seen players pass back to the keeper when they could also have shot at goal for example. 

 

The formation database system Hodgman talked about (and wich apparantly is also used in FIFA and PES) would probably be better, but it will be much more complicated and I'd seriously have so study soccer tactics. Also, I like how chaotic my current system is. :)

 

Thanks again, and more tips and suggestions are welcome!

Share this post


Link to post
Share on other sites

I'm always impressed with the behaviors I get when implementing any sort of flocking.  While I've never played soccer on a field or on a game, I have created some killer squad-based movement for a combat based game by combining small flocks into a large flock.  I'm sure this idea can be tweaked for the various duties of footballers (I imagine they are defensive and offensive players and whatnot).

 

I created a "base" flock of five agents -- four grunts and a leader.  The grunts flock (averaged direction and speed, tight cohesion) based on the leader's movement.  There are several of these groups with all of the leaders being a separate "flock" that is moving toward a military objective with different cohesion rules.

 

For the player, this created a really aggressively moving group of soldiers advancing on a position.  How you can make this work to emulate soccer, I'm not sure. 

 

Also (this has nothing to do with the OP), since when did Americans start caring about soccer?  240 years of no interest in the World Cup came to a crashing halt this summer.  Everywhere I went had it on the TV.  What gives? 

Share this post


Link to post
Share on other sites

i've been working on a soccer too, this video looks like it might have some good 1988-era tips:

 

http://www.gdcvault.com/play/1019341/Classic-Game-Postmortem-Kick

 

likewise, i've gotten a good bit out of studying the code from freekick3:

 

http://codeflow.wordpress.com/2012/12/09/the-ai-in-freekick-3/

Edited by racarate

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement