# Pool AI

This topic is 4802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi , I'm making a pool game and I'm at point where I can implement the AI for the game. What is the best algorithm to play pool (9-ball) ? 1. selecting the right color (full or half-full balls) 2. sorting from nearby a pocket tot far away 3. selecting only the balls who are pottable (=> no balls on the way to pocket and way from white to selected ball) 4. play the ball with right power, right angle the first and second stap aren't really difficult. I have some problems with the 3 en 4 step. My questions : 1. How do I check if a ball is pottable in a pocket ? (I guess something with angle? what is the maximum angle to pot ?) 2. What is a right angle to play a ball (how to calculate) ? Thx in advance !

##### Share on other sites
Maybe you could test every ball with the right color and see which one you would have to hit to get an as straight line as possible. And then check if that ball is possible to hit (other balls in the way?) and if it has a clear path to the pocket.

##### Share on other sites
Keep in mind that the real strategy is not in which shot to make, but where to leave the ball after the shot. I've won a lot of games in pool against people that could shoot better than me because I don't leave 'em a shot.

##### Share on other sites

Hi,

quite an interesting question, because I play a lot of pool myself (recently broke my personal record by running 5 consecutive racks 8-ball in competition play!!).

- What game? I think you should start with a 9-ball algo. This way you always know which ball you have to play. If you have this running, you could implement a ball-selection algo afterwards for 8-ball / 14.1. I would first concentrate on aiming / force / english (or side).

- Aiming: I'll explain this the way I do with beginner pool players. To pot an object ball in pocket:
Draw a line from the pocket straight through the middle of the object ball. We mark the point where this line 'leaves' the object ball. This is the point where the cueball should hit the object ball. If the cueball hits the object ball exactly at that point, the two balls will be exactly aligned to the pocket (for a fraction of time). Now, from this point, draw a line through the middle of the cue-ball. This line is now your aiming vector.

- Position play: The line in which the cue-ball bounces of the object ball is perpendicular to the line from the object ball to the pocket. [simplified]The may the cueball bounces of a rail: Equal angle in, Equal angle out [/simplified]. Calculate all lines the cue-ball travels after potting the object ball. I will call these 'travel-lines'.

I would mark 'zones' in which to leave your cue-ball for your next shot (say the 2-ball) by doing the following:
- draw a line from the nearest pocket to the 2-ball to the right side of the 2-ball
- draw a line from the nearest pocket to the 2-ball to the left side of the 2-ball
This should give you a triangular zone on the table. Intersect this zone with perpendicular lines say 15 cm to 1 meter from the 2-ball (you don't want to be too near or to far). Of course, intersect this zone with rails first. You now have your zone.

[assuming you only 'stun' balls]
The speed at which the cue-ball travels after potting a ball could be calculated by using a simple function :

newSpeed = (potting angle / 90) * oldSpeed. If you have a straight pot (angle = 0 degrees), the cueball will stay frozen. If you have a very thin cut (say angle = 80 degrees). The cueball will have almost the same speed as your original potting speed.

Once you have this down, you can experiment with spin (or english) to adjust angles the cue-ball bounces of rails.

Hope this helps,

Edo

##### Share on other sites
Quote:
 Original post by coderx75Keep in mind that the real strategy is not in which shot to make, but where to leave the ball after the shot. I've won a lot of games in pool against people that could shoot better than me because I don't leave 'em a shot.

Although this isnt even slightly the case in computerised pool, well except for snookers of course. Even a game like virtual pool 3 u could play any shot that was playable of the cusion etc.

ace

##### Share on other sites
Quote:
Original post by ace_lovegrove
Quote:
 Original post by coderx75Keep in mind that the real strategy is not in which shot to make, but where to leave the ball after the shot. I've won a lot of games in pool against people that could shoot better than me because I don't leave 'em a shot.

Although this isnt even slightly the case in computerised pool, well except for snookers of course. Even a game like virtual pool 3 u could play any shot that was playable of the cusion etc.

ace

A good player will do the same in a real game, so I'm going to give coderx75 the benefit of assuming he is a good player, and that therefore he was refering purely to a snooker.

As for choosing a ball, if you're working with 9 ball, they should be potted in order.

##### Share on other sites

Quote:
 Keep in mind that the real strategy is not in which shot to make, but where to leave the ball after the shot. I've won a lot of games in pool against people that could shoot better than me because I don't leave 'em a shot.

I don't think the game of Unzip Attack should focus on that. 9-ball is an attacking game, it should focus on potting and position first. Safeties are a lot harder to program, because it involves the path and positions of 2 balls in stead of only the cueball.

Cheers,

Edo

• 9
• 23
• 10
• 19