Box2D Forums

It is currently Sun May 19, 2013 8:29 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Jun 26, 2012 9:38 pm 
Offline

Joined: Tue Sep 25, 2007 2:22 pm
Posts: 482
Hi,

I'm just breaking ground on a little API for cloning a box2d world in order to run some speculative simulation for the AI players. I'm wondering, has anyone already done this before, specifically a b2World::clone() method or similar?


Top
 Profile  
 
PostPosted: Tue Jun 26, 2012 10:09 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
This will clone a world, but I doubt it would be fast enough to run many times per second on large worlds.
http://www.iforce2d.net/b2djson/
Just wondering, why does the AI need to clone the world? Does every AI entity do that?


Top
 Profile  
 
PostPosted: Wed Jun 27, 2012 7:04 am 
Offline

Joined: Tue Sep 25, 2007 2:22 pm
Posts: 482
The AI and some special moves require a predictive element. There is too much going on to predict the future accurately without simulating it directly. I can't reuse the main game b2World because it uses a tiny fixed timestep (8.3ms) and I'd rather let the AI and various predictive player elements have a full second of insight into the future using a 50 or 100ms timestep. The warm starting mechanism that creates very stable contacts works best when timesteps are fixed for a given b2World.

Incidentally, this will also make ball interception by the AI much easier to code.

The dumb AI inside this shadow simulation will use rand() to choose joystick direction and button presses, plus a few filters to keep their search space bounds a bit tighter. I've had very good luck using a brute force strategy in games where I had enough extra CPU around to use up.


Top
 Profile  
 
PostPosted: Fri Jun 29, 2012 3:38 pm 
Offline

Joined: Tue Sep 25, 2007 2:22 pm
Posts: 482
After some testing this week, I've had to conclude that a second world for the AI is not a viable approach on the iPad.

I am testing to see if using raycasted collision reaction and simple velocity/position updates is enough to allow the AI the insight it needs. I don't need the full precision of Box2D, but I do need a chance to play out various scenarios. I'm lucky that all the dynamic elements (4 players, 2 goalies, 1 ball) are circles, so it is easy for me to calculate if a collision occurred.


Top
 Profile  
 
PostPosted: Fri Jun 29, 2012 5:35 pm 
Offline

Joined: Tue Sep 25, 2007 2:22 pm
Posts: 482
Ok, this is pretty cool. I just copied the core integration code from b2Island::Solve and use that to advance my objects for the AI. It is enough for what I am trying to do. 8KHz.


Top
 Profile  
 
PostPosted: Mon Jul 02, 2012 9:36 pm 
Offline

Joined: Tue Sep 25, 2007 2:22 pm
Posts: 482
Thought anyone seeing this thread might enjoy seeing a video of the AI in action (primitive so far, but visualization looks cool):

http://www.youtube.com/watch?v=2TAsrAbKwo4


Top
 Profile  
 
PostPosted: Mon Jul 02, 2012 10:15 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
Location: Tokyo
Nice! It's all moving a bit too fast to catch what is going on, but definitely looks natural.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group