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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/orefinder_estimate/cluster.rb', line 57
def generate_clusters(seed:, ore:, era:, cfg:, px:, pz:, biome:, search_radius: 220)
peak_y = Probability.optimal_y_for_mining(cfg)
band_lo, band_hi = adaptive_center_band(cfg, search_radius)
num_centers = search_radius < 48 ? 2 : 3
points_per_cluster = [4, 3, 3]
min_y = cfg['minY']
max_y = cfg['maxY']
expand = lambda do |cx, cz, n, rng, confidence_bonus, primary|
xz_min = primary ? PRIMARY_XZ_MIN : SECONDARY_XZ_MIN
xz_max = primary ? PRIMARY_XZ_MAX : SECONDARY_XZ_MAX
y_max = primary ? PRIMARY_Y_MAX : SECONDARY_Y_MAX
pts = []
push = lambda do |x, y, z|
prob = Probability.calculate_ore_probability(cfg, y, biome)
d = dist2(x, z, px, pz)
conf = Probability.clamp(Probability.calculate_confidence(prob, d, y, peak_y) + confidence_bonus, 0, 100)
pts << {
'x' => x, 'y' => y, 'z' => z,
'confidence' => Rng.round_to_tenth(conf),
'probabilityPct' => Rng.round_half_up(prob * 1000) / 10.0,
'distance' => Rng.round_to_tenth(d)
}
end
if primary && n > 0
center_y = Probability.clamp(Rng.round_half_up(peak_y + (rng.call - 0.5) * 2), min_y, max_y)
push.call(Rng.round_half_up(cx), center_y, Rng.round_half_up(cz))
end
start_i = (primary && n > 0) ? 1 : 0
(start_i...n).each do
mag_x = xz_min + rng.call * (xz_max - xz_min)
mag_z = xz_min + rng.call * (xz_max - xz_min)
sx = rng.call < 0.5 ? -1 : 1
sz = rng.call < 0.5 ? -1 : 1
x = Rng.round_half_up(cx + sx * mag_x)
z = Rng.round_half_up(cz + sz * mag_z)
dy = if primary
Probability.clamp(Rng.round_half_up((rng.call + rng.call - 1) * y_max), -y_max, y_max)
else
Probability.clamp(Rng.round_half_up((rng.call + rng.call + rng.call - 1.5) * 2), -y_max, y_max)
end
y = Probability.clamp(Rng.round_half_up(peak_y + dy), min_y, max_y)
push.call(x, y, z)
end
if primary && !pts.empty?
max_probs = pts.map { |p| p['probabilityPct'] }
max_p = max_probs.max
if max_p < 75
k = max_probs.index(max_p)
y_best = Probability.clamp(Rng.round_half_up(peak_y), min_y, max_y)
p0 = pts[k]
prob = Probability.calculate_ore_probability(cfg, y_best, biome)
d = dist2(p0['x'], p0['z'], px, pz)
conf = Probability.clamp(Probability.calculate_confidence(prob, d, y_best, peak_y) + confidence_bonus, 0, 100)
pts[k] = {
'x' => p0['x'], 'y' => y_best, 'z' => p0['z'],
'confidence' => Rng.round_to_tenth(conf),
'probabilityPct' => Rng.round_half_up(prob * 1000) / 10.0,
'distance' => Rng.round_to_tenth(d)
}
end
end
pts.each_with_index.sort_by do |p, i|
[-point_ux_score(p['probabilityPct'], p['distance'], search_radius), -p['confidence'], i]
end.map(&:first)
end
base_rng = Rng.make_rng([seed.to_s, ore, era, 'centers', num_str(Rng.round_half_up(px)), num_str(Rng.round_half_up(pz))])
base_angle = base_rng.call * Math::PI * 2
built = []
(0...num_centers).each do |c|
r = Rng.make_rng([seed.to_s, ore, era, 'c', c.to_s, num_str(band_lo), num_str(band_hi)])
angle = base_angle + c * ((2 * Math::PI) / num_centers) + (r.call - 0.5) * 0.45
rad = band_lo + r.call * (band_hi - band_lo)
cx = px + Math.cos(angle) * rad
cz = pz + Math.sin(angle) * rad
n = points_per_cluster[c] || 3
primary = c.zero?
bonus = primary ? 5 : 0
pts = expand.call(cx, cz, n, r, bonus, primary)
if pts.empty?
max_prob = 0
mean_prob = 0
mean_norm_dist = 1
else
max_prob = pts.map { |p| p['probabilityPct'] }.max
mean_prob = pts.sum { |p| p['probabilityPct'] } / pts.length.to_f
mean_norm_dist = pts.sum { |p| norm_distance(p['distance'], search_radius) } / pts.length.to_f
end
rank = cluster_rank_score(max_prob, mean_prob, mean_norm_dist)
rank += 22 if c.zero?
built << { 'pts' => pts, 'rank' => rank }
end
sorted = built.each_with_index.sort_by { |b, i| [-b['rank'], i] }.map(&:first)
best = sorted.empty? ? [] : sorted[0]['pts']
secondary = sorted[1..].map { |b| b['pts'] }
{ 'bestCluster' => best, 'secondaryClusters' => secondary }
end
|