-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatePoints.py
More file actions
109 lines (84 loc) · 3.95 KB
/
Copy pathCreatePoints.py
File metadata and controls
109 lines (84 loc) · 3.95 KB
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
from math import sin, cos, pi, log1p
# This is only used for generation of gaussian distribution.
import random as rd
# Our random value generator.
from rng import random_value
import AwardPoints
from createCsv import create
from getCoefficient import GenerateCoeff as Gen
from DartBoard import *
def distribute(number_of_players, max_number_of_rounds, shots_per_round):
points = []
coords = generate_circle_array() # Create circle.
shot_coords = []
# Sigma is the "accuracy parameter", ideal ranges are 1 to 5
sigma_begin = 1.1
sigma_current = sigma_begin
# One round has (shots_per_round) throws * 10 rounds in a match.
for n in range(number_of_players):
number_of_rounds = 1
while number_of_rounds <= int(max_number_of_rounds):
offset = False
for y in range(shots_per_round):
rand_coord = random_value(37, len(coords) - 1, 0, len(coords) - 1, integer=True) # Pick random index of coords.
gauss_samplex = generate_gauss(sigma_current)
gauss_sampley = generate_gauss(sigma_current)
coefficientx = Gen() # 20% chance for an offset, this can either help or sabotage
coefficienty = Gen()
if coefficientx != 0 or coefficienty != 0:
offset = True
else:
offset = False
value = coords[rand_coord] # The value to multiply.
# Move the point towards the centre, add offset
x_cord = value[0] * gauss_samplex
y_cord = value[1] * gauss_sampley
x_cord += coefficientx
y_cord += coefficienty
# Compression for more randomness. 10% for each cord to land in a very specific area
if random_value(37, 10, 0, 10, integer=True) >= 9:
y_cord = cord_compression(y_cord)
points.append(AwardPoints.calculate_points(xCord=x_cord, yCord=y_cord))
shot_coords.append([x_cord, y_cord])
continue
if random_value(37, 10, 0, 10, integer=True) >= 9:
x_cord = cord_compression(y_cord)
points.append(AwardPoints.calculate_points(xCord=x_cord, yCord=y_cord))
shot_coords.append([x_cord, y_cord])
continue
shot_coords.append([x_cord, y_cord])
points.append(AwardPoints.calculate_points(xCord=x_cord, yCord=y_cord))
number_of_rounds += 1
create(rounds=max_number_of_rounds, offset=offset,
sigma_current=sigma_current, shots_per_round=shots_per_round,
points=points, player_index=n + 1)
if True:
dart_board = DartBoard(player=n + 1, shots=shot_coords, maxRounds=max_number_of_rounds,
maxShots=shots_per_round)
dart_board.run()
sigma_current += 0.2
shot_coords.clear()
points.clear()
# Generates coordinates of a circle.
def generate_circle_array():
radius = 5
coords = []
theta = 0
resolution = 0.05 # Sets the amount of coords generated for the circle, lower means more coords.
while theta < 2 * pi:
coords.append((radius * cos(theta), radius * sin(theta)))
theta += resolution
return coords
# Generate gaussian distribution with mean 0 and stddev of sg^-1.
def generate_gauss(sg):
sample = rd.gauss(0.0, 1 / sg)
while sample > 1 or sample < -1:
sample = rd.gauss(0.0, sg)
return sample
# This function will compress a coordinate in order to add more randomness to the simulation.
def cord_compression(cord_to_compress):
compressed = 2.9 * log1p(0.1 * cord_to_compress + 1)
return compressed
if __name__ == "__main__":
# Match is 3 throws/8 rounds, we are doing 8 throws/3 rounds which is the same
distribute(number_of_players=6, shots_per_round=8, max_number_of_rounds=3)