mgmg 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/mgmg/cuisine.rb +49 -49
- data/lib/mgmg/equip.rb +181 -171
- data/lib/mgmg/ir.rb +114 -108
- data/lib/mgmg/option.rb +19 -4
- data/lib/mgmg/poly.rb +68 -61
- data/lib/mgmg/reinforce.rb +34 -35
- data/lib/mgmg/utils.rb +3 -4
- data/lib/mgmg/version.rb +1 -1
- data/lib/mgmg.rb +11 -4
- data/reference.md +27 -25
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f3f377aff6ac79ec7111b1b81fcfc5148505ca5f57606be79192f832d80d7c92
|
4
|
+
data.tar.gz: 3cca84c8c97b44f18945d1817a921d42b7702f77a61dff4e8836a52f1a9a0f14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76db175b332d5c5d69ab12f171b734ceb82d4102151b19ce17e710e4776acaabe5e706f0b830eef251a664ae2d702b92d504af6409441da164dd64be1736a19f
|
7
|
+
data.tar.gz: aa9416fcbaca9dc1d631925c4b5b3eb946196d81aab90748567c3c638adba12bf6474a70f1c815806527afe334cad434d841ce19e22350816df443e4c485fbdc
|
data/CHANGELOG.md
CHANGED
@@ -144,3 +144,11 @@
|
|
144
144
|
|
145
145
|
## 1.5.3 2022/06/28
|
146
146
|
- `Recipe#option`がキーワード引数を受け取れなかったバグを修正.
|
147
|
+
|
148
|
+
## 1.5.4 2022/06/30
|
149
|
+
- 既製品の探索を制御する`:include_system_equips`オプションを追加.
|
150
|
+
- 既製品を含まないレシピを計算するとき,これを偽に設定することで,高速化される.
|
151
|
+
- デフォルト値は`true`.ただし,既製品を含まないレシピ文字列を`to_recipe`すると,自動的に`false`に書き換える.
|
152
|
+
- 一部のメソッドで計算結果をキャッシュすることで,同じ材料装備を含む大量のレシピを計算する場合に高速化された.
|
153
|
+
- `Mgmg.#clear_cache`ですべてのキャッシュをクリアできる.
|
154
|
+
- 一部のオプションのデフォルト値をグローバルに変更するための定数ハッシュ`Mgmg::Option::Defaults`を追加.
|
data/lib/mgmg/cuisine.rb
CHANGED
@@ -22,6 +22,55 @@ module Mgmg
|
|
22
22
|
"料理[攻撃:#{self.attack}, 物防:#{self.phydef}, 魔防:#{self.magdef}]"
|
23
23
|
end
|
24
24
|
alias :inspect :to_s
|
25
|
+
|
26
|
+
MainFood = {
|
27
|
+
'獣肉' => Vec[10, 0, 0],
|
28
|
+
'ウッチ' => Vec[ 0, 10, 10],
|
29
|
+
'ゴッチ' => Vec[ 0, 12, 12],
|
30
|
+
'ガガッチ' => Vec[ 0, 14, 14],
|
31
|
+
'ドランギョ' => Vec[15, 15, 10],
|
32
|
+
'ドラバーン' => Vec[20, 20, 15],
|
33
|
+
'フレドラン' => Vec[50, 0, 0],
|
34
|
+
'アースドラン' => Vec[ 0, 50, 0],
|
35
|
+
'アクアドラン' => Vec[ 0, 0, 50],
|
36
|
+
'ダークドン' => Vec[30, 30, 30],
|
37
|
+
}
|
38
|
+
SubFood = {
|
39
|
+
'氷酒' => Vec[ 50, 70, 50],
|
40
|
+
'氷水酒' => Vec[ 50, 90, 50],
|
41
|
+
'氷河酒' => Vec[ 50, 110, 50],
|
42
|
+
'カエン酒' => Vec[ 70, 50, 70],
|
43
|
+
'爆炎酒' => Vec[ 90, 50, 90],
|
44
|
+
'煉獄酒' => Vec[110, 50, 110],
|
45
|
+
}
|
46
|
+
Cookery = {
|
47
|
+
'焼き' => Vec[50, 50, 30],
|
48
|
+
'蒸す' => Vec[30, 75, 75],
|
49
|
+
}
|
50
|
+
Cookery.store('丸焼き', Cookery['焼き'])
|
51
|
+
Cookery.store('すき焼き', Cookery['焼き'])
|
52
|
+
Cookery.store('焼く', Cookery['焼き'])
|
53
|
+
Cookery.store('焼', Cookery['焼き'])
|
54
|
+
Cookery.store('蒸し焼き', Cookery['蒸す'])
|
55
|
+
Cookery.store('ボイル', Cookery['蒸す'])
|
56
|
+
Cookery.store('蒸し', Cookery['蒸す'])
|
57
|
+
Cookery.store('蒸', Cookery['蒸す'])
|
58
|
+
|
59
|
+
class << self
|
60
|
+
def cook(cookery_s, main_s, sub_s, level)
|
61
|
+
begin
|
62
|
+
c = Cookery[cookery_s]
|
63
|
+
m = MainFood[main_s]
|
64
|
+
s = SubFood[sub_s]
|
65
|
+
v = Vec[1, 1, 1]
|
66
|
+
v.e_mul!(m).e_mul!(c).e_mul!(s.dup.add!(100+level)).e_div!(10000)
|
67
|
+
new(v)
|
68
|
+
rescue
|
69
|
+
arg = [cookery_s, main_s, sub_s, level].inspect
|
70
|
+
raise ArgumentError, "Some of arguments for cooking seems to be wrong. #{arg} is given, but they should be [cookery (String), main food (String), sub food (String), cooking level (Integer)]. Not all of cookeries and foods are supported."
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
25
74
|
end
|
26
75
|
|
27
76
|
SystemCuisine = {
|
@@ -72,55 +121,6 @@ module Mgmg
|
|
72
121
|
end
|
73
122
|
end
|
74
123
|
|
75
|
-
MainFood = {
|
76
|
-
'獣肉' => Vec[10, 0, 0],
|
77
|
-
'ウッチ' => Vec[ 0, 10, 10],
|
78
|
-
'ゴッチ' => Vec[ 0, 12, 12],
|
79
|
-
'ガガッチ' => Vec[ 0, 14, 14],
|
80
|
-
'ドランギョ' => Vec[15, 15, 10],
|
81
|
-
'ドラバーン' => Vec[20, 20, 15],
|
82
|
-
'フレドラン' => Vec[50, 0, 0],
|
83
|
-
'アースドラン' => Vec[ 0, 50, 0],
|
84
|
-
'アクアドラン' => Vec[ 0, 0, 50],
|
85
|
-
'ダークドン' => Vec[30, 30, 30],
|
86
|
-
}
|
87
|
-
SubFood = {
|
88
|
-
'氷酒' => Vec[ 50, 70, 50],
|
89
|
-
'氷水酒' => Vec[ 50, 90, 50],
|
90
|
-
'氷河酒' => Vec[ 50, 110, 50],
|
91
|
-
'カエン酒' => Vec[ 70, 50, 70],
|
92
|
-
'爆炎酒' => Vec[ 90, 50, 90],
|
93
|
-
'煉獄酒' => Vec[110, 50, 110],
|
94
|
-
}
|
95
|
-
Cookery = {
|
96
|
-
'焼き' => Vec[50, 50, 30],
|
97
|
-
'蒸す' => Vec[30, 75, 75],
|
98
|
-
}
|
99
|
-
Cookery.store('丸焼き', Cookery['焼き'])
|
100
|
-
Cookery.store('すき焼き', Cookery['焼き'])
|
101
|
-
Cookery.store('焼く', Cookery['焼き'])
|
102
|
-
Cookery.store('焼', Cookery['焼き'])
|
103
|
-
Cookery.store('蒸し焼き', Cookery['蒸す'])
|
104
|
-
Cookery.store('ボイル', Cookery['蒸す'])
|
105
|
-
Cookery.store('蒸し', Cookery['蒸す'])
|
106
|
-
Cookery.store('蒸', Cookery['蒸す'])
|
107
|
-
|
108
|
-
class << Cuisine
|
109
|
-
def cook(cookery_s, main_s, sub_s, level)
|
110
|
-
begin
|
111
|
-
c = Cookery[cookery_s]
|
112
|
-
m = MainFood[main_s]
|
113
|
-
s = SubFood[sub_s]
|
114
|
-
v = Vec[1, 1, 1]
|
115
|
-
v.e_mul!(m).e_mul!(c).e_mul!(s.dup.add!(100+level)).e_div!(10000)
|
116
|
-
new(v)
|
117
|
-
rescue
|
118
|
-
arg = [cookery_s, main_s, sub_s, level].inspect
|
119
|
-
raise ArgumentError, "Some of arguments for cooking seems to be wrong. #{arg} is given, but they should be [cookery (String), main food (String), sub food (String), cooking level (Integer)]. Not all of cookeries and foods are supported."
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
124
|
module_function def cuisine(*arg)
|
125
125
|
case arg.size
|
126
126
|
when 3
|
data/lib/mgmg/equip.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Mgmg
|
2
|
+
CacheMLS = Hash.new
|
2
3
|
using Refiner
|
3
4
|
class Equip
|
5
|
+
Cache, CacheML = Hash.new, Hash.new
|
4
6
|
ParamList = %w|攻撃 物防 魔防 HP MP 腕力 器用 素早 魔力|
|
5
7
|
ElementList = %w|火 地 水|
|
6
8
|
EqPosList = %w|武 頭 胴 腕 足 飾|
|
@@ -196,195 +198,203 @@ module Mgmg
|
|
196
198
|
Zero = self.new(28, 0, Vec.new(6, 0).freeze, 12, 12, Vec.new(9, 0).freeze, Vec.new(3, 0).freeze)
|
197
199
|
Zero.total_cost.freeze; Zero.history.clear.freeze
|
198
200
|
Zero.freeze
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
end
|
207
|
-
private def build_sub0(stack, str)
|
208
|
-
SystemEquip.each do |k, v|
|
209
|
-
if SystemEquipRegexp[k].match(str)
|
210
|
-
stack << v
|
211
|
-
str = str.gsub(k, "<#{stack.length-1}>")
|
212
|
-
end
|
201
|
+
|
202
|
+
class << self
|
203
|
+
def build(str, s_level, c_level, left_associative: true, include_system_equips: true)
|
204
|
+
str = Mgmg.check_string(str)
|
205
|
+
stack = []
|
206
|
+
stack, str = build_sub0(stack, str) if include_system_equips
|
207
|
+
build_sub(stack, str, s_level, c_level, left_associative)
|
213
208
|
end
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
elsif m = ( lassoc ? /\A(.+)\+(.+?)\Z/ : /\A(.+?)\+(.+)\Z/ ).match(str)
|
221
|
-
if c_level < 0
|
222
|
-
compose(build_sub(stack, m[1], s_level, c_level, lassoc), build_sub(stack, m[2], s_level, c_level, lassoc), 0, true)
|
223
|
-
else
|
224
|
-
compose(build_sub(stack, m[1], s_level, c_level, lassoc), build_sub(stack, m[2], s_level, c_level, lassoc), c_level, false)
|
209
|
+
private def build_sub0(stack, str)
|
210
|
+
SystemEquip.each do |k, v|
|
211
|
+
if SystemEquipRegexp[k].match(str)
|
212
|
+
stack << v
|
213
|
+
str = str.gsub(k, "<#{stack.length-1}>")
|
214
|
+
end
|
225
215
|
end
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
if
|
230
|
-
|
216
|
+
[stack, str]
|
217
|
+
end
|
218
|
+
private def build_sub(stack, str, s_level, c_level, lassoc)
|
219
|
+
if m = /\A(.*\+?)\[([^\[\]]+)\](\+?[^\[]*)\Z/.match(str)
|
220
|
+
stack << build_sub(stack, m[2], s_level, c_level, lassoc)
|
221
|
+
build_sub(stack, "#{m[1]}<#{stack.length-1}>#{m[3]}", s_level, c_level, lassoc)
|
222
|
+
elsif m = ( lassoc ? /\A(.+)\+(.+?)\Z/ : /\A(.+?)\+(.+)\Z/ ).match(str)
|
223
|
+
if c_level < 0
|
224
|
+
compose(build_sub(stack, m[1], s_level, c_level, lassoc), build_sub(stack, m[2], s_level, c_level, lassoc), 0, true)
|
225
|
+
else
|
226
|
+
compose(build_sub(stack, m[1], s_level, c_level, lassoc), build_sub(stack, m[2], s_level, c_level, lassoc), c_level, false)
|
227
|
+
end
|
228
|
+
elsif m = /\A\<(\d+)\>\Z/.match(str)
|
229
|
+
stack[m[1].to_i]
|
231
230
|
else
|
232
|
-
|
231
|
+
if s_level < 0
|
232
|
+
smith(str, 0, true)
|
233
|
+
else
|
234
|
+
smith(str, s_level, false)
|
235
|
+
end
|
233
236
|
end
|
234
237
|
end
|
235
|
-
end
|
236
|
-
|
237
|
-
def compose(main, sub, level, outsourcing)
|
238
|
-
main_k, sub_k = main.kind, sub.kind
|
239
|
-
main_s, sub_s = main.star, sub.star
|
240
|
-
main_main, sub_main = main.main, sub.main
|
241
|
-
main_sub, sub_sub = main.sub, sub.sub
|
242
|
-
para = Vec.new(9, 0)
|
243
|
-
ele = Vec.new(3, 0)
|
244
|
-
|
245
|
-
# 9パラメータ
|
246
|
-
coef = Equip9[main_k].dup
|
247
|
-
para[] = coef
|
248
|
-
para.add!(level).e_div!(2)
|
249
|
-
para.e_mul!(sub.para).e_div!(100)
|
250
|
-
coef.sub!(Equip9[sub_k])
|
251
|
-
coef.add!( 100 + (main_s-sub_s)*5 - ( ( main_main==sub_main && main_main != 9 ) ? 30 : 0 ) )
|
252
|
-
coef.add!(Material9[main_main]).sub!(Material9[sub_main])
|
253
|
-
coef.e_mul!(EquipFilter[main_k])
|
254
|
-
para.e_mul!(coef).e_div!( main_k==sub_k ? 200 : 100 )
|
255
|
-
para.add!(main.para)
|
256
238
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
239
|
+
def compose(main, sub, level, outsourcing)
|
240
|
+
main_k, sub_k = main.kind, sub.kind
|
241
|
+
main_s, sub_s = main.star, sub.star
|
242
|
+
main_main, sub_main = main.main, sub.main
|
243
|
+
main_sub, sub_sub = main.sub, sub.sub
|
244
|
+
para = Vec.new(9, 0)
|
245
|
+
ele = Vec.new(3, 0)
|
246
|
+
|
247
|
+
# 9パラメータ
|
248
|
+
coef = Equip9[main_k].dup
|
249
|
+
para[] = coef
|
250
|
+
para.add!(level).e_div!(2)
|
251
|
+
para.e_mul!(sub.para).e_div!(100)
|
252
|
+
coef.sub!(Equip9[sub_k])
|
253
|
+
coef.add!( 100 + (main_s-sub_s)*5 - ( ( main_main==sub_main && main_main != 9 ) ? 30 : 0 ) )
|
254
|
+
coef.add!(Material9[main_main]).sub!(Material9[sub_main])
|
255
|
+
coef.e_mul!(EquipFilter[main_k])
|
256
|
+
para.e_mul!(coef).e_div!( main_k==sub_k ? 200 : 100 )
|
257
|
+
para.add!(main.para)
|
258
|
+
|
259
|
+
# エレメント
|
260
|
+
ele[] = sub.element
|
261
|
+
ele.e_mul!([75, level].min).e_div!( main_k==sub_k ? 200 : 100 )
|
262
|
+
ele.add!(main.element)
|
263
|
+
|
264
|
+
ret = new(main_k, main.weight+sub.weight, main_s+sub_s, main_sub, sub_main, para, ele)
|
265
|
+
ret.total_cost.add!(main.total_cost).add!(sub.total_cost)
|
266
|
+
cc = ret.comp_cost(outsourcing)
|
267
|
+
ret.total_cost[1] += cc
|
268
|
+
ret.total_cost[main_k < 8 ? 0 : 2] += cc
|
269
|
+
ret.min_levels.merge!(main.min_levels, sub.min_levels)
|
270
|
+
ret.history = [*main.history, *sub.history, ret]
|
271
|
+
ret
|
280
272
|
end
|
281
|
-
main_m, main_s, main_mc = Mgmg.parse_material(m[2])
|
282
|
-
sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
|
283
|
-
para = Vec.new(9, 0)
|
284
|
-
ele = Vec.new(3, 0)
|
285
273
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
274
|
+
def smith(str, level, outsourcing)
|
275
|
+
str = Mgmg.check_string(str)
|
276
|
+
return Cache[str].dup if level==0 && Cache.has_key?(str)
|
277
|
+
unless m = /\A(.+)\((.+\d+),?(.+\d+)\)\Z/.match(str)
|
278
|
+
raise InvalidSmithError.new(str)
|
279
|
+
end
|
280
|
+
kind = EquipIndex[m[1].to_sym]
|
281
|
+
unless kind
|
282
|
+
raise InvalidEquipClassError.new(m[1])
|
283
|
+
end
|
284
|
+
main_m, main_s, main_mc = Mgmg.parse_material(m[2])
|
285
|
+
sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
|
286
|
+
para = Vec.new(9, 0)
|
287
|
+
ele = Vec.new(3, 0)
|
288
|
+
|
289
|
+
# 9パラメータ
|
290
|
+
para[] = Equip9[kind]
|
291
|
+
para.e_mul!(Main9[main_m]).e_div!(100)
|
292
|
+
coef = Sub9[sub_m].dup
|
293
|
+
coef.add!(level)
|
294
|
+
para.e_mul!(coef).e_div!( main_mc==sub_mc ? 200 : 100 )
|
295
|
+
|
296
|
+
# エレメント
|
297
|
+
ele[] = MainEL[main_m]
|
298
|
+
ele.e_mul!(SubEL[sub_m]).e_div!(6)
|
299
|
+
|
300
|
+
# 重量
|
301
|
+
weight = ( ( EquipWeight[kind] + SubWeight[sub_m] - level.div(2) ) * ( MainWeight[main_m] ) ).div(10000)
|
302
|
+
|
303
|
+
ret = new(kind, ( weight<1 ? 1 : weight ), (main_s+sub_s).div(2), main_mc, sub_mc, para, ele)
|
304
|
+
ret.total_cost[kind < 8 ? 0 : 2] += ret.smith_cost(outsourcing)
|
305
|
+
ret.min_levels.store(str, Equip.min_level(str))
|
306
|
+
Cache.store(str, ret.freeze) if level==0
|
307
|
+
ret.dup
|
310
308
|
end
|
311
|
-
kind = EquipIndex[m[1].to_sym]
|
312
|
-
main_m, main_s, = Mgmg.parse_material(m[2])
|
313
|
-
sub_m, sub_s, = Mgmg.parse_material(m[3])
|
314
309
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
def min_comp(str, opt: Option.new)
|
321
|
-
str = Mgmg.check_string(str)
|
322
|
-
stack, str = minc_sub0([], str)
|
323
|
-
(minc_sub(stack, str, opt.left_associative)[1]-1)*3
|
324
|
-
end
|
325
|
-
private def minc_sub0(stack, str)
|
326
|
-
SystemEquip.each do |k, v|
|
327
|
-
if SystemEquipRegexp[k].match(str)
|
328
|
-
stack << v.star
|
329
|
-
str = str.gsub(k, "<#{stack.length-1}>")
|
310
|
+
def min_level(str, weight=1)
|
311
|
+
str = Mgmg.check_string(str)
|
312
|
+
return CacheML[str] if CacheML.has_key?(str)
|
313
|
+
unless m = /\A(.+)\((.+\d+),?(.+\d+)\)\Z/.match(str)
|
314
|
+
raise InvalidSmithError.new(str)
|
330
315
|
end
|
316
|
+
kind = EquipIndex[m[1].to_sym]
|
317
|
+
main_m, main_s, = Mgmg.parse_material(m[2])
|
318
|
+
sub_m, sub_s, = Mgmg.parse_material(m[3])
|
319
|
+
|
320
|
+
q, r = ((weight+1)*10000).divmod(MainWeight[main_m])
|
321
|
+
l = ( EquipWeight[kind] + SubWeight[sub_m] - q + ( r==0 ? 1 : 0 ) )*2
|
322
|
+
ret = [(main_s-1)*3, (sub_s-1)*3, l].max
|
323
|
+
CacheML.store(str, ret)
|
324
|
+
ret
|
331
325
|
end
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
stack
|
337
|
-
minc_sub(stack,
|
338
|
-
elsif m = ( lassoc ? /\A(.+)\+(.+?)\Z/ : /\A(.+?)\+(.+)\Z/ ).match(str)
|
339
|
-
a, _ = minc_sub(stack, m[1], lassoc)
|
340
|
-
b, _ = minc_sub(stack, m[2], lassoc)
|
341
|
-
[a+b, [a, b].max]
|
342
|
-
elsif m = /\A\<(\d+)\>\Z/.match(str)
|
343
|
-
[stack[m[1].to_i], 1]
|
344
|
-
else
|
345
|
-
[smith(str, 0, true).star, 1]
|
326
|
+
|
327
|
+
def min_comp(str, opt: Option.new)
|
328
|
+
str = Mgmg.check_string(str)
|
329
|
+
stack = []
|
330
|
+
stack, str = minc_sub0(stack, str) if opt.include_system_equips
|
331
|
+
(minc_sub(stack, str, opt.left_associative)[1]-1)*3
|
346
332
|
end
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
ret < 0 ? -1 : ret
|
354
|
-
end
|
355
|
-
private def mins_sub0(stack, str)
|
356
|
-
SystemEquip.each do |k, v|
|
357
|
-
if SystemEquipRegexp[k].match(str)
|
358
|
-
stack << 0
|
359
|
-
str = str.gsub(k, "<#{stack.length-1}>")
|
333
|
+
private def minc_sub0(stack, str)
|
334
|
+
SystemEquip.each do |k, v|
|
335
|
+
if SystemEquipRegexp[k].match(str)
|
336
|
+
stack << v.star
|
337
|
+
str = str.gsub(k, "<#{stack.length-1}>")
|
338
|
+
end
|
360
339
|
end
|
340
|
+
[stack, str]
|
361
341
|
end
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
342
|
+
private def minc_sub(stack, str, lassoc)
|
343
|
+
if m = /\A(.*\+?)\[([^\[\]]+)\](\+?[^\[]*)\Z/.match(str)
|
344
|
+
stack << minc_sub(stack, m[2], lassoc)[0]
|
345
|
+
minc_sub(stack, "#{m[1]}<#{stack.length-1}>#{m[3]}", lassoc)
|
346
|
+
elsif m = ( lassoc ? /\A(.+)\+(.+?)\Z/ : /\A(.+?)\+(.+)\Z/ ).match(str)
|
347
|
+
a, _ = minc_sub(stack, m[1], lassoc)
|
348
|
+
b, _ = minc_sub(stack, m[2], lassoc)
|
349
|
+
[a+b, [a, b].max]
|
350
|
+
elsif m = /\A\<(\d+)\>\Z/.match(str)
|
351
|
+
[stack[m[1].to_i], 1]
|
352
|
+
else
|
353
|
+
[smith(str, 0, true).star, 1]
|
354
|
+
end
|
374
355
|
end
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
356
|
+
|
357
|
+
def min_smith(str, opt: Option.new)
|
358
|
+
str = Mgmg.check_string(str)
|
359
|
+
stack = []
|
360
|
+
stack, str = mins_sub0(stack, str) if opt.include_system_equips
|
361
|
+
ret = (([mins_sub(stack, str, opt.left_associative)]+stack).max-1)*3
|
362
|
+
ret < 0 ? -1 : ret
|
380
363
|
end
|
381
|
-
|
382
|
-
|
383
|
-
|
364
|
+
private def mins_sub0(stack, str)
|
365
|
+
SystemEquip.each do |k, v|
|
366
|
+
if SystemEquipRegexp[k].match(str)
|
367
|
+
stack << 0
|
368
|
+
str = str.gsub(k, "<#{stack.length-1}>")
|
369
|
+
end
|
370
|
+
end
|
371
|
+
[stack, str]
|
372
|
+
end
|
373
|
+
private def mins_sub(stack, str, lassoc)
|
374
|
+
if m = /\A(.*\+?)\[([^\[\]]+)\](\+?[^\[]*)\Z/.match(str)
|
375
|
+
stack << mins_sub(stack, m[2], lassoc)
|
376
|
+
mins_sub(stack, "#{m[1]}<#{stack.length-1}>#{m[3]}", lassoc)
|
377
|
+
elsif m = ( lassoc ? /\A(.+)\+(.+?)\Z/ : /\A(.+?)\+(.+)\Z/ ).match(str)
|
378
|
+
[mins_sub(stack, m[1], lassoc), mins_sub(stack, m[2], lassoc)].max
|
379
|
+
elsif m = /\A\<(\d+)\>\Z/.match(str)
|
380
|
+
0
|
381
|
+
else
|
382
|
+
mins_sub2(str)
|
383
|
+
end
|
384
|
+
end
|
385
|
+
private def mins_sub2(str)
|
386
|
+
str = Mgmg.check_string(str)
|
387
|
+
unless m = /\A(.+)\((.+\d+),?(.+\d+)\)\Z/.match(str)
|
388
|
+
raise InvalidSmithError.new(str)
|
389
|
+
end
|
390
|
+
kind = EquipIndex[m[1].to_sym]
|
391
|
+
unless kind
|
392
|
+
raise InvalidEquipClassError.new(m[1])
|
393
|
+
end
|
394
|
+
main_m, main_s, main_mc = Mgmg.parse_material(m[2])
|
395
|
+
sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
|
396
|
+
[main_s, sub_s].max
|
384
397
|
end
|
385
|
-
main_m, main_s, main_mc = Mgmg.parse_material(m[2])
|
386
|
-
sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
|
387
|
-
[main_s, sub_s].max
|
388
398
|
end
|
389
399
|
end
|
390
400
|
end
|
data/lib/mgmg/ir.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Mgmg
|
2
2
|
using Refiner
|
3
3
|
class IR
|
4
|
+
Cache = Hash.new
|
4
5
|
class Const
|
5
6
|
def initialize(value)
|
6
7
|
@value = value
|
@@ -94,44 +95,44 @@ module Mgmg
|
|
94
95
|
def to_s
|
95
96
|
@body.map(&:to_s).join('+')
|
96
97
|
end
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
98
|
+
class << self
|
99
|
+
def sum(a, b)
|
100
|
+
unconsts, const = [], Const.new(0)
|
101
|
+
case a
|
102
|
+
when Multi
|
103
|
+
if a.body[0].kind_of?(Const)
|
104
|
+
const.value += a.body[0].value
|
105
|
+
unconsts = a.body[1..(-1)]
|
106
|
+
else
|
107
|
+
unconsts = a.body.dup
|
108
|
+
end
|
109
|
+
when Const
|
110
|
+
const.value += a.value
|
106
111
|
else
|
107
|
-
unconsts
|
112
|
+
unconsts << a
|
108
113
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
114
|
+
case b
|
115
|
+
when Multi
|
116
|
+
if b.body[0].kind_of?(Const)
|
117
|
+
const.value += b.body[0].value
|
118
|
+
unconsts.concat(b.body[1..(-1)])
|
119
|
+
else
|
120
|
+
unconsts.concat(b.body)
|
121
|
+
end
|
122
|
+
when Const
|
123
|
+
const.value += b.value
|
119
124
|
else
|
120
|
-
unconsts
|
125
|
+
unconsts << b
|
126
|
+
end
|
127
|
+
body = ( const.value == 0 ? unconsts : [const, *unconsts] )
|
128
|
+
case body.size
|
129
|
+
when 0
|
130
|
+
const
|
131
|
+
when 1
|
132
|
+
body[0]
|
133
|
+
else
|
134
|
+
new(body)
|
121
135
|
end
|
122
|
-
when Const
|
123
|
-
const.value += b.value
|
124
|
-
else
|
125
|
-
unconsts << b
|
126
|
-
end
|
127
|
-
body = ( const.value == 0 ? unconsts : [const, *unconsts] )
|
128
|
-
case body.size
|
129
|
-
when 0
|
130
|
-
const
|
131
|
-
when 1
|
132
|
-
body[0]
|
133
|
-
else
|
134
|
-
new(body)
|
135
136
|
end
|
136
137
|
end
|
137
138
|
end
|
@@ -315,87 +316,92 @@ module Mgmg
|
|
315
316
|
end
|
316
317
|
Zero = self.new(28, Vec.new(6, 0).freeze, 12, 12, Array.new(9){Const.new(0)}.freeze)
|
317
318
|
Zero.rein.freeze; Zero.freeze
|
318
|
-
end
|
319
|
-
class << IR
|
320
|
-
def build(str, left_associative: true, reinforcement: [])
|
321
|
-
str = Mgmg.check_string(str)
|
322
|
-
stack, str = build_sub0([], str)
|
323
|
-
build_sub(stack, str, left_associative).add_reinforcement(reinforcement)
|
324
|
-
end
|
325
|
-
private def build_sub0(stack, str)
|
326
|
-
SystemEquip.each do |k, v|
|
327
|
-
if SystemEquipRegexp[k].match(str)
|
328
|
-
stack << from_equip(v)
|
329
|
-
str = str.gsub(k, "<#{stack.length-1}>")
|
330
|
-
end
|
331
|
-
end
|
332
|
-
[stack, str]
|
333
|
-
end
|
334
|
-
private def build_sub(stack, str, lassoc)
|
335
|
-
if m = /\A(.*\+?)\[([^\[\]]+)\](\+?[^\[]*)\Z/.match(str)
|
336
|
-
stack << build_sub(stack, m[2], lassoc)
|
337
|
-
build_sub(stack, "#{m[1]}<#{stack.length-1}>#{m[3]}", lassoc)
|
338
|
-
elsif m = ( lassoc ? /\A(.+)\+(.+?)\Z/ : /\A(.+?)\+(.+)\Z/ ).match(str)
|
339
|
-
compose(build_sub(stack, m[1], lassoc), build_sub(stack, m[2], lassoc))
|
340
|
-
elsif m = /\A\<(\d+)\>\Z/.match(str)
|
341
|
-
stack[m[1].to_i]
|
342
|
-
else
|
343
|
-
smith(str)
|
344
|
-
end
|
345
|
-
end
|
346
319
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
main.para[i]
|
361
|
-
else
|
362
|
-
Mgmg::IR::Compose.new(main.para[i], sub.para[i], Equip9[main_k][i], coef[i], den)
|
320
|
+
class << self
|
321
|
+
def build(str, left_associative: true, reinforcement: [], include_system_equips: true)
|
322
|
+
str = Mgmg.check_string(str)
|
323
|
+
stack = []
|
324
|
+
stack, str = build_sub0(stack, str) if include_system_equips
|
325
|
+
build_sub(stack, str, left_associative).add_reinforcement(reinforcement)
|
326
|
+
end
|
327
|
+
private def build_sub0(stack, str)
|
328
|
+
SystemEquip.each do |k, v|
|
329
|
+
if SystemEquipRegexp[k].match(str)
|
330
|
+
stack << from_equip(v)
|
331
|
+
str = str.gsub(k, "<#{stack.length-1}>")
|
332
|
+
end
|
363
333
|
end
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
unless kind
|
375
|
-
raise InvalidEquipClassError.new(m[1])
|
376
|
-
end
|
377
|
-
main_m, main_s, main_mc = Mgmg.parse_material(m[2])
|
378
|
-
sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
|
379
|
-
sa = ( Mgmg::EquipPosition[kind] == 0 ? :s : :a )
|
380
|
-
|
381
|
-
coef = Equip9[kind].dup
|
382
|
-
coef.e_mul!(Main9[main_m]).e_div!(100)
|
383
|
-
den = ( main_mc==sub_mc ? 200 : 100 )
|
384
|
-
para = Array.new(9) do |i|
|
385
|
-
if coef[i] == 0
|
386
|
-
Mgmg::IR::Const.new(0)
|
334
|
+
[stack, str]
|
335
|
+
end
|
336
|
+
private def build_sub(stack, str, lassoc)
|
337
|
+
if m = /\A(.*\+?)\[([^\[\]]+)\](\+?[^\[]*)\Z/.match(str)
|
338
|
+
stack << build_sub(stack, m[2], lassoc)
|
339
|
+
build_sub(stack, "#{m[1]}<#{stack.length-1}>#{m[3]}", lassoc)
|
340
|
+
elsif m = ( lassoc ? /\A(.+)\+(.+?)\Z/ : /\A(.+?)\+(.+)\Z/ ).match(str)
|
341
|
+
compose(build_sub(stack, m[1], lassoc), build_sub(stack, m[2], lassoc))
|
342
|
+
elsif m = /\A\<(\d+)\>\Z/.match(str)
|
343
|
+
stack[m[1].to_i]
|
387
344
|
else
|
388
|
-
|
345
|
+
smith(str)
|
389
346
|
end
|
390
347
|
end
|
391
348
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
349
|
+
def compose(main, sub)
|
350
|
+
main_k, sub_k = main.kind, sub.kind
|
351
|
+
main_s, sub_s = main.star, sub.star
|
352
|
+
main_main, sub_main = main.main, sub.main
|
353
|
+
main_sub, sub_sub = main.sub, sub.sub
|
354
|
+
|
355
|
+
coef = Equip9[main_k].dup
|
356
|
+
coef.sub!(Equip9[sub_k])
|
357
|
+
coef.add!( 100 + (main_s-sub_s)*5 - ( ( main_main==sub_main && main_main != 9 ) ? 30 : 0 ) )
|
358
|
+
coef.add!(Material9[main_main]).sub!(Material9[sub_main])
|
359
|
+
den = ( main_k==sub_k ? 200 : 100 )
|
360
|
+
para = Array.new(9) do |i|
|
361
|
+
if EquipFilter[main_k][i] == 0
|
362
|
+
main.para[i]
|
363
|
+
else
|
364
|
+
Mgmg::IR::Compose.new(main.para[i], sub.para[i], Equip9[main_k][i], coef[i], den)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
new(main_k, main_s+sub_s, main_sub, sub_main, para)
|
369
|
+
end
|
370
|
+
def smith(str)
|
371
|
+
str = Mgmg.check_string(str)
|
372
|
+
return Cache[str].dup if Cache.has_key?(str)
|
373
|
+
unless m = /\A(.+)\((.+\d+),?(.+\d+)\)\Z/.match(str)
|
374
|
+
raise InvalidSmithError.new(str)
|
375
|
+
end
|
376
|
+
kind = EquipIndex[m[1].to_sym]
|
377
|
+
unless kind
|
378
|
+
raise InvalidEquipClassError.new(m[1])
|
379
|
+
end
|
380
|
+
main_m, main_s, main_mc = Mgmg.parse_material(m[2])
|
381
|
+
sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
|
382
|
+
sa = ( Mgmg::EquipPosition[kind] == 0 ? :s : :a )
|
383
|
+
|
384
|
+
coef = Equip9[kind].dup
|
385
|
+
coef.e_mul!(Main9[main_m]).e_div!(100)
|
386
|
+
den = ( main_mc==sub_mc ? 200 : 100 )
|
387
|
+
para = Array.new(9) do |i|
|
388
|
+
if coef[i] == 0
|
389
|
+
Mgmg::IR::Const.new(0)
|
390
|
+
else
|
391
|
+
Mgmg::IR::Smith.new(Sub9[sub_m][i], coef[i], den, sa)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
ret = new(kind, (main_s+sub_s).div(2), main_mc, sub_mc, para)
|
396
|
+
Cache.store(str, ret.freeze)
|
397
|
+
ret.dup
|
398
|
+
end
|
399
|
+
def from_equip(equip)
|
400
|
+
para = equip.para.map do |value|
|
401
|
+
Mgmg::IR::Const.new(value)
|
402
|
+
end
|
403
|
+
new(equip.kind, equip.star, equip.main, equip.sub, para)
|
397
404
|
end
|
398
|
-
new(equip.kind, equip.star, equip.main, equip.sub, para)
|
399
405
|
end
|
400
406
|
end
|
401
407
|
end
|
data/lib/mgmg/option.rb
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
module Mgmg
|
2
2
|
class Option
|
3
|
+
Defaults = {
|
4
|
+
left_associative: true, include_system_equips: true,
|
5
|
+
smith_max: 10000, armor_max: 10000, comp_max: 10000
|
6
|
+
}
|
3
7
|
def initialize(
|
4
|
-
left_associative:
|
5
|
-
smith_min: nil, armor_min:nil, comp_min: nil, smith_max:
|
8
|
+
left_associative: Defaults[:left_associative],
|
9
|
+
smith_min: nil, armor_min:nil, comp_min: nil, smith_max: Defaults[:smith_max], armor_max: Defaults[:armor_max], comp_max: Defaults[:comp_max],
|
6
10
|
step: 1, magdef_maximize: true,
|
7
11
|
target_weight: 0, reinforcement: [], buff: nil,
|
8
|
-
irep: nil, cut_exp: Float::INFINITY
|
12
|
+
irep: nil, cut_exp: Float::INFINITY,
|
13
|
+
include_system_equips: Defaults[:include_system_equips]
|
9
14
|
)
|
10
15
|
@left_associative = left_associative
|
11
16
|
@smith_min = smith_min
|
@@ -27,9 +32,10 @@ module Mgmg
|
|
27
32
|
end
|
28
33
|
@irep = irep
|
29
34
|
@cut_exp = cut_exp
|
35
|
+
@include_system_equips = include_system_equips
|
30
36
|
end
|
31
37
|
attr_accessor :left_associative, :smith_min, :armor_min, :comp_min, :smith_max, :armor_max, :comp_max
|
32
|
-
attr_accessor :step, :magdef_maximize, :target_weight, :reinforcement, :irep, :cut_exp
|
38
|
+
attr_accessor :step, :magdef_maximize, :target_weight, :reinforcement, :irep, :cut_exp, :include_system_equips
|
33
39
|
def initialize_copy(other)
|
34
40
|
@left_associative = other.left_associative
|
35
41
|
@smith_min = other.smith_min
|
@@ -44,6 +50,7 @@ module Mgmg
|
|
44
50
|
@reinforcement = other.reinforcement.dup
|
45
51
|
@irep = other.irep
|
46
52
|
@cut_exp = other.cut_exp
|
53
|
+
@include_system_equips = other.include_system_equips
|
47
54
|
end
|
48
55
|
def update_sa_min(recipe, force=true)
|
49
56
|
case recipe
|
@@ -69,9 +76,11 @@ module Mgmg
|
|
69
76
|
self
|
70
77
|
end
|
71
78
|
def set_default(recipe, force: false)
|
79
|
+
@include_system_equips = false if @include_system_equips && !Mgmg::SystemEquipRegexp.values.any?{|re| re.match(recipe)}
|
72
80
|
update_sa_min(recipe, force)
|
73
81
|
@comp_min = recipe.min_comp(opt: self) if force || @comp_min.nil?
|
74
82
|
@irep = recipe.ir(opt: self) if force || @irep.nil?
|
83
|
+
|
75
84
|
self
|
76
85
|
end
|
77
86
|
def buff
|
@@ -81,4 +90,10 @@ module Mgmg
|
|
81
90
|
@reinforcement = v
|
82
91
|
end
|
83
92
|
end
|
93
|
+
|
94
|
+
module_function def option(recipe=nil, **kw)
|
95
|
+
ret = Option.new(**kw)
|
96
|
+
ret.set_default(recipe) unless recipe.nil?
|
97
|
+
ret
|
98
|
+
end
|
84
99
|
end
|
data/lib/mgmg/poly.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Mgmg
|
2
2
|
using Refiner
|
3
3
|
class TPolynomial
|
4
|
+
Cache = Hash.new
|
4
5
|
def initialize(mat, kind, star, main_m, sub_m)
|
5
6
|
@mat, @kind, @star, @main, @sub = mat, kind, star, main_m, sub_m
|
6
7
|
end
|
@@ -285,71 +286,77 @@ module Mgmg
|
|
285
286
|
1
|
286
287
|
end
|
287
288
|
end
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
end
|
296
|
-
def from_equip(equip, para)
|
297
|
-
new(Mat.new(1, 1, equip.para[ParamIndex[para]]), equip.kind, equip.star, equip.main, equip.sub)
|
298
|
-
end
|
299
|
-
def smith(str, para)
|
300
|
-
unless m = /\A(.+)\((.+\d+),?(.+\d+)\)\Z/.match(str)
|
301
|
-
raise ArgumentError.new("given string `#{str}' is unparsable as a smithing recipe")
|
289
|
+
|
290
|
+
class << self
|
291
|
+
ParamIndex = Hash.new
|
292
|
+
%i|attack phydef magdef hp mp str dex speed magic|.each.with_index do |s, i|
|
293
|
+
ParamIndex.store(s, i)
|
294
|
+
ParamIndex.store(i, i)
|
295
|
+
ParamIndex.store(Equip::ParamList[i], i)
|
302
296
|
end
|
303
|
-
|
304
|
-
|
305
|
-
sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
|
306
|
-
para = ParamIndex[para]
|
307
|
-
|
308
|
-
c = ( Equip9[kind][para] * Main9[main_m][para] ).cdiv(100).quo( main_mc==sub_mc ? 200 : 100 )
|
309
|
-
new(Mat.v_array(c*Sub9[sub_m][para], c), kind, (main_s+sub_s).div(2), main_mc, sub_mc)
|
310
|
-
end
|
311
|
-
def compose(main, sub, para)
|
312
|
-
main_k, sub_k = main.kind, sub.kind
|
313
|
-
main_s, sub_s = main.star, sub.star
|
314
|
-
main_main, sub_main = main.main, sub.main
|
315
|
-
main_sub, sub_sub = main.sub, sub.sub
|
316
|
-
para = ParamIndex[para]
|
317
|
-
|
318
|
-
if Equip9[main_k][para] == 0
|
319
|
-
c = 0.quo(1)
|
320
|
-
else
|
321
|
-
c = ( 100 + Equip9[main_k][para] - Equip9[sub_k][para] + Material9[main_main][para] - Material9[sub_main][para] +
|
322
|
-
(main_s-sub_s)*5 - ( ( main_main==sub_main && main_main != 9 ) ? 30 : 0 ) ).quo( main_k==sub_k ? 40000 : 20000 )
|
297
|
+
def from_equip(equip, para)
|
298
|
+
new(Mat.new(1, 1, equip.para[ParamIndex[para]]), equip.kind, equip.star, equip.main, equip.sub)
|
323
299
|
end
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
300
|
+
def smith(str, para)
|
301
|
+
key = [str.freeze, para].freeze
|
302
|
+
return Cache[key].dup if Cache.has_key?(key)
|
303
|
+
unless m = /\A(.+)\((.+\d+),?(.+\d+)\)\Z/.match(str)
|
304
|
+
raise ArgumentError.new("given string `#{str}' is unparsable as a smithing recipe")
|
305
|
+
end
|
306
|
+
kind = EquipIndex[m[1].to_sym]
|
307
|
+
main_m, main_s, main_mc = Mgmg.parse_material(m[2])
|
308
|
+
sub_m, sub_s, sub_mc = Mgmg.parse_material(m[3])
|
309
|
+
para = ParamIndex[para]
|
310
|
+
|
311
|
+
c = ( Equip9[kind][para] * Main9[main_m][para] ).cdiv(100).quo( main_mc==sub_mc ? 200 : 100 )
|
312
|
+
ret = new(Mat.v_array(c*Sub9[sub_m][para], c), kind, (main_s+sub_s).div(2), main_mc, sub_mc)
|
313
|
+
Cache.store(key, ret.freeze)
|
314
|
+
ret.dup
|
332
315
|
end
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
316
|
+
def compose(main, sub, para)
|
317
|
+
main_k, sub_k = main.kind, sub.kind
|
318
|
+
main_s, sub_s = main.star, sub.star
|
319
|
+
main_main, sub_main = main.main, sub.main
|
320
|
+
main_sub, sub_sub = main.sub, sub.sub
|
321
|
+
para = ParamIndex[para]
|
322
|
+
|
323
|
+
if Equip9[main_k][para] == 0
|
324
|
+
c = 0.quo(1)
|
325
|
+
else
|
326
|
+
c = ( 100 + Equip9[main_k][para] - Equip9[sub_k][para] + Material9[main_main][para] - Material9[sub_main][para] +
|
327
|
+
(main_s-sub_s)*5 - ( ( main_main==sub_main && main_main != 9 ) ? 30 : 0 ) ).quo( main_k==sub_k ? 40000 : 20000 )
|
328
|
+
end
|
329
|
+
mat = main.mat.padd(sub.mat.pprod(Mat.h_array(c*Equip9[main_k][para], c)))
|
330
|
+
new(mat, main_k, main_s+sub_s, main_sub, sub_main)
|
340
331
|
end
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
332
|
+
def build(str, para, left_associative: true, include_system_equips: true)
|
333
|
+
str = Mgmg.check_string(str)
|
334
|
+
_para = ParamIndex[para]
|
335
|
+
if _para.nil?
|
336
|
+
raise ArgumentError, "unknown parameter symbol `#{para.inspect}' given"
|
337
|
+
end
|
338
|
+
stack = []
|
339
|
+
stack, str = build_sub0(stack, str, _para) if include_system_equips
|
340
|
+
build_sub(stack, str, _para, left_associative)
|
341
|
+
end
|
342
|
+
private def build_sub0(stack, str, para)
|
343
|
+
SystemEquip.each do |k, v|
|
344
|
+
stack << from_equip(v, para)
|
345
|
+
str = str.gsub(k, "<#{stack.length-1}>")
|
346
|
+
end
|
347
|
+
[stack, str]
|
348
|
+
end
|
349
|
+
private def build_sub(stack, str, para, lassoc)
|
350
|
+
if m = /\A(.*\+?)\[([^\[\]]+)\](\+?[^\[]*)\Z/.match(str)
|
351
|
+
stack << build_sub(stack, m[2], para, lassoc)
|
352
|
+
build_sub(stack, "#{m[1]}<#{stack.length-1}>#{m[3]}", para, lassoc)
|
353
|
+
elsif m = ( lassoc ? /\A(.+)\+(.+?)\Z/ : /\A(.+?)\+(.+)\Z/ ).match(str)
|
354
|
+
compose(build_sub(stack, m[1], para, lassoc), build_sub(stack, m[2], para, lassoc), para)
|
355
|
+
elsif m = /\A\<(\d+)\>\Z/.match(str)
|
356
|
+
stack[m[1].to_i]
|
357
|
+
else
|
358
|
+
smith(str, para)
|
359
|
+
end
|
353
360
|
end
|
354
361
|
end
|
355
362
|
end
|
data/lib/mgmg/reinforce.rb
CHANGED
@@ -12,46 +12,45 @@ module Mgmg
|
|
12
12
|
'(' + @vec.map.with_index{|e, i| e==0 ? nil : "#{Equip::ParamList[i]}:#{e}"}.compact.join(', ') + ')'
|
13
13
|
end
|
14
14
|
alias :inspect :to_s
|
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
|
-
|
15
|
+
|
16
|
+
# スキル名 攻 物 防 HP MP 腕 器 速 魔
|
17
|
+
Skill = {
|
18
|
+
'物防御UP' => Reinforcement.new( Vec[ 0, 10, 0, 0, 0, 0, 0, 0, 0] ),
|
19
|
+
'魔防御UP' => Reinforcement.new( Vec[ 0, 0, 10, 0, 0, 0, 0, 0, 0] ),
|
20
|
+
'腕力UP' => Reinforcement.new( Vec[ 0, 0, 0, 0, 0, 10, 0, 0, 0] ),
|
21
|
+
'メンテナンス' => Reinforcement.new( Vec[ 50, 0, 0, 0, 0, 0, 0, 0, 0] ),
|
22
|
+
'ガードアップ' => Reinforcement.new( Vec[ 0, 50, 0, 0, 0, 0, 0, 0, 0] ),
|
23
|
+
'パワーアップ' => Reinforcement.new( Vec[ 0, 0, 0, 0, 0, 50, 0, 0, 0] ),
|
24
|
+
'デックスアップ' => Reinforcement.new( Vec[ 0, 0, 0, 0, 0, 0, 50, 0, 0] ),
|
25
|
+
'スピードアップ' => Reinforcement.new( Vec[ 0, 0, 0, 0, 0, 0, 0, 50, 0] ),
|
26
|
+
'マジックアップ' => Reinforcement.new( Vec[ 0, 0, 0, 0, 0, 0, 0, 0, 50] ),
|
27
|
+
'オールアップ' => Reinforcement.new( Vec[ 0, 50, 0, 0, 0, 50, 50, 50, 50] ),
|
28
|
+
}
|
29
|
+
|
30
|
+
class << self
|
31
|
+
def cuisine(c)
|
32
|
+
Reinforcement.new( Vec[*(c.vec), *Array.new(6, 0)] )
|
33
|
+
end
|
34
|
+
def compile(arg)
|
35
|
+
case arg
|
36
|
+
when Reinforcement
|
37
|
+
arg
|
38
|
+
when Cuisine
|
39
|
+
cuisine(arg)
|
40
|
+
when String
|
41
|
+
if Skill.has_key?(arg)
|
42
|
+
Skill[arg]
|
43
|
+
elsif SystemCuisine.has_key?(arg)
|
44
|
+
cuisine(SystemCuisine[arg])
|
45
|
+
else
|
46
|
+
raise InvalidReinforcementNameError, arg
|
47
|
+
end
|
46
48
|
else
|
47
|
-
raise
|
49
|
+
raise ArgumentError, "The argument should be Mgmg::Cuisine or skill name String. (`#{arg}' is given)"
|
48
50
|
end
|
49
|
-
else
|
50
|
-
raise ArgumentError, "The argument should be Mgmg::Cuisine or skill name String. (`#{arg}' is given)"
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
55
54
|
class Equip
|
56
55
|
def reinforce(*arg)
|
57
56
|
arg.each do |r|
|
data/lib/mgmg/utils.rb
CHANGED
@@ -153,10 +153,9 @@ module Mgmg
|
|
153
153
|
module_function def invexp3(exp, sa, comp)
|
154
154
|
Math.sqrt(exp - ((sa-1)**2) - (2*((comp-1)**2)) - 4).round + 1
|
155
155
|
end
|
156
|
-
module_function def
|
157
|
-
|
158
|
-
|
159
|
-
ret
|
156
|
+
module_function def clear_cache
|
157
|
+
CacheMLS.clear; Equip::Cache.clear; Equip::CacheML.clear; TPolynomial::Cache.clear; IR::Cache.clear
|
158
|
+
nil
|
160
159
|
end
|
161
160
|
|
162
161
|
CharacterList = /[^\(\)\+0123456789\[\]あきくしすたてなねのびりるイウガクグサジスタダチツデトドニノフブペボムラリルロンヴー一万二光兜典刀剣劣匠双古名吹咆品哮地大天太子安宝小帽弓弩当息悪戦手指斧書服木本杖業樹歴殺水氷法火炎牙物玉王産用界異的皮盾短石砕竜紫綿耳聖脛腕腿般良色衣袋覇質軍軽輝輪重量金鉄鎧闇陽靴額飾首骨鬼龍]/.freeze
|
data/lib/mgmg/version.rb
CHANGED
data/lib/mgmg.rb
CHANGED
@@ -30,6 +30,13 @@ class String
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
def min_level(w=0, include_outsourcing=false, opt: Mgmg::Option.new)
|
33
|
+
key = [self.dup.freeze, w, include_outsourcing, opt.left_associative].freeze
|
34
|
+
return Mgmg::CacheMLS[key] if Mgmg::CacheMLS.has_key?(key)
|
35
|
+
ret = __min_level_sub(w, include_outsourcing, opt)
|
36
|
+
Mgmg::CacheMLS.store(key, ret)
|
37
|
+
ret
|
38
|
+
end
|
39
|
+
private def __min_level_sub(w, include_outsourcing, opt)
|
33
40
|
built = build(-1, opt:)
|
34
41
|
w = build(built.min_levels_max, -1, opt:).weight - w if w <= 0
|
35
42
|
return -1 if include_outsourcing && built.weight <= w
|
@@ -59,10 +66,10 @@ class String
|
|
59
66
|
Mgmg::Equip.min_comp(self, opt:)
|
60
67
|
end
|
61
68
|
def build(smith=-1, comp=smith, opt: Mgmg::Option.new)
|
62
|
-
Mgmg::Equip.build(self, smith, comp, left_associative: opt.left_associative).reinforce(*opt.reinforcement)
|
69
|
+
Mgmg::Equip.build(self, smith, comp, left_associative: opt.left_associative, include_system_equips: opt.include_system_equips).reinforce(*opt.reinforcement)
|
63
70
|
end
|
64
71
|
def ir(opt: Mgmg::Option.new)
|
65
|
-
Mgmg::IR.build(self, left_associative: opt.left_associative, reinforcement: opt.reinforcement)
|
72
|
+
Mgmg::IR.build(self, left_associative: opt.left_associative, reinforcement: opt.reinforcement, include_system_equips: opt.include_system_equips)
|
66
73
|
end
|
67
74
|
def poly(para=:cost, opt: Mgmg::Option.new)
|
68
75
|
case para
|
@@ -83,7 +90,7 @@ class String
|
|
83
90
|
md = self.poly(:magmag, opt:)
|
84
91
|
pd <= md ? pd : md
|
85
92
|
when :cost
|
86
|
-
if Mgmg::SystemEquip.has_key?(self)
|
93
|
+
if opt.include_system_equips and Mgmg::SystemEquip.has_key?(self) then
|
87
94
|
return Mgmg::TPolynomial.new(Mgmg::Mat.new(1, 1, 0.quo(1)), 28, 0, 12, 12)
|
88
95
|
end
|
89
96
|
built = self.build(-1, opt:)
|
@@ -94,7 +101,7 @@ class String
|
|
94
101
|
ret.mat.body[0][0] += const
|
95
102
|
ret
|
96
103
|
else
|
97
|
-
Mgmg::TPolynomial.build(self, para, left_associative: opt.left_associative)
|
104
|
+
Mgmg::TPolynomial.build(self, para, left_associative: opt.left_associative, include_system_equips: opt.include_system_equips)
|
98
105
|
end
|
99
106
|
end
|
100
107
|
def eff(para, smith, comp=smith, opt: Mgmg::Option.new)
|
data/reference.md
CHANGED
@@ -19,23 +19,23 @@
|
|
19
19
|
|
20
20
|
`self`が解釈不能な場合,例外が発生します.また,製作Lvや完成品の☆制限のチェックを行っていないほか,本ライブラリでは`武器+防具`や`防具+武器`の合成も可能になっています.街の鍛冶・防具製作・道具製作屋に任せた場合をシミュレートする場合は製作Lvを負の値(`-1`など,負であれば何でもよい)にします(製作Lv0相当の性能を計算し,消費エレメント量は委託仕様となります).
|
21
21
|
|
22
|
-
`opt`は,`left_associative`のみ使用します.
|
22
|
+
`opt`は,`left_associative`と`include_system_equips`のみ使用します.
|
23
23
|
|
24
24
|
## `Enumerable#build(smith=-1, armor=smith, comp=armor.tap{armor=smith}, opt: Mgmg.option())`
|
25
25
|
複数のレシピ文字列からなる`self`の各要素を製作し,そのすべてを装備したときの`Mgmg::Equip`を返します.製作では`鍛冶Lv=smith`, `防具製作Lv=armor`, `道具製作Lv=comp`とします.1つしか指定しなければすべてそのLv,2つなら1つ目を`smith=armor`,2つ目を`comp`に,3つならそれぞれの値とします.製作Lvが負の場合,製作Lv0として計算した上で,消費エレメント量は街の製作屋に頼んだ場合の値を計算します.武器複数など,同時装備が不可能な場合でも,特にチェックはされません.
|
26
26
|
|
27
|
-
`opt`は,`left_associative`のみ使用します.
|
27
|
+
`opt`は,`left_associative`と`include_system_equips`のみ使用します.
|
28
28
|
|
29
29
|
## `String#min_weight(opt: Mgmg.option())`
|
30
30
|
製作可能な最小重量を返します.基本的には合成回数+1ですが,既製品を含む場合はその限りではありません.
|
31
31
|
|
32
|
-
|
32
|
+
`opt`は,`include_system_equips`のみ使用します.
|
33
33
|
|
34
34
|
## `String#max_weight(include_outsourcing=false, opt: Mgmg.option())`
|
35
35
|
製作可能な最大重量を返します.`include_outsourcing`が真の場合,委託製作時の重量を返します.
|
36
36
|
委託製作では,製作Lv0相当となるため,素材の☆による最低製作Lvで作るよりも重くなる場合があります.
|
37
37
|
|
38
|
-
|
38
|
+
`opt`は,`include_system_equips`のみ使用します.
|
39
39
|
|
40
40
|
## `String#min_level(w=0, include_outsourcing=false, opt: Mgmg.option())`
|
41
41
|
`self`を重量`w`以下で作るための最低製作Lvを返します.
|
@@ -60,12 +60,12 @@
|
|
60
60
|
## `Enumerable#min_levels(weight=1, opt: Mgmg.option())`
|
61
61
|
すべての要素`str`に対する`str.min_levels`をマージした`Hash`を返します.
|
62
62
|
|
63
|
-
|
63
|
+
`opt`は,`include_system_equips`のみ使用します.
|
64
64
|
|
65
65
|
## `Enumerable#min_levels_max(weight=1, opt: Mgmg.option())`
|
66
66
|
`self.min_levels`から武器,防具それぞれに対する最大値を求め,`[必要最小鍛冶Lv, 必要最小防具製作Lv]`を返します.武器,防具の一方のみが含まれる場合,もう一方は`-1`になります.
|
67
67
|
|
68
|
-
|
68
|
+
`opt`は,`include_system_equips`のみ使用します.
|
69
69
|
|
70
70
|
## `String#min_comp(opt: Mgmg.option())`,`Enumerable#min_comp(opt: Mgmg.option())`
|
71
71
|
レシピ通りに合成するのに必要な道具製作Lvを返します.ただし,全体が「[]」で囲われているか,非合成レシピの場合,代わりに`-1`を返します.
|
@@ -79,7 +79,7 @@
|
|
79
79
|
|
80
80
|
`Enumerable`の場合,すべての要素に対し,武器,防具それぞれの最大値を求め,`[必要最小鍛冶Lv, 必要最小防具製作Lv]`を返します.武器,防具の一方のみが含まれる場合,もう一方は`-1`になります.
|
81
81
|
|
82
|
-
|
82
|
+
`opt`は,`include_system_equips`のみ使用します.
|
83
83
|
|
84
84
|
## `String#poly(para=:cost, opt: Mgmg.option())`
|
85
85
|
レシピ文字列である`self`を解釈し,`para`で指定した9パラ値について,丸めを無視した鍛冶・防具製作Lvと道具製作Lvの2変数からなる多項式関数を示す`Mgmg::TPolynomial`クラスのインスタンスを生成し,返します.`para`は次のシンボルのいずれかを指定します.
|
@@ -96,17 +96,17 @@
|
|
96
96
|
|
97
97
|
また,`:cost`を渡すことで,消費エレメント量に関する近似多項式を得られます.`self`に`"+"`が含まれていれば合成品とみなし,最後の合成に必要な地エレメント量を,それ以外では,武器なら消費火エレメント量を,防具なら消費水エレメント量を返します.ただし,`self`が既成品そのものの場合,零多項式を返します.
|
98
98
|
|
99
|
-
`opt`は,`left_associative`のみ使用します.
|
99
|
+
`opt`は,`left_associative`と`include_system_equips`のみ使用します.
|
100
100
|
|
101
101
|
## `String#ir(opt: Mgmg.option())`
|
102
102
|
レシピ文字列である`self`を解釈し,9パラ値について,丸めを考慮した鍛冶・防具製作Lvと道具製作Lvの2変数からなる関数オブジェクトを保持する`Mgmg::IR`クラスのインスタンスを生成し,返します.詳しくは,[後述](#mgmgir)の`Mgmg::IR`クラスの説明を参照ください.
|
103
103
|
|
104
|
-
`opt`は,`left_associative`と`reinforcement`を使用します.
|
104
|
+
`opt`は,`left_associative`と`include_system_equips`,`reinforcement`を使用します.
|
105
105
|
|
106
106
|
## `Enumerable#ir(opt: Mgmg.option())`
|
107
107
|
複数のレシピ文字列からなる`self`の各要素を製作し,そのすべてを装備したときの`Mgmg::IR`を返します.この場合,鍛冶Lv,防具製作Lv,道具製作Lvの3変数からなる関数オブジェクトを保持するものとして扱われます.各装備の種別に応じ,鍛冶Lvまたは防具製作Lvを適用し,9パラ値を計算します.
|
108
108
|
|
109
|
-
`opt`は,`left_associative`と`reinforcement`を使用します.
|
109
|
+
`opt`は,`left_associative`と`include_system_equips`,`reinforcement`を使用します.
|
110
110
|
|
111
111
|
## `String#smith_seach(para, target, comp, opt: Mgmg.option())`
|
112
112
|
`para`の値が`target`以上となるのに必要な最小の鍛冶・防具製作Lvを二分探索で探索して返します.
|
@@ -441,21 +441,23 @@ alias として`*`があるほか`scalar(1.quo(value))`として`quo`,`/`,`s
|
|
441
441
|
## `Mgmg.#option(recipe=nil, **kw)`
|
442
442
|
`kw`はキーワード引数本体です.定義されているキーワードと意味,使用される主なメソッドは下表の通りです.デフォルト値は簡易的な表示であり,細かい点では不正確です.
|
443
443
|
`recipe`にレシピ`String`または`Enumerable`を渡すと,そのレシピを使ってデフォルト値を具体化しますが,各メソッドで自動的に具体化されるため,通常は必要ありません.
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
444
|
+
`Defaults`対応が「対応」となっているキーワード引数については,`Mgmg::Option::Defaults[:include_system_equips]=false`などとすることで,デフォルト値をグローバルに変更することができます.デフォルト値にかかわらず,メソッド呼び出し時に個別に指定すればその値が優先されます.
|
445
|
+
|
446
|
+
|キーワード|デフォルト値|`Defaults`対応|意味|主なメソッド,備考|
|
447
|
+
|:-|:-|:-|:-|:-|
|
448
|
+
|left_associative|`true`|対応|レシピ文字列を左結合で解釈する|`Mgmg::Option`を使用するすべてのメソッド|
|
449
|
+
|smith_min|`recipe.min_level(target_weight)`|非対応|鍛冶Lvに関する探索範囲の最小値|`String#search`など|
|
450
|
+
|armor_min|`recipe.min_level(*target_weight)[1]`|非対応|防具製作Lvに関する探索範囲の最小値|`Enumerable#search`など.`String`系では代わりに`smith_min`を使う|
|
451
|
+
|comp_min|`recipe.min_comp`|非対応|道具製作Lvに関する探索範囲の最小値|`String#search`など|
|
452
|
+
|smith_max, armor_max, comp_max|`10000`|対応|各製作Lvの探索範囲の最大値|`String#search`など|
|
453
|
+
|target_weight|`0`|非対応|`smith_min`のデフォルト値計算に使う目標重量|`String#search`など|
|
454
|
+
|step|`1`|非対応|探索時において道具製作Lvを動かす幅|`String#search`など|
|
455
|
+
|magdef_maximize|`true`|非対応|目標を魔防最大(真)かコスト最小(偽)にするためのスイッチ|`String#phydef_optimize`|
|
456
|
+
|reinforcement|`[]`|非対応|[前述](#mgmgequipreinforcearg)の`Mgmg::Equip#reinforce`による強化リスト|一部を除くすべてのメソッド|
|
457
|
+
|buff|`[]`|非対応|`reinforcement`のエイリアス|どちらか一方のみを指定する|
|
458
|
+
|irep|`recipe.ir()`|非対応|`Mgmg::IR`の使い回しによる高速化|`String#search`など,内部的に使用|
|
459
|
+
|cut_exp|`Float::INFINITY`|非対応|探索時の総経験値の打ち切り値|`String#search`など,内部的に使用|
|
460
|
+
|include_system_equips|`true`|対応|レシピ解釈時に,既製品を受け付ける|`Mgmg::Option`を使用するすべてのメソッド|
|
459
461
|
|
460
462
|
## `Mgmg::Recipe`
|
461
463
|
レシピ文字列,注目パラメータ,オプションをセットにして扱うためのクラスです.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mgmg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KAZOON
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|