Pool simulation with Go and Fyne

Programming Snapshot – Go Pool Simulation

Article from Issue 283/2024

To improve his skill at the pool table, Mike Schilli sets out to program a simulation in Go using the Fyne framework.

If you just aim by the seat of your pants at the pool table in the pub, the results will vary between brilliant and downright embarrassing. That's why I decided to finally learn the angle at which you have to hit a ball so that it heads off in the right direction, straight for the pocket. To do this, I studied Poolology [1], which explains the strategy in detail. I don't have a pool table at home to practice on, so I wondered: How difficult would it be to write a graphical simulation of the pool balls in Go? That way I could try out the technology onscreen before challenging the biggest pool hustlers in the wickedest pool halls of San Francisco.

In the simplest of cases, pool players shoot the cue ball straight into the ball to be played, and the cue ball hits the colored ball right in the middle (you hope). The colored ball absorbs the energy of the cue ball and moves in the same direction, while the cue ball remains stationary – unless you used a trick such as spin. Things become more complicated if you hit a colored ball at an angle. In that case, it will shoot off to the side while the cue ball keeps moving along a deflected path. The angles here depend on the amount of overlap with which the colored ball was hit. In more concrete terms: If a pool player does not aim at the center of a ball but exactly at its edge (called a half-ball), the colored ball drifts away at an angle of about 30 degrees.


Use Express-Checkout link below to read the full article (PDF).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Chip Shot

    We all know that the Fyne framework for Go can be used to create GUIs for the desktop, but you can also write games with it. Mike Schilli takes on a classic from the soccer field.

  • Programming with QCanvas

    The Qt toolkit from Trolltech sports features that appeal to any developer’s needs, but one of the most fascinating and powerful parts of the toolkit is the QCanvas class.

  • Gaming for Godot

    Creating a game requires a wide set of skills to combine graphics, animations, sound, double-clicks, and meticulous coding. The free and open source Godot game engine provides you with all the tools you need to get started.

  • Moving Art

    Pencil2D, an easy-to-use painting and 2D animation program, lets you create small animations quickly. Despite the simple user interface, you might need a little help getting started.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More