Artificial Intelligence in Football ...

BlitzMax Forums/BlitzMax Programming/Artificial Intelligence in Football ...

mic_pringle(Posted 2007) [#1]
Hi,

I'm looking for some help/ideas/suggestions to help me implement a fairly realistic 2d football engine, where the decisions the players make are based on stats and tactics, and where the user doesn't actually take part in the game, but rather watches the game play out, being only able to change tactical decisions, and see them reflected in real time on the pitch.

I've been scanning the 'net now for sometime, hoping to pick up some theory or something on how this can be implemented, but I've so far come across nothing of any value.

This is pretty much an open thread, so post any/all ideas or theories you may have or that you think may help me.

Thanks in advance.

-Mic


tonyg(Posted 2007) [#2]
Programming Game AI by Example has a section on Football AI.


siread(Posted 2007) [#3]
Yoda soccer is open source and written in Blitz+ if I remember rightly. You may get some useful info/ideas from the code.

Also take a look at my game Sensational Soccer, in particular the tactics editor to see how the players positions are updated depending on the location of the ball. The AI is pretty basic in Sensational but the players all have individual skills and they are reflected reasonably well in the game. If you have any specific questions, just ask. :)


mic_pringle(Posted 2007) [#4]
Hi Si,

Thanks for the response. Just checking out Yoda Soccer now.

I've actually emailed you before, and you very kindly sent over some of the source code for the text match engine you did for NSS2, but I was having a bit of a hard time following it as it was in C.

I'm just after some of the theory behind it really ... will defo check out Yoda though, but if you have any thoughts or ideas you could drop in here for me it'd be greatly appreciated.

-Mic


Banshee(Posted 2007) [#5]
Well if you want realism in a football player just remove all signs of intelligence and make it spit.

More helpfully though, the first way that springs to mind in approaching this would be to divide the pitch into zones, and when the ball is in a particular zone set where the player should be based on which team last touched the ball. You can add logic as to whether the player bothers to get there, walks, runs or whatever, that's a player profile decision and probably factors in stamina too.

When the ball is in the same or adjacent zone then the player needs to switch over to a more active system where it makes decisions based on which player has the ball, if it's a friendly player and a defender - move up the pitch, if it's a friendly player and a midfield and the player is also a midfielder - move out to the side... Well your knowledge of football beats mine here, but something like that anyway.

Failing that, just make one look like 'Becks' and give the human player a baseball bat - because I owe that guy some payback for making me cringe whenever someone can't be bothered to use my full name. *shudder*


mic_pringle(Posted 2007) [#6]
Cheers Banshee ... will give your 'zoning' idea some thought, and I also like the idea about two levels of intelligence based on where the ball is.

The main sticking point for me at the moment is figuring out where to start ... I'm kinda hoping siread will jump in hear and give me some pointers !?


tonyg(Posted 2007) [#7]
Check with your local library for that book I linked to. Even if they haven't got it they can order it. Normally takes 1-2 weeks.


mic_pringle(Posted 2007) [#8]
Hi tonyg,

Will do, did have a check on Amazon and there was a fair few second hand copies so will probably end up getting one of those I think.

-Mic


siread(Posted 2007) [#9]
The way Banshee describes it is exactly how NSS and Sensational Soccer work.

You want to set up a player type that not only stores his current x,y location but also his desired location based on where the ball is. My pitch is split into 9 segments, so you could just use a 2 dimensional array [9,2]. Say the ball is in segment 4 then read [4,1] for the x position and [4,2] for the y position. Then move the player towards that location.

With this system you will tend to get player sitting still in one position for too long then suddenly charging off when the ball changes segments. It looks unrealistic if a player stands in the exact same place for more than a few seconds. You could of course break the pitch into more segments but I decided to do 2 things to combat this.

1) Find the coords of the centre of the segment, then work out how far the ball is offset from this. Then offset the player's desired location by the same amount (without leaving the pitch). You can see this at work in my tactics editor by dragging the ball around its current segment.
2) Make the player move randomly around his desired location.

I actually implemented the tactics system after I had a single player responding to joystick input. That way you can make sure that a player accelerates at the right rate, has momentum, tires out depending on distance run/stamina and so on. As you're making a management style game it may not be useful that way. Depends if you are animating the players or going for the FM style counters, i guess.

Hope that helps. :)


siread(Posted 2007) [#10]
BTW, having said all that i'm thinking of experimenting with a slightly different system for NSS4. Rather than have 9 segments just use 1 and find the offset of the ball from the cetre of the pitch. Then move all the players based on their formation. This loses some of the fine tuning you can have with the 9 segments, such as wingbacks getting as far forward as the opponent's penalty area, or players breaking from the centre of the pitch to the wing and so on, but I imagine these kinds of instructions could be set for individual players in your team screen. It's something I will play with in the coming months.


mic_pringle(Posted 2007) [#11]
Hi si,

Thanks a lot for that ... it's given me some some good ideas and at least a starting point.

I was thinking about starting with something exceptionally basic to get a solid foundation, and then start building in things like attributes, certain football rules such as offside etc

As for animating, not totally sure yet, but was thinking some like Yoda or Sensational ... although couldn't get Yoda to run properly on my MacBook !?

-Mic


siread(Posted 2007) [#12]
You can use my Sensational sprites. Just have a hunt around the folders.


Fry Crayola(Posted 2007) [#13]
Si, a few years ago I was experimenting with a "one segment" system whereby the rough position of a player was determined using formulae rather than hand-crafting.

It became apparent that the different needs of each player on the pitch meant that most of them would have needed their own calculations in order to ensure that these positions would be accurate enough to use as a solid platform to build upon. This was in Blitz3D so I dropped what little I had when Max came along, but I had pretty much decided by then that I wasn't going to pursue it any longer.

When you look into it, it's not just NSS3 and Sensational Soccer that break the pitch up into segments. Sensible Soccer did it, Championship Manager built its entire third game upon it, and Football Manager 2007 still uses it under the hood, albeit in an ineditable format.

As such, I'm planning to use the same system as "step one" of the whole AI process, just as a means of maintaining the basic, solid shape before each player starts to consider his surroundings and the situation at hand. Much like Championship Manager I'll be using two separate sets of coordinates, one for having possession, one for without.

Everything after that should, in theory, be down to the player AI and tactical instructions, deciding if he should sit further back to cover a gap, close down the player in possession or make a driving run into space.

I expect to be starting work on the match engine next Monday at the latest, so I might just pop in and out of this thread with my thoughts.


mic_pringle(Posted 2007) [#14]
Hi Fry,

Sounds like we may be working on something similar ... I'd love to hear any further thoughts you may have !?

-Mic


Fry Crayola(Posted 2007) [#15]
I've recently made a blog post on this topic, specifically covering the whole issue of sorting out the rough positions.

It's nice to have finally started on the match engine stuff...


mic_pringle(Posted 2007) [#16]
Hi Fry,

I know it's been quite a while but did you manage to get any further with this !?

(Just gonna check out your blog now!)

-Mic