-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsimulation_single.py
120 lines (104 loc) · 3.59 KB
/
simulation_single.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import numpy as np
import cv2
hole_length = 380
pixel_ratio = 7.4265734265
img = cv2.imread('images/Hole 18 Riverview/Hole 18 Riverview.jpg')
height, width, channels = img.shape
statistics = {
"fairway_50-75": 2.95,
"rough_50-75": 3.0,
"fairway_75-100": 2.86,
"rough_75-100": 3.1,
"fairway_100-125": 2.87,
"rough_100-125": 3.08,
"fairway_125-150": 2.91,
"rough_125-150": 3.13,
"fairway_150-175": 3.0,
"rough_150-175": 3.17,
"fairway_175-200": 3.04,
"rough_175-200": 3.25
}
def calculate_approach_score(fairway, distance):
dict_string = ""
if fairway:
dict_string += "fairway_"
else:
dict_string += "rough_"
if distance < 75:
dict_string += "50-75"
elif 75 <= distance < 100:
dict_string += "75-100"
elif 100 <= distance < 125:
dict_string += "100-125"
elif 125 <= distance < 150:
dict_string += "125-150"
elif 150 <= distance < 175:
dict_string += "150-175"
else:
dict_string += "175-200"
return statistics[dict_string]
fairway_driver = True
# get value for driver how far off center of fairway
off_center_driver = np.random.normal(0, 20)
print("Driver off center:", off_center_driver)
# get value for driver carry distance
carry_distance_driver = np.random.normal(300, 10)
print("Driver carry distance:", carry_distance_driver)
if off_center_driver > 10 or off_center_driver < -10:
print("You drove it in the rough with the driver")
fairway_driver = False
else:
print("You drove it in the fairway with the driver")
pass
driver_score = 1
if off_center_driver < -23:
print("You hit your driver out of bounds, adding two to score")
driver_score += 2
if off_center_driver > 50:
print("You hit your driver in the penalty area, adding one to score")
driver_score += 1
driver_length_to_hole = hole_length - carry_distance_driver
driver_score += calculate_approach_score(fairway_driver, driver_length_to_hole)
print("Driver score:", driver_score, "\n")
color = (255,0,0)
if driver_score > 4.0:
color = (0, 255, 0)
elif driver_score < 4.0:
color = (0, 0, 255)
# draw on picture
# cv2.line(img, (341,height-80), (340,height-80-int(carry_distance_driver*pixel_ratio)), (255,255,255), 15)
cv2.circle(img, (341+int(off_center_driver*pixel_ratio),height-80-int(carry_distance_driver*pixel_ratio)), 15, color, -1)
fairway_2i = True
# get value for 2i how far off center of fairway
off_center_2i = np.random.normal(0, 15)
print("2i off center:", off_center_2i)
# get value for driver carry distance
carry_distance_2i = np.random.normal(250, 10)
print("2i carry distance:", carry_distance_2i)
if off_center_2i > 14 or off_center_2i < -14:
print("You drove it in the rough with the 2i")
fairway_2i = False
else:
print("You drove it in the fairway with the 2i")
pass
score_2i = 1
if off_center_2i < -23:
print("You hit your 2i out of bounds, adding two to score")
score_2i += 2
if off_center_2i > 50:
print("You hit your 2i in the penalty area, adding one to score")
score_2i += 1
length_to_hole_2i = hole_length - carry_distance_2i
score_2i += calculate_approach_score(fairway_2i, length_to_hole_2i)
print("2i score:", score_2i, "\n")
color = (255,0,0)
if score_2i > 4.0:
color = (0, 255, 0)
elif score_2i < 4.0:
color = (0, 0, 255)
# draw on picture
# cv2.line(img, (341,height-80), (340,height-80-int(carry_distance_driver*pixel_ratio)), (255,255,255), 15)
cv2.circle(img, (341+int(off_center_2i*pixel_ratio),height-80-int(carry_distance_2i*pixel_ratio)), 15, color, -1)
cv2.imshow('Simulation Results', img)
cv2.waitKey(0)
cv2.destroyAllWindows()