manasimu 0.0.26 → 0.0.29

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: f194c1efd40c93772541e4aa6bf1164ff46a836a91887e848944548ed5afabde
4
- data.tar.gz: 1716988949899acf5972599c371dd95696748311afd728d1bcd6a9040c2ef901
3
+ metadata.gz: f72b3b73b7814d529111d94adcf4a6257a73a0fd556328d312b15d891e17f5a3
4
+ data.tar.gz: 9574fa9f53290ff7532c87319037ba98b793e6d9bdff4b20b9e99da20a0fbea3
5
5
  SHA512:
6
- metadata.gz: 14ffb32574c728c83f737d234205e37a85748ba08a68fe952e5a3945a5fb8715ed3791105fa89971f7c874b76de8e9ca8a6168ec7a7d64992f1482adc8ec8f17
7
- data.tar.gz: 5e2a6b2740ec5259ab5d60625b6201b05707022735808e75fd1d1d3753ff591db9b9a651401f48b3b91367ebf6baa9c58f0f6448d6ac73bd33a67f381bc13a1b
6
+ metadata.gz: aedd75381bbc4fd8e2256c9a83ac2a06ed951e28dfd06dae6c483c785098c76a0b247954be3ca19cda094a3608c7d950f0068d01380caf595492c5c436daa29b
7
+ data.tar.gz: 9953c1faa928cd8edf0be11505596ef9dff13514eb26f86f45811171dc15005e33b201b81774743f28c50c52db043708304b9ab70d5f03a8c65b7f17214d4302
Binary file
data/lib/manasimu/card.rb CHANGED
@@ -128,7 +128,7 @@ class Card
128
128
  end
129
129
 
130
130
  class CardType
131
- attr_accessor :contents, :played, :drawed, :name, :can_plays, :mana_sources
131
+ attr_accessor :contents, :played, :drawed, :name, :can_plays, :mana_sources, :language
132
132
 
133
133
  def self.create(card_type, name)
134
134
  ret = card_type.dup
@@ -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,64 +74,146 @@ 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 |j|
80
+ [en, ja].each do |language|
79
81
 
80
82
  distinct_types.sort! do |a,b|
81
- if j < 0
83
+ if language == en
82
84
  a.name <=> b.name
83
- elsif a.names[j] and b.names[j]
84
- a.names[j] <=> b.names[j]
85
- elsif not a.names[j] and not b.names[j]
86
- 0
87
- elsif a.names[j]
88
- -1
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
- 1
93
+ # none
91
94
  end
92
95
  end
93
96
 
94
97
  lines.each do |line|
95
98
  line.chomp!
96
- search_type = distinct_types.bsearch do |type|
97
- if j < 0
98
- name = type.name.split(' // ')[0]
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
- if name
104
- flag = true
105
- name.chars.each_with_index do |nc,i|
106
- if line.length > i
107
- lc = line.chars[i]
108
- if nc > lc
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
- elsif nc < lc
112
- flag = false
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
- else
118
- flag = true
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
- flag
123
- else
124
- false
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
- end
204
+
127
205
  if search_type
128
- if j < 0
206
+ if language == en
129
207
  a = search_type.name.split(' // ')[0]
130
- else
131
- a = search_type.names[j].split(' // ')[0]
132
- end
133
- if line =~ /^#{a}.*$/ and a != 'X'
208
+ if line =~ /^#{a}.*$/ and a != 'X'
209
+ search_type.language = 'en'
210
+ ret << search_type
211
+ end
212
+ elsif language == ja
213
+ search_type.language = 'ja'
134
214
  ret << search_type
215
+ else
216
+ # none
135
217
  end
136
218
  end
137
219
  end
@@ -142,6 +224,25 @@ class Deck
142
224
  ret
143
225
  end
144
226
 
227
+ def self.tsearch(arr, line, low, high)
228
+ if high - low < 1000
229
+ return [low, high]
230
+ end
231
+ c1 = ((low * 2 + high ) / 3).to_i - 1
232
+ c2 = ((low + high * 2 ) / 3).to_i + 1
233
+
234
+ n1 = arr[c1].name_ja_split
235
+ n2 = arr[c2].name_ja_split
236
+
237
+ y1 = levenshtein(line, n1)
238
+ y2 = levenshtein(line, n2)
239
+ if y1 > y2
240
+ tsearch(arr, line, c1, high)
241
+ else
242
+ tsearch(arr, line, low, c2)
243
+ end
244
+ end
245
+
145
246
  def self.get_card_details(deck_items)
146
247
  cards = []
147
248
  card_id = 0
@@ -181,4 +282,26 @@ class Deck
181
282
  end
182
283
  [cards, clone_card_types]
183
284
  end
285
+
286
+ def self.levenshtein(first, second)
287
+ matrix = [(0..first.length).to_a]
288
+ (1..second.length).each do |j|
289
+ matrix << [j] + [0] * (first.length)
290
+ end
291
+
292
+ (1..second.length).each do |i|
293
+ (1..first.length).each do |j|
294
+ if first[j-1] == second[i-1]
295
+ matrix[i][j] = matrix[i-1][j-1]
296
+ else
297
+ matrix[i][j] = [
298
+ matrix[i-1][j],
299
+ matrix[i][j-1],
300
+ matrix[i-1][j-1],
301
+ ].min + 1
302
+ end
303
+ end
304
+ end
305
+ return matrix.last.last
306
+ end
184
307
  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.26
4
+ version: 0.0.29
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