Forum C# Best way to handle processor intensive AI?

Best way to handle processor intensive AI?

Postby AndyKerrison » January 11th, 2013, 5:56 pm

Right, so the game I'm developing is a multiplayer board game. It is a 4 player game, and 'empty' slots will be filled by AI players. For the majority of the game the AI decisions are fairly trivial to make, but on occasion it need to do something more complicated - think chess-style search space algorithm to determine the best move. Now, there's something like a 100ms limit on requests to the server before they get killed for CPU hogging. I can't be sure how long the calculation will take, so my question is, what are some good ways to handle this?

At the moment I'm thinking I put some kind of timer in the code, have the search routine check it regularly and if still incomplete at >= 90ms then bail out and return the best move found so far.

Alternatively, if I'm feeling a bit cheeky, I could halt the search state and send an 'incomplete' message back to the clients, which will immediately respond by triggering a 'continue' event. It's a bit more complex, but would give me more time to play with. Although does feel like borderline abuse of the system... but then this search only happens a few times per game anyway. It's not like there's much processing going on the rest of the time.

Any other good ideas?
AndyKerrison
 
Posts: 14
Joined: November 29th, 2012, 9:24 am

Re: Best way to handle processor intensive AI?

Postby Benjaminsen » January 11th, 2013, 6:20 pm

The way this is typically handled in a game like Chess is to let the code run for X amount of time, using the best move found when X time has expired. In your case 100ms.

On the note of simply pausing processing, yes that sound fairly abusive and it something we are likely to dislike.

As a solution we do offer private servers where the CPU timeout can be extended / disabled. If this sound interesting shoot me an email at chris@player.io and I will send over the details.
Benjaminsen
.IO
 
Posts: 1444
Joined: January 12th, 2010, 11:54 am
Location: Denmark

Re: Best way to handle processor intensive AI?

Postby ASH1138 » January 27th, 2013, 10:43 am

AndyKerrison wrote:Right, so the game I'm developing is a multiplayer board game. It is a 4 player game, and 'empty' slots will be filled by AI players. For the majority of the game the AI decisions are fairly trivial to make, but on occasion it need to do something more complicated - think chess-style search space algorithm to determine the best move. Now, there's something like a 100ms limit on requests to the server before they get killed for CPU hogging. I can't be sure how long the calculation will take, so my question is, what are some good ways to handle this?

At the moment I'm thinking I put some kind of timer in the code, have the search routine check it regularly and if still incomplete at >= 90ms then bail out and return the best move found so far.

Alternatively, if I'm feeling a bit cheeky, I could halt the search state and send an 'incomplete' message back to the clients, which will immediately respond by triggering a 'continue' event. It's a bit more complex, but would give me more time to play with. Although does feel like borderline abuse of the system... but then this search only happens a few times per game anyway. It's not like there's much processing going on the rest of the time.

Any other good ideas?



Move everything to the client. ;) Designate one player as the AI- host and have him send all the AI commands over to the other players. Not the smoothest method, but the most reliable.

I personally implement this myself in my RTS game, the same concept, when there are AI players,I just move everything over to one client, and have him decide everything.

Of course if that player turns out to be a cheater, set up a system to ban him....wait? Why would someone want to modify the AI in the first place? :?:
ASH1138
 
Posts: 285
Joined: November 17th, 2012, 2:29 pm


Return to C#



cron