manasimu 0.0.14 → 0.0.17

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: 3c73ee6bfefc5a1611b3170d86b8dc27dbf75c58f2dc3f2be7d570679cedfab3
4
- data.tar.gz: f771ef43cafe46bcc75eed2c0964c42e39f32d7c1ab92a0e09e1a5b6ad6b4845
3
+ metadata.gz: cd8f2deebb97ccdfec7d84f59caf31ca2548c5d2152d03f171acef1718619035
4
+ data.tar.gz: 1422e049b960adb6f9365921c20426a61a5c384ecb87435b1ca4ed284b156025
5
5
  SHA512:
6
- metadata.gz: c1e61d71e665d98b74a8cfa52d877e2131be56484fdee9d78d85b1e072d5ffa5172444b7c0683c30c94e113f9876048b31d4bbb4af528fac08296d2650bb6ce1
7
- data.tar.gz: 5a6ea06c33e3227a1f4f74be5a6d4266069090ecda660e29ad7c9b717891367d4764943726f2a0cd32632fafd6e58e505526c6809ed0da87e67b3b133382dd7d
6
+ metadata.gz: 60cb513f51880b6150fac14f1caef1e86775bcd04da5c55406e3d439d4d0e770606ab4254f599b1dccbad0a27cdc7fdd728db3deeae346b9fbf7d15fb9c5ff26
7
+ data.tar.gz: c95fcc75ff9f576d42791ac69997500de7cff984360f81d146def3555f80df084549a9ca97d64564e5d6b34b69c21e9a76adee29904330943ca75dce0c917b59
Binary file
@@ -0,0 +1,3 @@
1
+ class BasicLandCard < Card
2
+
3
+ end
@@ -15,11 +15,12 @@ class PathwayCard < Card
15
15
  end
16
16
  end
17
17
 
18
- def color_identity
18
+ def mana_source
19
19
  if @side
20
20
  [@symbol]
21
21
  else
22
22
  @card_type.color_identity
23
23
  end
24
24
  end
25
+
25
26
  end
@@ -1,7 +1,7 @@
1
1
  class SlowLandCard < Card
2
2
 
3
- def resolve(side, hands, plays)
4
- super(side, hands, plays)
3
+ def resolve(side, hands, plays, deck)
4
+ super(side, hands, plays, deck)
5
5
  num = 0
6
6
  for card in plays do
7
7
  next if card == self
@@ -0,0 +1,64 @@
1
+ class SncFetchLandCard < TapLandCard
2
+
3
+ attr_accessor :deck
4
+
5
+ def resolve(side, hands, plays, deck)
6
+ super(side, hands, plays, deck)
7
+ return @fetch_source if @fetch_source
8
+ @tapped = true
9
+ if deck
10
+ @fetches = deck
11
+ .select { |card| card.instance_of? BasicLandCard }
12
+ .select { |card| @mana_source.include? card.mana_source[0] }
13
+ .uniq { |card| card.card_type }
14
+ @deck = deck
15
+ @fetch_source = @fetches.map { |card| card.mana_source }.flatten.uniq
16
+ else
17
+ @fetches = []
18
+ @fetch_source = []
19
+ end
20
+ end
21
+
22
+ def first_produce_symbol=(color)
23
+ super(color)
24
+ if @deck
25
+ basic_land = @deck
26
+ .select { |card| card.instance_of? BasicLandCard }
27
+ .select { |card| color.to_i.to_s == color || card.mana_source.include?(color) }
28
+ .first
29
+ if basic_land
30
+ @deck.delete basic_land
31
+ @deck.shuffle!
32
+ @fetch_source = [color]
33
+ @fetches = [basic_land]
34
+ else
35
+ raise Exception.new('basic land is empty')
36
+ end
37
+ else
38
+ []
39
+ end
40
+ @fetched = true
41
+ end
42
+
43
+ def mana_source
44
+ raise Exception.new('you should resolve first') if not @fetch_source
45
+ @fetch_source
46
+ end
47
+
48
+ def configure
49
+ mana_types = ManaType.search_text_by_land_type(card_type.text)
50
+ @mana_source = mana_types.map {|mana_type| mana_type.color}.flatten.uniq
51
+ @fetched = false
52
+ self
53
+ end
54
+
55
+ def reset
56
+ super
57
+ @fetched = false
58
+ @fetch_source = nil
59
+ end
60
+
61
+ def mana_produced?
62
+ @fetched
63
+ end
64
+ end
@@ -4,8 +4,8 @@ class TapLandCard < Card
4
4
  @tapped
5
5
  end
6
6
 
7
- def resolve(side, hands, plays)
8
- super(side, hands, plays)
7
+ def resolve(side, hands, plays, deck)
8
+ super(side, hands, plays, deck)
9
9
  @tapped = true
10
10
  end
11
11
 
data/lib/manasimu/card.rb CHANGED
@@ -6,13 +6,16 @@ class Card
6
6
  @playable = false
7
7
  end
8
8
 
9
+ def configure
10
+ end
11
+
9
12
  def step_in_hands(turn)
10
- @card_type.step_in_hands(turn - 1, self)
13
+ @card_type.step_in_hands(turn, self)
11
14
  @can_play = false
12
15
  end
13
16
 
14
17
  def step_in_plays(turn)
15
- @card_type.step_in_plays(turn - 1, self)
18
+ @card_type.step_in_plays(turn, self)
16
19
  end
17
20
 
18
21
  def drawed(turn)
@@ -28,7 +31,7 @@ class Card
28
31
  end
29
32
  end
30
33
 
31
- def resolve(side = "a", hands, plays)
34
+ def resolve(side = "a", hands, plays, deck)
32
35
  end
33
36
 
34
37
  def played?
@@ -39,6 +42,14 @@ class Card
39
42
  false
40
43
  end
41
44
 
45
+ def mana_source
46
+ @card_type.mana_source
47
+ end
48
+
49
+ def mana_source_size
50
+ @card_type.mana_source_size
51
+ end
52
+
42
53
  def mana_source?
43
54
  @card_type.mana_source?
44
55
  end
@@ -57,8 +68,8 @@ class Card
57
68
  @card_type.types
58
69
  end
59
70
 
60
- def mana
61
- @card_type.mana
71
+ def type
72
+ @card_type.type
62
73
  end
63
74
 
64
75
  def color_identity
@@ -107,6 +118,10 @@ class Card
107
118
  def first_produce_symbol=(symbol)
108
119
  end
109
120
 
121
+ def set_code
122
+ @card_type.set_code
123
+ end
124
+
110
125
  def to_s
111
126
  @card_type.to_s
112
127
  end
@@ -140,17 +155,17 @@ class CardType
140
155
  end
141
156
 
142
157
  def step_in_hands(turn, card)
143
- if turn >= 0 and card.can_play?
158
+ if card.can_play?
144
159
  @can_plays[turn] ||= 0
145
160
  @can_plays[turn] += 1
146
161
  end
147
162
  end
148
163
 
149
164
  def step_in_plays(turn, card)
150
- if turn >= 0 and card.mana_source? and not card.tapped?
165
+ if card.mana_source? and not card.tapped?
151
166
  @mana_sources[turn] ||= {}
152
- size = card.color_identity.length
153
- card.color_identity.each do |c|
167
+ size = card.mana_source.length
168
+ card.mana_source.each do |c|
154
169
  @mana_sources[turn][c] ||= 0
155
170
  @mana_sources[turn][c] += 1.0 / size
156
171
  end
@@ -167,47 +182,63 @@ class CardType
167
182
  @drawed[turn] += 1
168
183
  end
169
184
 
185
+ def mana_source
186
+ @mana_source ||= @contents.map { |c|
187
+ c.color_identity ? c.color_identity.split(',') : []
188
+ }.flatten.uniq
189
+ end
190
+
191
+ def mana_source_size
192
+ (a = mana_source) ? a.size : 0
193
+ end
194
+
170
195
  def mana_source?
171
- @mana_source ||= @contents.any? {|content| content.mana_source?}
196
+ @is_mana_source ||= @contents.any? {|content| content.mana_source?}
172
197
  end
173
198
 
174
- def types
175
- @types ||= @contents.map {|c| c.types}
199
+ def mana_cost
200
+ return @mana_cost if @mana_cost
201
+ spell = @contents.select {|c| c.types != "Land"}.first
202
+ if spell
203
+ @mana_cost = spell.mana_cost
204
+ else
205
+ @mana_cost = '0'
206
+ end
207
+ end
208
+
209
+ def converted_mana_cost
210
+ @converted_mana_cost ||= @contents.map {|c| c.converted_mana_cost}.min
176
211
  end
177
212
 
178
- def mana
179
- @mana ||= @contents.map {|content| content.color_identity }.flatten
213
+ def text
214
+ @text ||= @contents.map {|c| c.text}.flatten.join('')
215
+ end
216
+
217
+ def type
218
+ @type ||= @contents.map {|c| c.type}.flatten.uniq
219
+ end
220
+
221
+ def types
222
+ @types ||= @contents.map {|c| c.types}
180
223
  end
181
224
 
182
225
  def color_identity
183
226
  return @memo_colors if @memo_colors
184
227
  @memo_colors ||= []
185
228
  @contents.each do |c|
186
- c.color_identity.split(",").each do |color|
187
- @memo_colors << color if not @memo_colors.include? color
229
+ if c.color_identity
230
+ c.color_identity.split(",").each do |color|
231
+ @memo_colors << color if not @memo_colors.include? color
232
+ end
188
233
  end
189
234
  end
190
235
  @memo_colors
191
236
  end
192
237
 
193
- def converted_mana_cost
194
- @converted_mana_cost ||= @contents.map {|c| c.converted_mana_cost}.min
195
- end
196
-
197
238
  def color_identity_size
198
239
  color_identity.length
199
240
  end
200
241
 
201
- def mana_cost
202
- return @mana_cost if @mana_cost
203
- spell = @contents.select {|c| c.types != "Land"}.first
204
- if spell
205
- @mana_cost = spell.mana_cost
206
- else
207
- @mana_cost = '0'
208
- end
209
- end
210
-
211
242
  def symbols
212
243
  return @symbols if @symbols
213
244
  @symbols = []
@@ -236,6 +267,10 @@ class CardType
236
267
  converted_mana_cost
237
268
  end
238
269
 
270
+ def set_code
271
+ @contents[0].set_code
272
+ end
273
+
239
274
  def is_land?(side = nil)
240
275
  return @is_land if @is_land
241
276
  arr = if side == 'a'
@@ -307,7 +342,7 @@ class CardType
307
342
  # lands and mana_cost connect to each symbols
308
343
  lands.each_with_index do |land, i|
309
344
  next if capas[i].to_i == 0
310
- land_colors = land.color_identity
345
+ land_colors = land.mana_source
311
346
  symbols.each_with_index do |symbol, j|
312
347
  if symbol == "1" or land_colors.include? symbol
313
348
  result << [i + 1, x + 1 + j]
@@ -328,19 +363,23 @@ class CardType
328
363
 
329
364
  def count(turn = nil)
330
365
  turn ||= converted_mana_cost
331
- played = @played [turn] || 0
332
- drawed = 0
366
+ played_count = @played[turn] || 0
367
+ drawed_count = 0
333
368
  (turn+1).times do |i|
334
- drawed += @drawed[i] || 0
369
+ drawed_count += @drawed[i] || 0
335
370
  end
336
- can_played = @can_plays[turn] || 0
337
- mana_sources = @mana_sources[turn] || {}
338
- [played, drawed, can_played, mana_sources]
371
+ can_played_count = @can_plays[turn] || 0
372
+ mana_sources_count = @mana_sources[turn] || {}
373
+ [played_count, drawed_count, can_played_count, mana_sources_count]
339
374
  end
340
375
 
341
376
  def to_s
342
377
  @contents.map {|c| c.to_s}.join(",")
343
378
  end
379
+
380
+ def to_factory
381
+ @contents.map {|c| c.to_factory}
382
+ end
344
383
  end
345
384
 
346
385
  class CardTypeAggregate
@@ -368,7 +407,7 @@ class CardTypeAggregate
368
407
  end
369
408
 
370
409
  class Content
371
- attr_accessor :name, :number, :side, :set_code, :mana_cost, :types, :color_identity, :converted_mana_cost, :text
410
+ attr_accessor :name, :number, :side, :set_code, :mana_cost, :type, :types, :color_identity, :converted_mana_cost, :text
372
411
 
373
412
  def initialize(hash)
374
413
  @name = hash[:name]
@@ -377,6 +416,7 @@ class Content
377
416
  @set_code = hash[:set_code]
378
417
  @mana_cost = hash[:mana_cost]
379
418
  @types = hash[:types]
419
+ @type = hash[:type]
380
420
  @text = hash[:text]
381
421
  @color_identity = hash[:color_identity]
382
422
  @converted_mana_cost = hash[:converted_mana_cost].to_i
@@ -390,6 +430,23 @@ class Content
390
430
  "[#{@name}] [#{@types}] [#{@color_identity}] [#{@mana_cost}]"
391
431
  end
392
432
 
433
+ def to_factory
434
+ <<EOF
435
+ factory '#{@name.underscore}_content', class: Content do
436
+ name {'#{@name}'}
437
+ number {'#{@number}'}
438
+ side {'#{@side}'}
439
+ set_code { '#{@set_code}'}
440
+ mana_cost { '#{@mana_cost}'}
441
+ type { '#{@type}'}
442
+ types { '#{@types}'}
443
+ text { '#{@text}'}
444
+ color_identity { '#{@color_identity}'}
445
+ converted_mana_cost {#{@converted_mana_cost}}
446
+ end
447
+ EOF
448
+ end
449
+
393
450
  end
394
451
 
395
452
  class FordFulkersonSingleton
data/lib/manasimu/data.rb CHANGED
@@ -70,14 +70,22 @@ class Deck
70
70
  card_type = @@card_types.find(deck_item[:set], deck_item[:setnum])
71
71
  clone = CardType.create(card_type, deck_item[:name])
72
72
  card_types << clone
73
- if clone.name =~ /.*Pathway$/ and clone.mana_source?
74
- card = PathwayCard.new(clone)
75
- elsif clone.is_land? and
76
- clone.contents[0].text =~ /enters the battlefield tapped\./
77
- card = TapLandCard.new(clone)
78
- elsif clone.is_land? and
79
- clone.contents[0].text =~ /enters the battlefield tapped unless you control two or more other lands./
80
- card = SlowLandCard.new(clone)
73
+ if clone.is_land?
74
+ if clone.name =~ /.*Pathway$/
75
+ card = PathwayCard.new(clone)
76
+ elsif clone.contents[0].text =~ /enters the battlefield tapped\./
77
+ card = TapLandCard.new(clone)
78
+ elsif clone.contents[0].text =~ /enters the battlefield tapped unless you control two or more other lands./
79
+ card = SlowLandCard.new(clone)
80
+ elsif clone.set_code == 'SNC' and
81
+ clone.contents[0].text =~ /enters the battlefield, sacrifice it/
82
+ card = SncFetchLandCard.new(clone)
83
+ card.configure
84
+ elsif clone.type[0] =~ /^Basic Land — .*$/
85
+ card = BasicLandCard.new(clone)
86
+ else
87
+ card = Card.new(clone)
88
+ end
81
89
  else
82
90
  card = Card.new(clone)
83
91
  end
data/lib/manasimu/game.rb CHANGED
@@ -1,48 +1,60 @@
1
1
  class Game
2
2
  attr_accessor :hands, :plays, :deck
3
3
 
4
- def initialize(deck)
5
- @deck = deck.shuffle(random: Random.new)
4
+ def initialize(deck, shuffle = true, debugg = false)
5
+ if shuffle
6
+ @deck = deck.shuffle(random: Random.new)
7
+ else
8
+ @deck = deck
9
+ end
6
10
  @deck.each { |card| card.reset }
7
11
  @hands = []
8
12
  @plays = []
9
13
  @planner = Planner.new
14
+ @debugg = debugg
10
15
  7.times { draw(0) }
11
16
  end
12
17
 
13
18
  def step(turn)
14
- # puts "turn #{turn}"
15
- # puts "played"
16
- # @plays.each do |card| puts " #{card}" end
17
- # puts "hands"
18
- # @hands.each do |card| puts " #{card}" end
19
+ if @debugg
20
+ puts "---------------------------------"
21
+ puts "turn #{turn} deck #{@deck.length}"
22
+ puts "played"
23
+ @plays.each do |card| puts " #{card}" end
24
+ puts "hands"
25
+ @hands.each do |card| puts " #{card}" end
26
+ end
19
27
 
20
- upkeep(turn)
21
28
  draw(turn)
29
+ play_cards = plan;
30
+ @hands.each { |card| card.step_in_hands(turn) }
22
31
  plan.each do |card|
23
32
  play(card, turn)
24
33
  end
25
- end
26
-
27
- def upkeep(turn)
28
- @hands.each { |card| card.step_in_hands(turn) }
29
34
  @plays.each { |card| card.step_in_plays(turn) }
30
35
  end
31
36
 
32
37
  def draw(turn)
33
38
  card = @deck.pop
34
- # puts "draw #{card}"
39
+ if @debugg
40
+ puts "draw #{card}"
41
+ end
35
42
  card.drawed(turn)
36
43
  @hands << card
37
44
  end
38
45
 
39
46
  def plan
40
- @planner.plan(@hands, @plays)
47
+ @planner.plan(@hands, @plays, @deck)
41
48
  end
42
49
 
43
50
  def play(card, turn)
44
- # puts "play #{card}"
45
- card.resolve(nil, @hands, @plays)
51
+ if @debugg
52
+ puts "play #{card}"
53
+ end
54
+
55
+ card.resolve(nil, @hands, @plays, @deck)
56
+ @deck = card.deck if card.respond_to? :deck
57
+
46
58
  card.played(turn, nil)
47
59
  @plays << card
48
60
  @hands.delete card
@@ -1,7 +1,55 @@
1
1
  class ManaType
2
- class Red end;
3
- class Blue end;
4
- class Green end;
5
- class White end;
6
- class Black end;
2
+ attr_accessor :color, :land_type
3
+
4
+ def initialize(color, land_type)
5
+ @land_type = land_type
6
+ @color = color
7
+ end
8
+
9
+ def self.all
10
+ r ||= Red.new
11
+ u ||= Blue.new
12
+ g ||= Green.new
13
+ w ||= White.new
14
+ b ||= Black.new
15
+ @@all ||= [r, u, g, w, b]
16
+ end
17
+
18
+ def self.search_text_by_land_type(text)
19
+ self.all.select do |mana_type|
20
+ text.include? mana_type.land_type
21
+ end
22
+ end
23
+
24
+ def self.search_text_by_color(text)
25
+ self.all.select do |mana_type|
26
+ text.include? mana_type.color
27
+ end
28
+ end
29
+
30
+ class Red < ManaType
31
+ def initialize
32
+ super("R", "Mountain")
33
+ end
34
+ end
35
+ class Blue < ManaType
36
+ def initialize
37
+ super("U", "Island")
38
+ end
39
+ end
40
+ class Green < ManaType
41
+ def initialize
42
+ super("G", "Forest")
43
+ end
44
+ end
45
+ class White < ManaType
46
+ def initialize
47
+ super("W", "Plains")
48
+ end
49
+ end
50
+ class Black < ManaType
51
+ def initialize
52
+ super("B", "Swamp")
53
+ end
54
+ end
7
55
  end
@@ -1,6 +1,6 @@
1
1
  class Planner
2
2
 
3
- def plan(hands, fields)
3
+ def plan(hands, fields, deck)
4
4
  lands_in_hand = lands(hands)
5
5
 
6
6
  max_price = 0
@@ -14,11 +14,12 @@ class Planner
14
14
  # dup
15
15
  current_hands = hands.dup
16
16
  current_fields = fields.dup
17
+ current_deck = deck.dup
17
18
 
18
19
  # play the land
19
20
  current_hands.delete play_land
20
21
  current_fields << play_land
21
- play_land.resolve(nil, current_hands, current_fields)
22
+ play_land.resolve(nil, current_hands, current_fields, current_deck)
22
23
 
23
24
  # search_opt_spells
24
25
  price, spells, symbols, lands =
@@ -44,7 +45,8 @@ class Planner
44
45
 
45
46
  if max_lands
46
47
  max_lands.each_with_index do |land, i|
47
- if not land.mana_produced?
48
+ if not land.mana_produced? and max_symbols[i]
49
+ debugger if max_symbols[i].nil?
48
50
  land.first_produce_symbol = max_symbols[i]
49
51
  end
50
52
  end
@@ -68,7 +70,7 @@ class Planner
68
70
  end
69
71
 
70
72
  lands.sort! do |a, b|
71
- b.color_identity_size <=> a.color_identity_size
73
+ b.mana_source_size <=> a.mana_source_size
72
74
  end
73
75
 
74
76
  price = 0
@@ -6,7 +6,7 @@ class Simulator
6
6
 
7
7
  def run
8
8
  @config.simulations.times do
9
- game = Game.new(@config.deck)
9
+ game = Game.new(@config.deck, true, @config.debugg)
10
10
  @config.turns.times do |i|
11
11
  turn = i + 1
12
12
  game.step turn
@@ -16,5 +16,8 @@ class Simulator
16
16
  end
17
17
 
18
18
  class SimulatorConfig
19
- attr_accessor :simulations, :turns, :deck
19
+ attr_accessor :simulations, :turns, :deck, :debugg
20
+ def initialize
21
+ @debugg = false
22
+ end
20
23
  end
data/lib/manasimu.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'bundler'
2
2
  Bundler.require
3
3
 
4
+ require_relative './manasimu/mana_type.rb'
4
5
  require_relative './manasimu/card.rb'
6
+ require_relative './manasimu/card/basicland.rb'
5
7
  require_relative './manasimu/card/pathway.rb'
6
8
  require_relative './manasimu/card/tapland.rb'
7
9
  require_relative './manasimu/card/slowland.rb'
10
+ require_relative './manasimu/card/snc_fetchland.rb'
8
11
  require_relative './manasimu/planner.rb'
9
12
  require_relative './manasimu/game.rb'
10
13
  require_relative './manasimu/simulator.rb'
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.14
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - so1itaryrove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-15 00:00:00.000000000 Z
11
+ date: 2022-05-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: mtg arrena mana curve simulator
14
14
  email: so1itaryrove@gmail.com
@@ -20,8 +20,10 @@ files:
20
20
  - ext/ford_fulkerson.so
21
21
  - lib/manasimu.rb
22
22
  - lib/manasimu/card.rb
23
+ - lib/manasimu/card/basicland.rb
23
24
  - lib/manasimu/card/pathway.rb
24
25
  - lib/manasimu/card/slowland.rb
26
+ - lib/manasimu/card/snc_fetchland.rb
25
27
  - lib/manasimu/card/tapland.rb
26
28
  - lib/manasimu/data.rb
27
29
  - lib/manasimu/game.rb