Module: Mgmg::Optimize

Defined in:
lib/mgmg/optimize.rb

Constant Summary collapse

InvList =
[%w|帽子 フード サンダル|.freeze, %w|宝1 骨1 木1 木2 骨2|.freeze, %w|宝1 骨1 木1|.freeze].freeze
MwList =
%w|綿 皮 骨 木 水|.freeze

Class Method Summary collapse

Class Method Details

.buster_optimize(str, smith, comp = smith, opt: Option.new) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/mgmg/optimize.rb', line 161

def buster_optimize(str, smith, comp=smith, opt: Option.new)
  best = ( smith.nil? ? [str, str.poly(:mag_das, opt:)] : [str, str.build(smith, comp, opt:)] )
  str = Mgmg.check_string(str)
  ai = -1
  org = nil
  while str.sub!(/弓\(([骨水綿皮木][12][骨水綿皮木]1)\)/){
    ai += 1
    if ai == 0
      org = $1.dup
    end
    "弓(<A#{ai}>)"
  }; end
  str = str.sub(/<A0>/, org)
  a = Array.new(ai){ [0, 0, 0] }
  while a
    r = bus_apply_idx(str, a)
    best = bus_better(best, ( smith.nil? ? [r, r.poly(:mag_das, opt:)] : [r, r.build(smith, comp, opt:)] ))
    a = bus_next_a(a)
  end
  best[0]
end

.phydef_optimize(str, smith, comp = smith, opt: Option.new) ⇒ Object



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
# File 'lib/mgmg/optimize.rb', line 5

def phydef_optimize(str, smith, comp=smith, opt: Option.new)
  best = if smith.nil? then
    [str, str.poly(:phydef, opt:), str.poly(:magdef, opt:), str.poly(:cost, opt:)]
  else
    [str, str.build(smith, comp, opt:)]
  end
  str = Mgmg.check_string(str)
  ai = 0
  while str.sub!(/(帽子|フード|サンダル)\([宝木骨][12][宝木骨]1\)/){
    ai += 1
    "<A#{ai}>"
  }; end
  bi = 0
  while str.sub!(/[宝木骨]1\)/){
    bi += 1
    "<B#{bi}>)"
  }; end
  skin = false
  m = /([^\+]*\([^\(]+[綿皮]1\))\]*\Z/.match(str)
  if m
    if smith
      if m[1].sub(/綿1\)/, '皮1)').build(smith, opt:).weight == m[1].sub(/皮1\)/, '綿1)').build(smith, opt:).weight
        skin = true
      end
    else
      skin = true
    end
    str = str.sub(/皮(1\)\]*)\Z/) do
      "綿#{$1}"
    end
  end
  a = Array.new(ai){ [0, 0, 0] }
  b0 = Array.new(bi){ 0 }
  while a
    b = b0
    while b
      r = pd_apply_idx(str, a, b)
      best = if smith.nil? then
        pd_better(best, [r, r.poly(:phydef, opt:), r.poly(:magdef, opt:), r.poly(:cost, opt:)], opt.magdef_maximize)
      else
        pd_better(best, [r, r.build(smith, comp, opt:)], opt.magdef_maximize)
      end
      b = pd_next_b(b)
    end
    a = pd_next_a(a)
  end
  if skin
    str = str.sub(/綿(1\)\]*)\Z/) do
      "皮#{$1}"
    end
    a = Array.new(ai){ [0, 0, 0] }
    while a
      b = b0
      while b
        r = pd_apply_idx(str, a, b)
        best = if smith.nil? then
          pd_better(best, [r, r.poly(:phydef, opt:), r.poly(:magdef, opt:), r.poly(:cost, opt:)], opt.magdef_maximize)
        else
          pd_better(best, [r, r.build(smith, comp, opt:)], opt.magdef_maximize)
        end
        b = pd_next_b(b)
      end
      a = pd_next_a(a)
    end
  end
  best[0]
end