| I sort of did something similar for my Darts app for the iPhone, specifically for defining the throw model for the "AI" player. I found it easiest to simulate millions of random dart throws parameterized by throw angle and velocity. I record the slot on the board (1-20, Bull) hit given the launch angles and force of the throw. I let this "simulation" run until I had 50 samples per board slot. The simulation is run once ahead of time. The simulation results are bundled with the app. When it becomes the AI's turn, it picks a slot to aim at based on the game variation and state of the game. Currently, it chooses rather poorly in Cricket. Then it picks a random sample from the sample pool recorded from the aforementioned simulation. Based on the user-chosen competence level, it adds a small, random amount of error to the angle and velocity associated with the selected sample. Finally, the dart is launched using the calculated angles and force. While the app is Objective C, the offline simulation was written in Python. The whole thing was a blast to write. Here's an old video of gameplay: http://vimeo.com/2010432 Skip ahead to around 1:10 to see the AI take its turn. |