开发者

Simulate Golf Game Strategy

I am working on what at best could be considered a "primitive" golf game, where after a certain bit of randomness is introduced I need to play out a hole of golf. The hole is static and I am not concerned about the UI aspect as I jus开发者_C百科t have to draw a line on a graphic of the hole after the ball has been hit showing where it traveled.

I'm looking for input on thoughts of how to manage the "logic" side of the puzzle, below are some of my thoughts on the matter, input, suggestions, or references are greatly appreciated.

  1. Map out the hole into an array with a specific amount of precision, noting the type of surface: out of bounds, fairway, rough, green, sand, water, and most important the hole.
  2. Map out "regions" and if the ball is contained inside one of these regions setup parameters for "maximum" angle of departure. (For example the first part of the hole the shot must be between certain angles
  3. Using the current placement of the ball, and the region contained in #2, define a routine to randomly select the shooting angle, and power then move the ball, adjust the trajectory and move again.

I know this isn't the "most elegant" solution, but in reality, we are looking for a quick and dirty solution, as I just have to do this a few times, set it and forget it afterward.

From a languages perspective I'll be using ASP.NET and C# to get this done.


ok, quick and not so dirty :D

have a function to plan various combinations of routes using different clubs (distances) that for a given player will give various approach plans

optimum plans are 1 to 5 strokes on a normal fields (par 3 to 5) so you can just brute-force them by dividing the field into squares with certain precision

assuming that you divide the field with 10 yard precision for the normal terrain let's assume 50x30 grid as maximum.

if you assume that each stroke/club will hit a certain distance in 90% cases then each stroke would fall on a percentage of the grid - let's assume a club would hit between 200 and 250 yards then it would normally hit (125^2*pi-100^2*pi)/(500*300)/4 * 1500 = 45 squares. (first term is max distance area, second min distance, it is divided by the complete area and only 1 4th is taken because well aim in the general direction of the hole - not more then to 45 degrees to any side).

this repeated for max 5 times would give a list of possible good plans with number of plans 45 over 5 at 7 * 10^8 (number needs to be reduced because the last choice is not as free as previous 4, but there is more then one club, so I'll leave it at this)

so iterating over clubs and their typical distances and taking the grid that represents the field to further reduce the area you are shooting for (you wouldn't aim for the forest, sand, watter) you could calculate a score for a particular shot - for example if the terrain is close to hazards you could lower the shots score. if the terrain is not flat you could lower the score, etc.

you can also improve the algorithm here by allowing to expand the aim area if you can not go directly towards the hole.

you can prune your walk of the field by keeping a list of best strokes.

at the end choose from the best seven plans by flipping a coin. and play the first shot.

to the shot apply a dice regarding how well the ball is hit, change in wind conditions and such.

re-run the planning depending on where you landed. for green change the resolution of the grid.

all this would require you to have

  1. list of clubs and min and max distances they can achive, you can also store percentages of bad/good hits and apply some randomness for bad hits
  2. grid of the terrain of the hole with values for types of terrain and you should assign values for risk

Improvements to more proper algorithm would require you to have a function that would turn the terrain at full resolution into a network of connected nodes (because a lot of terrain is conceptually the same and dividing it into a grid is brute force) with associated cost (risk) on the path to the hole and then it turns into a travelling salesman problem for which you would have existing algorithms.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜