views:

272

answers:

3

I am currently in the planning stages of a game for google app engine, but cannot wrap my head around how I am going to handle AI. I intend to have persistant NPCs that will move about the map, but short of writing a program that generates the same XML requests I use to control player actions, than run it on another server I am stuck on how to do it. I have looked at the Task Queue feature, but due to long running processes not being an option on the App engine, I am a little stuck.

I intend to run multiple server instances with 200+ persistant NPC entities that I will need to update. Most action is slowly roaming around based on player movements/concentrations, and attacking close range players...(you can probably guess the type of game im developing)

+2  A: 

Will your game be turn based or real time?

Either way, I think you have 2 options to look into. One is to use the Cron feature so you can schedule NPC updates at regular intervals, the other is to stick a "update NPCs" task into the Task Queue every time a human player moves.

Peter Recore
it will be turn based...i think a combination of those might be feasible for what I am trying to do...the NPCs will be more active as players are active, so it would make sense. I am just wondering what the limitations of the cron'd task might be, could it handle a mass NPC update if the AI was simple (again AI is going to be fairly stupid)
Hortinstein
you'll need to break up your cron'd tasks into 30 second chunks just like you would regular requests, as all the cron API really does for you is let you call urls in your app.
Peter Recore
i think that any time a player moves within a certain area queuing a few NPC moves would be reasonable. I guess I will just have to balance as I go along and find a good marriage. I would probably make it propigate through other NPCs in the area of a moving NPC, so I could get a herd like movement. This will be difficult to get right, since I can already see accidently incrementing tasks to infinite.
Hortinstein
+1  A: 

If the game is turn based then it would probably be best to avoid the Cron task and just update the NPCs every time the player moves. I'm not sure how big of a map you are planning on but you may consider even having the player object find the NPCs that are close to it and call their AI routine. That way NPCs that are out of range of a player wouldn't move at all which may save on resources. Not sure if that matter though.

Peter
+1  A: 

Bear in mind that you can also break up your updates into multiple requests (internally): do a bit of work, redirect to the same handler but different state; do more work; etc. (I'm failing somehow to comment on Peter Recore's answer, which is where this really belongs.)

I see that the free service only allows 100k task queue calls/day, so 1 task/NPC would probably use up your resources way too fast. Cron job to do some work/create task queues to update NPCs in appropriately-sized groups?

Anyway, just some thoughts; good luck.

LH
LH, you were 9 reputation short of being able to leave comments on other people's questions. (see the FAQ for the relatively complete list of what abilities you gain with rep) I just upvoted your answer, so you should now be over 50.
Peter Recore
LH