manasimu 0.0.26 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/card_type_aggregate +0 -0
- data/lib/manasimu/card.rb +27 -2
- data/lib/manasimu/data.rb +157 -36
- 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
@@ -74,64 +74,144 @@ class Deck
|
|
74
74
|
distinct_types << type
|
75
75
|
end
|
76
76
|
|
77
|
+
en = -1
|
78
|
+
ja = 0
|
77
79
|
|
78
|
-
[
|
80
|
+
[en, ja].each do |language|
|
79
81
|
|
80
82
|
distinct_types.sort! do |a,b|
|
81
|
-
if
|
83
|
+
if language == en
|
82
84
|
a.name <=> b.name
|
83
|
-
elsif
|
84
|
-
a.
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
89
|
+
else
|
90
|
+
d
|
91
|
+
end
|
89
92
|
else
|
90
|
-
|
93
|
+
# none
|
91
94
|
end
|
92
95
|
end
|
93
96
|
|
94
97
|
lines.each do |line|
|
95
98
|
line.chomp!
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
elsif type.names[j]
|
100
|
-
name = type.names[j].split(' // ')[0]
|
101
|
-
end
|
99
|
+
line.chomp.strip!
|
100
|
+
line.chomp.lstrip!
|
101
|
+
line.gsub!(/ \d+$/, '')
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
109
126
|
flag = true
|
110
127
|
break
|
111
|
-
|
112
|
-
|
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
|
113
178
|
break
|
114
|
-
else
|
115
|
-
# continue
|
116
179
|
end
|
117
|
-
|
118
|
-
|
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
|
119
192
|
break
|
120
193
|
end
|
121
194
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
195
|
+
|
196
|
+
result = nil
|
197
|
+
|
198
|
+
if min_type and min <= 0.3
|
199
|
+
result = min_type
|
200
|
+
end
|
201
|
+
|
202
|
+
result
|
125
203
|
end
|
126
|
-
|
204
|
+
|
127
205
|
if search_type
|
128
|
-
if
|
206
|
+
if language == en
|
129
207
|
a = search_type.name.split(' // ')[0]
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
208
|
+
if line =~ /^#{a}.*$/ and a != 'X'
|
209
|
+
ret << search_type
|
210
|
+
end
|
211
|
+
elsif language == ja
|
134
212
|
ret << search_type
|
213
|
+
else
|
214
|
+
# none
|
135
215
|
end
|
136
216
|
end
|
137
217
|
end
|
@@ -142,6 +222,25 @@ class Deck
|
|
142
222
|
ret
|
143
223
|
end
|
144
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
|
+
|
145
244
|
def self.get_card_details(deck_items)
|
146
245
|
cards = []
|
147
246
|
card_id = 0
|
@@ -181,4 +280,26 @@ class Deck
|
|
181
280
|
end
|
182
281
|
[cards, clone_card_types]
|
183
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
|
184
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
|