More AI news

Hey there, some more news on the AI side of Mox. I’m very satisfied with the current state of the AI in Mox. It’s very stable and runs at a good speed. My worst test case, that simulates 2 AIS with each 7 shocks, resolves completely (all players play all shocks) in less than a second, which is completely satisfying, considering that each individual AI move takes a fraction of that time.

I have reimplemented the low-level storage part of my object model, to add some flexibility and more performance. That went suprisingly well (I was done in an hour). The new implementation is inspired from the WPF dependency properties implementation. Basically, each property is assigned a unique ID (32 bit). Each object’s properties values are stored in an array sorted by those IDs. Lookup is done with a binary search in that array.

I’m now tempted to try to multi-thread my AI code. I’m realizing that I’m very close to being able to do that, and I’m thinking that if I don’t do it now (early), when not so much of the rest is done and it is the easiest time to do, I’m never gonna do it. Here are the things I would need to do:

  • Synchronize one additional game for each “AI thread”. These would be independent copies of the main game, all synchronized identically so that all AIs see the same game. This is already implemented because I use this mechanism for the server/client architecture.
  • Make the game flow stateless. I’ve talked about this in an earlier post. For AI, I implemented a system where game flow components (which I call parts) are stateless and so can be executed again and again. Well, currently it is not quite the case. Some parts keep variables around to pass to the next part. I’m not clear about how I can totally remove those, but I’m leaning toward removing these from the parts and putting them into some thread affine context (one context per AI thread). If the parts are completely stateless, they can be safely shared across all threads.
  • Modify the AI entry point so that it dispatches the first level of choices to each thread, waits on the threads to finish and then decides on the final move to make. I don’t expect this to be hard.

Not too hard, heh? I think it would definitely add some value to Mox since most people have multiple processors now.

Then I can go back and implement some rules đŸ˜› I bet you guys are all thinking that I should talk more about the actual game of Magic!

Advertisements

About fparadis2

Lead Game programmer
This entry was posted in Mox. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s