Module: OrefinderEstimate::Probability

Defined in:
lib/orefinder_estimate/probability.rb

Class Method Summary collapse

Class Method Details

.biome_multiplier(cfg, normalized_biome) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/orefinder_estimate/probability.rb', line 51

def biome_multiplier(cfg, normalized_biome)
  m = cfg['biomeModifiers'][normalized_biome]
  return m unless m.nil?
  return 0.12 if cfg['specialRules'] && cfg['specialRules']['biomeExclusive']

  1.0
end

.calculate_confidence(probability, distance, y_level, optimal_y) ⇒ Object



83
84
85
86
87
88
# File 'lib/orefinder_estimate/probability.rb', line 83

def calculate_confidence(probability, distance, y_level, optimal_y)
  confidence = probability * 100
  confidence -= [(y_level - optimal_y).abs * 2, 30].min
  confidence -= [distance / 100.0, 20].min
  clamp(Rng.round_to_tenth(confidence), 0, 100)
end

.calculate_ore_probability(cfg, y, raw_biome) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/orefinder_estimate/probability.rb', line 59

def calculate_ore_probability(cfg, y, raw_biome)
  nb = normalize_biome(cfg, raw_biome)
  total = 0.0
  cfg['distributions'].each do |dist|
    prob = if dist['type'] == 'triangular' && !dist['peakY'].nil?
             triangular_probability(y, dist['minY'], dist['maxY'], dist['peakY'])
           elsif dist['type'] == 'uniform'
             uniform_probability(y, dist['minY'], dist['maxY'])
           else
             0.0
           end
    total += prob * dist['weight']
  end
  total *= biome_multiplier(cfg, nb)
  [total, 1.0].min
end

.clamp(n, lo, hi) ⇒ Object



11
12
13
# File 'lib/orefinder_estimate/probability.rb', line 11

def clamp(n, lo, hi)
  [[n, lo].max, hi].min
end

.normalize_biome(cfg, biome) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/orefinder_estimate/probability.rb', line 40

def normalize_biome(cfg, biome)
  dimension = cfg['dimension'] || 'overworld'
  b = biome.to_s.strip.downcase.gsub(/\s+/, '_')
  if dimension == 'nether'
    return Data::NETHER_BIOMES.include?(b) ? b : 'nether_wastes'
  end
  return 'plains' if Data::NETHER_BIOMES.include?(b)

  b
end

.optimal_y_for_mining(cfg) ⇒ Object



76
77
78
79
80
81
# File 'lib/orefinder_estimate/probability.rb', line 76

def optimal_y_for_mining(cfg)
  return cfg['practicalY'] unless cfg['practicalY'].nil?
  return cfg['actualPeakY'] unless cfg['actualPeakY'].nil?

  cfg['optimalY']
end

.triangular_probability(y, min_y, max_y, peak_y) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/orefinder_estimate/probability.rb', line 15

def triangular_probability(y, min_y, max_y, peak_y)
  return 0.0 if y < min_y || y > max_y

  range = max_y - min_y
  return 0.0 if range <= 0

  peak = [[peak_y, min_y].max, max_y].min
  peak_offset = peak - min_y
  fall_len = max_y - peak
  return 0.0 if peak_offset <= 0 && fall_len <= 0

  if y <= peak
    return (y == min_y ? 1.0 : 0.0) if peak_offset <= 0

    return (y - min_y).to_f / peak_offset
  end
  return 0.0 if fall_len <= 0

  (max_y - y).to_f / fall_len
end

.uniform_probability(y, min_y, max_y) ⇒ Object



36
37
38
# File 'lib/orefinder_estimate/probability.rb', line 36

def uniform_probability(y, min_y, max_y)
  y >= min_y && y <= max_y ? 1.0 : 0.0
end