Multi-Core AI

Video:

http://screencast.com/t/kIaXyrkUd

Discussion:

This weekend I’m working on optimizing memory usage in the game. This requires a lot of testing that involves having the AI play against the AI on the largest possible map with lots of players.  Now, late game, there’s only a handful of players left (in the video above you can probably figure out how many) but the times can take a lonnng time.

Let me first ask those of you reading this, how many of you have played the beta on a large map with lots of players with >500 turns into it? It gets slow. There are thousands of units and dozens of cities and lots of things going on. Each unit has its own armor, weapons, enchantments, equipment, rings, etc.  And each turn, the game has to go and evaluate all these to see if the various cached values need to be updated – and late game, they often do.

So in a bit of frustration, I bit the bullet and created a worker thread for each AI.  In FE 0.86, the player and “the AI” move simultaneously.  In my build, the player and each AI player moves simultaneously.

This could only be done because of the work in the past few months of making the game much more thread safe.  So it’s a good robustness test to be able to not just have a few “dedicated” threads where each thread has a specific job. Now, we can toss threads around as needed and let your multi-core machines take care of the rest.

Or put another way, the idea of putting all these into their own threads is pretty obvious. The ability to actually do this safely is the key element here.

Oh, in case you’re wondering, in my example the end turn wait went from 8 seconds to 2 seconds in my massive, mega game.

59,332 views 41 replies
Reply #1 Top

I play on large with 8 players. By turn 500 4 of them are usually wiped out. I haven't noticed extremely long wait times. I usually see about 8-12 seconds in the late game. I honestly use that time to do my own computing. Humans need to think too!

Reply #2 Top

8 to 12 seconds would drive me crazy.

The other benefit in reducing that time is that it puts more pressure on the core systems to be robust. 

Reply #3 Top

I usually play on medium maps with 6 players. Laggy frame rate and actions taking long times is usually a bigger problem then long turns late game.

 

Reply #4 Top

That's Fair. I always end turn with a scenic view of a city and then contemplate my Kingdom. Can't do this in most games out there.  :inlove:

Reply #5 Top
I was just reading a thread on Sword of the Stars II forums. Turn time by turn 203 was reported as 7 minutes. Pretty impressive work, Frogboy :-)
Reply #6 Top

I play large map (and wish it could be larger), with 8 or 9 players.  Instability is more a a problem than speed.  Don't recall how many turns.

This is with xp 32 bit, 3gb ram, core-2-duo  (big upgrade likely in a few months).

I expect that the current rig would get less benefit because it has only 2 cores.

Reply #7 Top

Quoting DsRaider, reply 3
I usually play on medium maps with 6 players. Laggy frame rate and actions taking long times is usually a bigger problem then long turns late game.

 

There are things you can do to help with frame rate.

1) Turn off anti-aliasing

2) Turn off pedestrians

3) Turn off the outlines 

Those 3 things can make a pretty big change if you're video card is older.

Reply #8 Top

Quite frankly I haven't been able to make it that far into a game in any build, and have noticed very little slowdown around turn 300 (about as far as I've gotten.)

Anything that decreases wait time is ok in my book. 

I think you should push the technology, not let the technology push you.

Reply #9 Top

I play on large map with max number of players all at challenging or higher.

 

I tend start off next to 2-3 of them and end up taking them out fairly early on so I can have room to develop.

 

I haven't found any independent races yet.  I haven't really noticed things slowing down that much yet but I haven't gotten very far do to CTDs.

 

I am hoping this new build 0.89 will allow me to get farther along in the game.

Reply #10 Top

Quoting SerinMaldy, reply 9
I am hoping this new build 0.89 will allow me to get farther along in the game.

 

0.89?  Is that a typo, or do you know something???  (Spill the beans, man! :) )

Reply #11 Top

I would love to get that far into a game, but thus far it keeps crashing. :(

Reply #12 Top

Quoting Gammit10, reply 11
I would love to get that far into a game, but thus far it keeps crashing.

I couldn't find any crash reports from you.  While we do get a lot of data automatically, it would be helpful if you posted some crash info (OS, video card, etc.).

Reply #13 Top

I like playing large map with 10 players. Unfortunately, the game is stable only on tiny and small maps for me. As it progresses on medium or large maps, it crashes... alot. It also becomes very laggy. I have all the options FG mentioned above turned off.

So in short, I too usually don't make it to the end game due to stability problems.

Reply #14 Top

A possible optimization is memoizing or caching a lot of planning, depending how the AI works; in one of my (low calibre) games, I found the AI replanning a lot of what it had done before; recalculatinf scoring of the same targets, etc; I changed it to try and think numerous turns ahead, and cache whatever coudl be cached, and then during certain operations of opponents or itself, it'd 'dirty' up some of the cache, causing those parts to recalculate; ie: try and minimize the amount of work to do each turn. In one turn, if it decided production shoudl be X, why not decide production after that as well real quick, and then not worry about it.. unless an event caused it to be necessary? *shrug*

 

AI is too variable by engine and game and situation, but maybe you can go down that route somehow.. just an idea.

 

Or, in that event.. if the problem only occurs during late game with many plaers and many thousands of units.. thats relatively unlikely? ie: At turn 500, usually there shoudl onyl be a couple players left.. is there any optimization for just that scenario? Dumb things down for certain operations, or 'go for the kill' change of mentality.. less focus on long term goal, but eliminate those options and just plan short term kill goals, or something? ie: Elikinate some of the options (or lower their priorities) as the game duration goes on?

 

jeff

Reply #15 Top


I think waiting 10-20 seconds per turn is not too much to ask, does not bother me whatsoever, and I would much rather see your time devoted to other aspects of the game (if that makes you feel any better).

Reply #16 Top

While I agree that I think the core mechanics of the game are more important to both my enjoyment of FE and its success, a four fold reduction in time taken to process turns late game is a pretty impressive achievement and always going to be appreciated!

Reply #17 Top

I always play on large maps with 10 opponents (the 10 standard factions and I play my own).

I usually don't get that far because it becomes boring for me as it is clear that I'm dominating everyone (playing on challenging, I always wanted to try hard but then the new patch comes with better AI so I stay at challenging). In 0.86 I'm still strong but not totally overpowered so I keep playing - currently turn 235 everything running very smooth even on my laptop. If I get farther I'll report ;-)

Reply #18 Top

So, will FE require mult-core processors because of the change? Or will a single core work, but just be really slow because it can't work in the background. Doesn't impact me, just curious.

Sounds like stability and performance still need some work. I haven't played through far on .86, but the beginning/middle of games have been stable and had decent performance. Then again, it sounds like others hit problems in middle/late game.

Reply #19 Top

Do you get automated crash reports fro me? I am playing a large map ATM, but it is only turn 150 or so, and the game is nearly over (only 3 nations left, and I have wiped out the armies of one of them). The end turn wait time seems ok to me, but I get many crashes (when saving, especially if I had done several reloading before). I don't think any occured only for pressing end turn.

Reply #20 Top

"I get many crashes (when saving, especially if I had done several reloading before). "

^ This. Most of my crashes are after reloading the game a few times. I suspect it's a garbage collection issue of some kind.

 

Reply #22 Top

Quoting onomastikon, reply 15

I think waiting 10-20 seconds per turn is not too much to ask, does not bother me whatsoever, and I would much rather see your time devoted to other aspects of the game (if that makes you feel any better).

Making it more multithreaded helps in making the game more stable and use less memory since it allows me to do a lot more testing in a shorter amount of time.

The threads are particularly important because they really show areas that aren't "thread safe".

Reply #23 Top

Quoting Heavenfall, reply 21
Your reports are not automatically submitted. See this https://forums.elementalgame.com/415301[/quote]

In 0.86 they are via Smart Exception.  But it is still very helpful for people to make a POST with what they ran into.

Reply #24 Top

Quoting Lord, reply 18
So, will FE require mult-core processors because of the change? Or will a single core work, but just be really slow because it can't work in the background. Doesn't impact me, just curious.

Sounds like stability and performance still need some work. I haven't played through far on .86, but the beginning/middle of games have been stable and had decent performance. Then again, it sounds like others hit problems in middle/late game.

You don't "need" multiple cores. But we don't technically support single core.  Dual core is the minimum spec.

Reply #25 Top

So endless games of pitting AI against AI...

What happens when it realises that the only wining move is not to play? :p