# AI pool player pocket calculation

Hi I was wondering if anyone knew an easy was for an AI to elimate possible pockets that a ball could be pocketed into. For example if one the cue ball and and one other ball are on the table all 6 pockets are impossible to pot in without doing cushion bounces. I just need a calculation that would eliminate unrealistic pockets leaving the rest to be compared.

Any ideas would be appreciated.

That sounds pretty tough.  Maybe you could have it do predictive simulationsâ€¦ iow, if I hit the cue in this direction, I will get this resultâ€¦

Another thought here: You could compute the angle between the target and each pocket, and thus the angle at which the cue would have to hit the target in order to achieve this effect. Then weed out pockets based on distance and difference (dot product) of angles.

Hope it helps.

I've thought of two ways there is the angle way as duenez said or I can calculate the line between the cue ball and the ball trying to be potted and then find the perpendicular line at that point. Then all pockets on the other side of the perpendicular line would be possible and then I could do angle calculations to find the best pocket.

me220,

Hi I am also working on a pool game, and may be able to give you a pointer.  The REAL issue here is not wether you can get a ball in a pocket or not (just form a vector between the pocket center and and the center of the ball)  however what about obstacle in the way (rail or ball).  Well just translate the vector to either side of the ball and test for intersections with obstacles (line test).  As far as the vector between the cueball and the objective ball, you could use a predictive simulation OR use 'estimated ball collisions' and determine what angle the objective ball needs to be hit by the Cue ball.

Incidently,  I would be interested in collaborating.  I have been working on my game for quite a while (recently moved from JOGL to JME) and may have jumped several of the hurdles you already have.

Hey yeah sharing ideas would be good especially for the AI as I've been struggling with that the most. So far I have an AI that can pot the ball in a given pocket with a random Gaussian error so its not perfect. My next step is just to calculate which pocket it should go for.

That was gonna be my next stage after I could pot a ball in any pocket. I was gonna somehow figure out if pocket was obscured and then define that pocket as useable. Are you going to run offscreen simulations? I'm using the jME physics 2 engine, I guess you wrote your own physics.

This is only a partial solution but it might pan out with some (a lot of) work.

Start off by ignoring the white ball.

Find out which other balls are pot-able.

Assume a maximum number of collisions (say 5) its ridiculous for a computer to pot a ball after bouncing off 20 cushions.

Send out a bunch rays (say 1 degree apart) from each pocket and reflect them off the cushions.

If the ray hits another pocket discard them.

If the ray reaches its bounce limit (5) without hitting a ball discard it.

Any (halfway decent) shot should be represented by at least two rays, lets assume:

One ray hits the ball somewhere nears its center

The other hits close to the opposite edge of the ball.

Calculate the ratio of closeness to center of the two rays:

E.g. The center ray is 10 times closer to the center than the other ray.

Each of the rays will intersect the ball at an angle say :

Center:  45 degrees

Other: 47

So the optimal shot is 45 + ((47-45) / 10) = 45.2

Now all you need to do is:

• Ensure the path to the pocket is actually clear: the ray has no width the real ball does.

• Calculate how the white has to be hit in order to get the ball.

The ray tracing system can be repeated for the white, however there are additional complications:

• English/spin on the white.

• The target point on the colored ball may not be in the center.

Note: I have used several approximations in this algorithm but they should be good enough.

I find the idea of an AI pool player very interesting and would like to collaborate with the two of you in some way. I am not making my own pool game right now, but I might be able to help think things out on the AI side maybe.

Here is a good questionâ€¦ 8-ball or 9-ball? I think making AI for a 9-Ball pool game would be a bit easier than for 8-ball. What do you think?