manasimu 0.0.24 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/db/card_type_aggregate +0 -0
- data/lib/manasimu/card.rb +27 -2
- data/lib/manasimu/data.rb +172 -32
- data/lib/manasimu/expansion.rb +11 -0
- 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: 4f594d88260d5a385a6c371967d6dba160e1078a3b0df93afeb6b260ae24298c
|
4
|
+
data.tar.gz: 3d5ad358c02c73e33802222f9729bd5c457249678eadb85f90420ff6703bb26f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11c10118e360fa088964054f4f3083a6dc493528970083ca0af3b24b5729caeae89becb979d23ac872e99f83c6f7b6ac287b9feff70f8c2d724019865f1ba539
|
7
|
+
data.tar.gz: 187a68ae85b566b9e8e592da86aa9e1338ee030b582211045be954e225ed450d3796fd171379e5862706f233a65b4bf506113d2cbc302d9af079924a97fbae39
|
data/db/card_type_aggregate
CHANGED
Binary file
|
data/lib/manasimu/card.rb
CHANGED
@@ -298,6 +298,15 @@ class CardType
|
|
298
298
|
@contents[0].names
|
299
299
|
end
|
300
300
|
|
301
|
+
@name_ja_split = nil
|
302
|
+
def name_ja_split
|
303
|
+
return @name_ja_split if @name_ja_split
|
304
|
+
c = @contents[0]
|
305
|
+
return "" if not c.names
|
306
|
+
return "" if not c.names[0]
|
307
|
+
@name_ja_split = c.names[0].split(' // ')[0]
|
308
|
+
end
|
309
|
+
|
301
310
|
def playable?(lands, capas)
|
302
311
|
return [false, [], []] if lands.empty?
|
303
312
|
return [false, [], []] if converted_mana_cost > lands.length
|
@@ -385,6 +394,14 @@ class CardType
|
|
385
394
|
[played_count, drawed_count, can_played_count, mana_sources_count]
|
386
395
|
end
|
387
396
|
|
397
|
+
def <=>(o)
|
398
|
+
a = @contents[0]
|
399
|
+
b = o.contents[0]
|
400
|
+
d = a.set_code <=> b.set_code
|
401
|
+
return d if d != 0
|
402
|
+
a.number <=> b.number
|
403
|
+
end
|
404
|
+
|
388
405
|
def to_s
|
389
406
|
@contents.map {|c| c.to_s}.join(",")
|
390
407
|
end
|
@@ -399,6 +416,10 @@ class CardTypeAggregate
|
|
399
416
|
@memo = []
|
400
417
|
end
|
401
418
|
|
419
|
+
def sort!
|
420
|
+
@memo.sort!
|
421
|
+
end
|
422
|
+
|
402
423
|
def find(set_code, number)
|
403
424
|
ret = @memo.bsearch do |c|
|
404
425
|
a = c.contents[0]
|
@@ -415,6 +436,10 @@ class CardTypeAggregate
|
|
415
436
|
end
|
416
437
|
end
|
417
438
|
|
439
|
+
def length
|
440
|
+
@memo.length
|
441
|
+
end
|
442
|
+
|
418
443
|
def add(card_type)
|
419
444
|
@memo << card_type
|
420
445
|
end
|
@@ -439,7 +464,7 @@ class Content
|
|
439
464
|
def initialize(hash)
|
440
465
|
@name = hash[:name]
|
441
466
|
@names = hash[:names]
|
442
|
-
@number = hash[:number]
|
467
|
+
@number = hash[:number].to_i
|
443
468
|
@side = hash[:side]
|
444
469
|
@set_code = hash[:set_code]
|
445
470
|
@mana_cost = hash[:mana_cost]
|
@@ -455,7 +480,7 @@ class Content
|
|
455
480
|
end
|
456
481
|
|
457
482
|
def to_s
|
458
|
-
"[#{@name}] [#{@types}] [#{@color_identity}] [#{@mana_cost}]"
|
483
|
+
"[#{@name}] [#{@names}] [#{@types}] [#{@color_identity}] [#{@mana_cost}]"
|
459
484
|
end
|
460
485
|
|
461
486
|
def to_factory
|
data/lib/manasimu/data.rb
CHANGED
@@ -66,53 +66,152 @@ class Deck
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def self.find_card_types(lines)
|
69
|
-
|
70
|
-
types.sort! do |a,b| a.name <=> b.name end
|
69
|
+
ret = []
|
71
70
|
|
72
71
|
distinct_types = []
|
73
|
-
|
72
|
+
card_types.each do |type|
|
74
73
|
next if distinct_types[-1] and distinct_types[-1].name == type.name
|
75
|
-
type.name
|
76
74
|
distinct_types << type
|
77
75
|
end
|
78
76
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
77
|
+
en = -1
|
78
|
+
ja = 0
|
79
|
+
|
80
|
+
[en, ja].each do |language|
|
81
|
+
|
82
|
+
distinct_types.sort! do |a,b|
|
83
|
+
if language == en
|
84
|
+
a.name <=> b.name
|
85
|
+
elsif language == ja
|
86
|
+
d = a.name_ja_split.length <=> b.name_ja_split.length
|
87
|
+
if d == 0
|
88
|
+
a.name_ja_split <=> b.name_ja_split
|
86
89
|
else
|
87
|
-
|
88
|
-
name = type.names[i].split(' // ')[0]
|
90
|
+
d
|
89
91
|
end
|
92
|
+
else
|
93
|
+
# none
|
94
|
+
end
|
95
|
+
end
|
90
96
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
97
|
+
lines.each do |line|
|
98
|
+
line.chomp!
|
99
|
+
line.chomp.strip!
|
100
|
+
line.chomp.lstrip!
|
101
|
+
line.gsub!(/ \d+$/, '')
|
102
|
+
|
103
|
+
if line =~ /^[\/,\|\d-]*$/ or line =~ /^x\d+$/
|
104
|
+
next
|
105
|
+
end
|
106
|
+
|
107
|
+
search_type =
|
108
|
+
if language == en
|
109
|
+
# binary search
|
110
|
+
distinct_types.bsearch do |type|
|
111
|
+
name = type.name.split(' // ')[0]
|
112
|
+
flag = true
|
113
|
+
name.chars.each_with_index do |nc,i|
|
114
|
+
if line.length > i
|
115
|
+
lc = line.chars[i]
|
116
|
+
if nc > lc
|
117
|
+
flag = true
|
118
|
+
break
|
119
|
+
elsif nc < lc
|
120
|
+
flag = false
|
121
|
+
break
|
122
|
+
else
|
123
|
+
# continue
|
124
|
+
end
|
125
|
+
else
|
126
|
+
flag = true
|
127
|
+
break
|
128
|
+
end
|
129
|
+
end
|
130
|
+
flag
|
131
|
+
end
|
132
|
+
else language == ja
|
133
|
+
# Levenshtein distance
|
134
|
+
|
135
|
+
line.gsub!(/[①②③④⑤⑥⑦⑧⑨⑩⑪⑫⑬●〇▼▽▲△]+/, '')
|
136
|
+
line.chomp!
|
137
|
+
line.strip!
|
138
|
+
line.lstrip!
|
139
|
+
|
140
|
+
len = line.length
|
141
|
+
|
142
|
+
s_index = distinct_types.bsearch_index do |type|
|
143
|
+
name = type.name_ja_split
|
144
|
+
name.length >= len - 2
|
145
|
+
end
|
146
|
+
|
147
|
+
e_index = distinct_types.bsearch_index do |type|
|
148
|
+
name = type.name_ja_split
|
149
|
+
name.length >= len + 2
|
150
|
+
end
|
151
|
+
|
152
|
+
next if not s_index
|
153
|
+
|
154
|
+
min = Float::MAX
|
155
|
+
min_type = nil
|
156
|
+
|
157
|
+
distinct_types[s_index..e_index].each do |type|
|
158
|
+
name = type.name_ja_split
|
159
|
+
|
160
|
+
check_indexies = []
|
161
|
+
if name.length == 1
|
162
|
+
check_indexies[0] = 0
|
163
|
+
elsif name.length == 2
|
164
|
+
check_indexies[0] = 0
|
165
|
+
check_indexies[1] = 1
|
166
|
+
elsif name.length > 0
|
167
|
+
check_indexies[0] = 0
|
168
|
+
check_indexies[1] = (name.length / 2).to_i
|
169
|
+
check_indexies[2] = name.length - 1
|
170
|
+
end
|
171
|
+
|
172
|
+
next if check_indexies.length == 0
|
173
|
+
|
174
|
+
include_some = false
|
175
|
+
check_indexies.each do |idx|
|
176
|
+
if not name[idx].empty? and line.index(name[idx])
|
177
|
+
include_some = true
|
178
|
+
break
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
next if not include_some
|
183
|
+
|
184
|
+
d = levenshtein(line, name)
|
185
|
+
base = [name.length, line.length].max
|
186
|
+
diff_rate = d.to_f / base
|
187
|
+
if diff_rate < min
|
188
|
+
min = diff_rate
|
189
|
+
min_type = type
|
190
|
+
end
|
191
|
+
if d == 0
|
100
192
|
break
|
101
|
-
else
|
102
|
-
# continue
|
103
193
|
end
|
104
|
-
else
|
105
|
-
flag = true
|
106
|
-
break
|
107
194
|
end
|
195
|
+
|
196
|
+
result = nil
|
197
|
+
|
198
|
+
if min_type and min <= 0.3
|
199
|
+
result = min_type
|
200
|
+
end
|
201
|
+
|
202
|
+
result
|
108
203
|
end
|
109
|
-
|
110
|
-
end
|
204
|
+
|
111
205
|
if search_type
|
112
|
-
|
113
|
-
|
206
|
+
if language == en
|
207
|
+
a = search_type.name.split(' // ')[0]
|
208
|
+
if line =~ /^#{a}.*$/ and a != 'X'
|
209
|
+
ret << search_type
|
210
|
+
end
|
211
|
+
elsif language == ja
|
114
212
|
ret << search_type
|
115
|
-
|
213
|
+
else
|
214
|
+
# none
|
116
215
|
end
|
117
216
|
end
|
118
217
|
end
|
@@ -123,6 +222,25 @@ class Deck
|
|
123
222
|
ret
|
124
223
|
end
|
125
224
|
|
225
|
+
def self.tsearch(arr, line, low, high)
|
226
|
+
if high - low < 1000
|
227
|
+
return [low, high]
|
228
|
+
end
|
229
|
+
c1 = ((low * 2 + high ) / 3).to_i - 1
|
230
|
+
c2 = ((low + high * 2 ) / 3).to_i + 1
|
231
|
+
|
232
|
+
n1 = arr[c1].name_ja_split
|
233
|
+
n2 = arr[c2].name_ja_split
|
234
|
+
|
235
|
+
y1 = levenshtein(line, n1)
|
236
|
+
y2 = levenshtein(line, n2)
|
237
|
+
if y1 > y2
|
238
|
+
tsearch(arr, line, c1, high)
|
239
|
+
else
|
240
|
+
tsearch(arr, line, low, c2)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
126
244
|
def self.get_card_details(deck_items)
|
127
245
|
cards = []
|
128
246
|
card_id = 0
|
@@ -162,4 +280,26 @@ class Deck
|
|
162
280
|
end
|
163
281
|
[cards, clone_card_types]
|
164
282
|
end
|
283
|
+
|
284
|
+
def self.levenshtein(first, second)
|
285
|
+
matrix = [(0..first.length).to_a]
|
286
|
+
(1..second.length).each do |j|
|
287
|
+
matrix << [j] + [0] * (first.length)
|
288
|
+
end
|
289
|
+
|
290
|
+
(1..second.length).each do |i|
|
291
|
+
(1..first.length).each do |j|
|
292
|
+
if first[j-1] == second[i-1]
|
293
|
+
matrix[i][j] = matrix[i-1][j-1]
|
294
|
+
else
|
295
|
+
matrix[i][j] = [
|
296
|
+
matrix[i-1][j],
|
297
|
+
matrix[i][j-1],
|
298
|
+
matrix[i-1][j-1],
|
299
|
+
].min + 1
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
return matrix.last.last
|
304
|
+
end
|
165
305
|
end
|
data/lib/manasimu/expansion.rb
CHANGED
@@ -1,3 +1,14 @@
|
|
1
1
|
class Expansion
|
2
2
|
attr_accessor :code, :name, :exists
|
3
|
+
|
4
|
+
def self.load
|
5
|
+
return [] if not File.exists?(File.expand_path( '../../../db/expansions', __FILE__ ))
|
6
|
+
File.open(File.expand_path( '../../../db/expansions', __FILE__ ), "r") do |file|
|
7
|
+
Marshal.load(file)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def ==(other)
|
12
|
+
self.code == other.code and self.exists
|
13
|
+
end
|
3
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: manasimu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- so1itaryrove
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: mtg arrena mana curve simulator
|
14
14
|
email: so1itaryrove@gmail.com
|