manasimu 0.0.25 → 0.0.28

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7789310be16e9d3b352d2aa77999dbd18b80e90e86270637cc0317bc5941be4a
4
- data.tar.gz: 6b85a7a3523e6033aa1efe1d70ef8f7540799a1e72ee4e8ba7f21f0b1d946b14
3
+ metadata.gz: 4f05b8686e87a5b30f3437b017034b1d11ef8d4f0ee750ae8054294848e3e782
4
+ data.tar.gz: 031dbf782b235517129e04642108281c11f6de3a07dacd140bcbedbc22b56bfb
5
5
  SHA512:
6
- metadata.gz: 2676d3fd0ba9efc9b1aea58f4dbf9d677da052ed4cd74e31d5e3a47a25db1ab74d5ca1ccab98081556d1d72edff16d5086b43d2579075c0e2684f5b208d80a2b
7
- data.tar.gz: f8bb389f4018e8d70f6f810d2475e68635feff41f78b1460f55e3e8e8e8e34414e7182d8b8c38ae3f3cbb6c02010a337c566048cac9e80f2323e5d74422311c6
6
+ metadata.gz: 4fbd32550c42b6360ff607e7d2c7f7e37e508736c5a8441e3bf6e7a54a5e8ee113530af81af27b5ec435b0483df2c6fee5ec4131b365e09983060620ff0acc8c
7
+ data.tar.gz: 984bcb2a54f4c30ed6505514f93bd58f9b3ca489f0c38dae55156d8ba44b8586251a3d3296db7aea6c2ba1458c04dbed656a3f730f66b8f8b8ee51c6ea16accf
Binary file
data/lib/manasimu/card.rb CHANGED
@@ -192,7 +192,7 @@ class CardType
192
192
 
193
193
  def mana_source
194
194
  @mana_source ||= @contents.map { |c|
195
- c.color_identity ? c.color_identity.split(',') : []
195
+ c.color_identity ? c.color_identity : []
196
196
  }.flatten.uniq
197
197
  end
198
198
 
@@ -206,7 +206,7 @@ class CardType
206
206
 
207
207
  def mana_cost
208
208
  return @mana_cost if @mana_cost
209
- spell = @contents.select {|c| c.types != "Land"}.first
209
+ spell = @contents.select {|c| not c.types.include? "Land"}.first
210
210
  if spell
211
211
  @mana_cost = spell.mana_cost
212
212
  else
@@ -227,7 +227,7 @@ class CardType
227
227
  end
228
228
 
229
229
  def types
230
- @types ||= @contents.map {|c| c.types}
230
+ @types ||= @contents.map {|c| c.types}.flatten
231
231
  end
232
232
 
233
233
  def color_identity
@@ -235,7 +235,7 @@ class CardType
235
235
  @memo_colors ||= []
236
236
  @contents.each do |c|
237
237
  if c.color_identity
238
- c.color_identity.split(",").each do |color|
238
+ c.color_identity.each do |color|
239
239
  @memo_colors << color if not @memo_colors.include? color
240
240
  end
241
241
  end
@@ -289,7 +289,7 @@ class CardType
289
289
  [0,1]
290
290
  end
291
291
  @is_land = arr.select do |i|
292
- @contents[i] and @contents[i].types == "Land"
292
+ @contents[i] and @contents[i].types.include? "Land"
293
293
  end.length > 0
294
294
  return @is_land
295
295
  end
@@ -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]
@@ -451,11 +476,11 @@ class Content
451
476
  end
452
477
 
453
478
  def mana_source?
454
- return @types == "Land"
479
+ return @types.include? "Land"
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,54 +74,144 @@ class Deck
74
74
  distinct_types << type
75
75
  end
76
76
 
77
+ en = -1
78
+ ja = 0
77
79
 
78
- [-1, 4].each do |i|
80
+ [en, ja].each do |language|
79
81
 
80
82
  distinct_types.sort! do |a,b|
81
- if i < 0
83
+ if language == en
82
84
  a.name <=> b.name
83
- elsif a.names[i] and b.names[i]
84
- a.names[i] <=> b.names[i]
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
85
92
  else
86
- 0
93
+ # none
87
94
  end
88
95
  end
89
96
 
90
97
  lines.each do |line|
91
98
  line.chomp!
92
- search_type = distinct_types.bsearch do |type|
93
- if i < 0
94
- name = type.name.split(' // ')[0]
95
- elsif type.names[i]
96
- name = type.names[i].split(' // ')[0]
97
- else
98
- next
99
- end
99
+ line.chomp.strip!
100
+ line.chomp.lstrip!
101
+ line.gsub!(/ \d+$/, '')
100
102
 
101
- flag = true
102
- name.chars.each_with_index do |nc,i|
103
- if line.length > i
104
- lc = line.chars[i]
105
- if nc > lc
106
- flag = true
107
- break
108
- elsif nc < lc
109
- flag = false
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
110
192
  break
111
- else
112
- # continue
113
193
  end
114
- else
115
- flag = true
116
- break
117
194
  end
195
+
196
+ result = nil
197
+
198
+ if min_type and min <= 0.3
199
+ result = min_type
200
+ end
201
+
202
+ result
118
203
  end
119
- flag
120
- end
204
+
121
205
  if search_type
122
- a = search_type.name.split(' // ')[0]
123
- if line =~ /^#{a}.*$/ and a != 'X'
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
124
212
  ret << search_type
213
+ else
214
+ # none
125
215
  end
126
216
  end
127
217
  end
@@ -132,6 +222,25 @@ class Deck
132
222
  ret
133
223
  end
134
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
+
135
244
  def self.get_card_details(deck_items)
136
245
  cards = []
137
246
  card_id = 0
@@ -171,4 +280,26 @@ class Deck
171
280
  end
172
281
  [cards, clone_card_types]
173
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
174
305
  end
@@ -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.25
4
+ version: 0.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - so1itaryrove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-04 00:00:00.000000000 Z
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