I’ve finished implementing the next stage of the AI golfing in Boss Golf!
Until now, it would just take the straight line to the hole, and hit as close as it could. It didn’t matter if it would land in a bunker or not, as long as it was closer to the hole, it was fine.
Now, though, it’ll actually take a good hard look at the golf course based on its own stats, generate a couple of alternative shots, grade them, and then take the one that is most desirable.
To start off, we have a Vision attribute for the AI golfers. This attribute governs how much the AI will try to “think outside the course”. It dictates the field of view that the AI has when thinking about a hole. Higher vision means being able to explore areas well outside the straight path to the hole. Lower vision means trying to hit as forward as they can, and fail to notice other better areas of the course.
Let’s take the hole below for an example:
It’s a pretty straightforward hole. There’s some trees to the side and a massive waste bunker all around the area.
Now let’s draw some potential fields of view:
In the above image, we have three different fields of view:
- Red is a golfer with high vision
- Yellow is a golfer with medium vision
- Cyan is a golfer with low vision
The red circle is the position where this shot is being taken, and the green circle is the location of the hole.
As said before, the Vision designates the search space for the AI to find a good shot. It’ll then iterate possible flight paths of the ball based in this search space, trying to get as close to the hole as possible, while also evaluating the terrain under it. The AI has come up with the following options:
These are the 6 best ideas that the AI has come up with. It’ll then score them based on how good a shot it is and how difficult a shot it is. Difficulty is calculated based on the club needed to reach that distance (1 Iron is god tier difficulty), as well as the terrain that it has to traverse, like below:
Red shows problematic terrain, such as the bunker or tall grass.
Green shows good terrain, such as the fairway and the green.
Now it isn’t as simple as choosing the shot with the lowest difficulty to “payoff” ratio. Or it would be too easy!
This is the point where the AI Confidence attribute can interfere with the AI’s thought process. The AI has a good idea about how difficult the shots are, and how high the payoff is. Next it’ll query its own confidence in order to help it choose. If it’s feeling particularly cocky, it may go for the high payoff, high difficulty shot. If it’s feeling not so confident, it may instead choose the lower payoff, easy to hit shot.
After choosing, the AI will then take the shot. But before it does, we add some fuzzy logic to its shot, to add the regular accuracy/power deviation that every player has.
And then it waits until the ball stops traveling and lands.
Once the ball comes to a shot, the AI will then reevaluate its choice, to see if the gamble paid off or not. If it projected to land on the fairway close to the hole, and it does, its confidence will rise a bit. If it instead landed straight on the bunker, AI confidence will lower, which can have other more significant impacts down the line!
Now this hole was very straightforward, and there would be very little variation between what a pro would do and what a beginner would do.
Imagine however that that little strip of fairway to the left of the main waste bunker actually had a clear shot to the green, like below:
This could give golfers with higher Vision an edge, as they would be the only ways able to see that kind of shot happening. It would also be a challenging shot, which would appeal to golfers that prefer challenging courses. With this one simple change, you could increase the challenge rating of the hole, and please more types of golfers!
So that’s it for now! Golfers are quite a bit smarter now, and their playstyles have just become a lot more varied if compared to before! So once 0.5 hits, you’ll be able to see golfers acting quite differently from each other, depending on your hole of course!
Next up is basically making sure things are working, and adding a better “idle” routine so that the AI wanders around in a more realistic manner. 0.5 should be available soon!
Thanks for reading!