manasimu 0.0.15 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edeb30bfc6e2c9a608856f5806fd5b34b8ab9cd6930462cd0dae8e219de08194
4
- data.tar.gz: dc7eaa4a60ea42b6a842ccc13df0a4831ba4d805c0f12b2ecfa5d7969aed5304
3
+ metadata.gz: 8d6ea60d2d69b6ec0c517c241c03f51dedb5fcb6f9830d01c5e43a71ca952fb3
4
+ data.tar.gz: d918b9183adf48e7fd623234f05fce40d9b880ffe80719d9c6532e191b65fafe
5
5
  SHA512:
6
- metadata.gz: 1647c593a3f49a13ecf430ff9aaf8df1d7286c74e73b179fc04b2badd05b72c2be9ee5ac44d8c2e1cb32d8ae8b7e6458c54e26b57f5b11f2fcf9e8b33f5486cf
7
- data.tar.gz: a2398b09125d7b7fa8538e4068a48f3dceb3d0262b4b9e1a9ebdc174ff2f1cb4f236965f66329f55d6f2b23cc85abbb5f707529daa1b68097c1ed07094d9c8ec
6
+ metadata.gz: 0747c61c051fc5477ddb4c695d0b6a53d2038ad52861cd989d3a6cdb7ff8a5e21661c6bf3da6a9eca3a0ff87c260f7ac4c7ee5ba512fcad9e012e65b668ef77a
7
+ data.tar.gz: b60ead57d04031778ce0d618c9ebf00726e78523deff225aeefc34b4235444546224f7611d1aea215b4a8fdb34bb70a7bf8a935cd575f177a742ef3a6030d840
Binary file
@@ -0,0 +1,3 @@
1
+ class BasicLandCard < Card
2
+
3
+ end
@@ -0,0 +1,64 @@
1
+ class FetchLandCard < TapLandCard
2
+ attr_accessor :deck
3
+
4
+ # enter the battlefield
5
+ def resolve(side, hands, plays, deck)
6
+ super(side, hands, plays, deck)
7
+ return @fetch_source if @fetch_source
8
+ if deck
9
+ @fetches = deck
10
+ .select { |card| card.instance_of? BasicLandCard }
11
+ .select { |card| @mana_source.include? card.mana_source[0] }
12
+ .uniq { |card| card.card_type }
13
+ @deck = deck
14
+ @fetch_source = @fetches.map { |card| card.mana_source }.flatten.uniq
15
+ else
16
+ @fetches = []
17
+ @fetch_source = []
18
+ end
19
+ end
20
+
21
+ def first_produce_symbol=(color)
22
+ super(color)
23
+ basic_land = @deck
24
+ .select { |card| card.instance_of? BasicLandCard }
25
+ .select { |card| color.to_i.to_s == color || card.mana_source.include?(color) }
26
+ .first
27
+ if basic_land
28
+ @fetched = color
29
+ @deck.delete basic_land
30
+ @deck.shuffle!
31
+ @fetch_source = basic_land.mana_source
32
+ @fetches = [basic_land]
33
+ else
34
+ raise Exception.new('basic land is empty')
35
+ end
36
+ @deck
37
+ end
38
+
39
+ def mana_source
40
+ raise Exception.new('you should resolve first') if not @fetch_source
41
+ @fetch_source
42
+ end
43
+
44
+ def mana_source=(m)
45
+ @mana_source = m
46
+ end
47
+
48
+ def configure
49
+ mana_types = ManaType.all
50
+ @mana_source = mana_types.map {|mana_type| mana_type.color}.flatten.uniq
51
+ @fetched = nil
52
+ self
53
+ end
54
+
55
+ def reset
56
+ super
57
+ @fetched = nil
58
+ @fetch_source = nil
59
+ end
60
+
61
+ def mana_produced?
62
+ not @fetched.nil?
63
+ end
64
+ 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,8 @@
1
+ class SncFetchLandCard < FetchLandCard
2
+
3
+ def configure
4
+ mana_types = ManaType.search_text_by_land_type(card_type.text)
5
+ super.mana_source = mana_types.map {|mana_type| mana_type.color}.flatten.uniq
6
+ self
7
+ end
8
+ end
@@ -4,8 +4,9 @@ class TapLandCard < Card
4
4
  @tapped
5
5
  end
6
6
 
7
- def resolve(side, hands, plays)
8
- super(side, hands, plays)
7
+ # when enter the battlefield
8
+ def resolve(side, hands, plays, deck)
9
+ super(side, hands, plays, deck)
9
10
  @tapped = true
10
11
  end
11
12
 
@@ -14,6 +15,10 @@ class TapLandCard < Card
14
15
  @tapped = false
15
16
  end
16
17
 
18
+ def tappend=(tapped)
19
+ @tapped = tapped
20
+ end
21
+
17
22
  def reset
18
23
  super
19
24
  @tapped = false
data/lib/manasimu/card.rb CHANGED
@@ -6,6 +6,9 @@ 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
13
  @card_type.step_in_hands(turn, self)
11
14
  @can_play = false
@@ -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
@@ -149,8 +164,8 @@ class CardType
149
164
  def step_in_plays(turn, card)
150
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]
@@ -341,6 +376,10 @@ class CardType
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,25 @@ 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.text =~ /earch your library for a basic land card, put it onto the battlefield tapped, then shuffle/
81
+ card = FetchLandCard.new(clone)
82
+ card.configure
83
+ elsif clone.set_code == 'SNC' and
84
+ clone.contents[0].text =~ /enters the battlefield, sacrifice it/
85
+ card = SncFetchLandCard.new(clone)
86
+ card.configure
87
+ elsif clone.type[0] =~ /^Basic Land — .*$/
88
+ card = BasicLandCard.new(clone)
89
+ else
90
+ card = Card.new(clone)
91
+ end
81
92
  else
82
93
  card = Card.new(clone)
83
94
  end
data/lib/manasimu/game.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Game
2
2
  attr_accessor :hands, :plays, :deck
3
3
 
4
- def initialize(deck, shuffle = true)
4
+ def initialize(deck, shuffle = true, debugg = false)
5
5
  if shuffle
6
6
  @deck = deck.shuffle(random: Random.new)
7
7
  else
@@ -11,39 +11,49 @@ class Game
11
11
  @hands = []
12
12
  @plays = []
13
13
  @planner = Planner.new
14
+ @debugg = debugg
14
15
  7.times { draw(0) }
15
16
  end
16
17
 
17
18
  def step(turn)
18
- # puts "turn #{turn}"
19
- # puts "played"
20
- # @plays.each do |card| puts " #{card}" end
21
- # puts "hands"
22
- # @hands.each do |card| puts " #{card}" end
19
+ if @debugg
20
+ puts "---------------------------------"
21
+ puts "turn #{turn} basic_lands #{@deck.select {|c| c.instance_of? BasicLandCard}.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
23
27
 
24
28
  draw(turn)
25
- play_cards = plan;
29
+ play_cards, deck = plan;
26
30
  @hands.each { |card| card.step_in_hands(turn) }
27
- plan.each do |card|
31
+ play_cards.each do |card|
28
32
  play(card, turn)
29
33
  end
34
+ deck = deck if deck
30
35
  @plays.each { |card| card.step_in_plays(turn) }
31
36
  end
32
37
 
33
38
  def draw(turn)
34
39
  card = @deck.pop
35
- # puts "draw #{card}"
40
+ if @debugg
41
+ puts "draw #{card}"
42
+ end
36
43
  card.drawed(turn)
37
44
  @hands << card
38
45
  end
39
46
 
40
47
  def plan
41
- @planner.plan(@hands, @plays)
48
+ @planner.plan(@hands, @plays, @deck)
42
49
  end
43
50
 
44
51
  def play(card, turn)
45
- # puts "play #{card}"
46
- card.resolve(nil, @hands, @plays)
52
+ if @debugg
53
+ puts "play #{card}"
54
+ end
55
+
56
+ card.resolve(nil, @hands, @plays, @deck)
47
57
  card.played(turn, nil)
48
58
  @plays << card
49
59
  @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 =
@@ -42,15 +43,17 @@ class Planner
42
43
  max_land = lands_in_hand[0]
43
44
  end
44
45
 
46
+ deck = nil
45
47
  if max_lands
46
48
  max_lands.each_with_index do |land, i|
47
- if not land.mana_produced?
49
+ if not land.mana_produced? and max_symbols[i]
48
50
  land.first_produce_symbol = max_symbols[i]
51
+ deck = land.deck if land.respond_to? :deck
49
52
  end
50
53
  end
51
54
  end
52
55
 
53
- [max_land, max_spells].select {|a| a}.flatten
56
+ [[max_land, max_spells].select {|a| a}.flatten, deck]
54
57
  end
55
58
 
56
59
  #
@@ -68,7 +71,7 @@ class Planner
68
71
  end
69
72
 
70
73
  lands.sort! do |a, b|
71
- b.color_identity_size <=> a.color_identity_size
74
+ b.mana_source_size <=> a.mana_source_size
72
75
  end
73
76
 
74
77
  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,14 @@
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/fetchland.rb'
11
+ require_relative './manasimu/card/snc_fetchland.rb'
8
12
  require_relative './manasimu/planner.rb'
9
13
  require_relative './manasimu/game.rb'
10
14
  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.15
4
+ version: 0.0.18
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,11 @@ files:
20
20
  - ext/ford_fulkerson.so
21
21
  - lib/manasimu.rb
22
22
  - lib/manasimu/card.rb
23
+ - lib/manasimu/card/basicland.rb
24
+ - lib/manasimu/card/fetchland.rb
23
25
  - lib/manasimu/card/pathway.rb
24
26
  - lib/manasimu/card/slowland.rb
27
+ - lib/manasimu/card/snc_fetchland.rb
25
28
  - lib/manasimu/card/tapland.rb
26
29
  - lib/manasimu/data.rb
27
30
  - lib/manasimu/game.rb