Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- DECK = ["fetch"]*7 + ["arbor"] + ["khalni"]*3 + ["woodland"]*1 + ["ug"]*2 + ["g"]*3 + ["u"] + ["yavimaya"] + ["saga"]*4 + ["tapland"] \
- + ["nadu"]*4 + ["nantuko"]*4 + ["chord"]*4 + ["1-drop"]*8 + ["drum"] + ["endurance"]*2 + ["shuko"]*3 + ["ring"] + ["chat"] + ["venser"] + ["outrider"] + ["stormdrake"]*2 + ["mumble"]*4
- LANDS = ["fetch", "arbor", "khalni", "woodland", "ug", "g", "u", "yavimaya", "saga", "tapland"]
- GREEN_CARDS = ["arbor", "nadu", "chord", "endurance", "mumble", "1-drop", "nantuko"]
- ITER = 1000000
- PRINT_ITER = 10
- INIT_HAND = 4
- INIT_CREATURES = 3
- INIT_LANDS = [] # type: ignore[var-annotated]
- INIT_REMOVE = ["nadu", "shuko", "saga", "ug", "fetch", "g", "ring"]
- class Iteration:
- nantuko: int
- triggers: int
- creatures: int
- untapped: int
- yavimaya: bool
- lands: list[str]
- deck: list[str]
- hand: list[str]
- def __init__(self, init_creatures, init_hand, init_lands, init_remove):
- self.nantuko = 1
- self.triggers = 2*init_creatures
- self.creatures = init_creatures
- self.untapped = init_creatures
- self.yavimaya = False
- self.lands = init_lands.copy()
- self.deck = DECK.copy()
- for r in init_remove:
- self.deck.remove(r)
- random.shuffle(self.deck)
- self.hand = []
- for h in range(init_hand):
- self.hand.append(self.deck.pop())
- if ITER <= PRINT_ITER:
- print(self.hand)
- def add_creature(self):
- self.triggers += 2
- self.creatures += 1
- self.untapped += 1
- if ITER <= PRINT_ITER:
- print("ADDED CREATURE")
- def trigger_landfall(self):
- self.triggers += self.nantuko*2
- self.creatures += self.nantuko
- self.untapped += self.nantuko
- def reset_nadu(self):
- self.triggers = self.creatures * 2
- def resolve_nadu_trigger(self):
- # do a trigger
- self.triggers -= 1
- card = self.deck.pop()
- if ITER <= PRINT_ITER:
- print(card)
- if card in LANDS:
- self.trigger_landfall()
- if card == "arbor" or card == "khalni":
- self.add_creature()
- if card != "tapland" and card != "khalni":
- self.lands.append(card)
- else:
- self.hand.append(card)
- def try_cast_chord(self, n):
- if "chord" not in self.hand:
- return False
- can_cast = False
- if self.untapped < 3:
- if self.try_cast_spell("chord", n, 3-self.untapped, 0, cast=False):
- self.untapped = 0
- can_cast = True
- elif self.untapped <= 3+n:
- if self.try_cast_spell("chord", 3+n-self.untapped, 0, 0, cast=False):
- self.untapped = 0
- can_cast = True
- else:
- if self.try_cast_spell("chord", 0, 0, 0, cast=False):
- self.untapped -= 3+n
- can_cast = True
- if not can_cast and "endurance" in self.hand:
- temp_hand = self.hand.copy()
- temp_hand.remove("chord")
- temp_hand.remove("endurance")
- pitched = False
- for g in GREEN_CARDS:
- if g in temp_hand:
- temp_hand.remove(g)
- pitched = True
- break
- if not pitched:
- return False
- temp_hand.append("chord")
- if self.untapped < 2:
- if self.try_cast_spell("chord", n, 2-self.untapped, 0, cast=False):
- self.untapped = 0
- can_cast = True
- elif self.untapped <= 2+n:
- if self.try_cast_spell("chord", 2+n-self.untapped, 0, 0, cast=False):
- self.untapped = 0
- can_cast = True
- else:
- if self.try_cast_spell("chord", 0, 0, 0, cast=False):
- self.untapped -= 2+n
- can_cast = True
- if can_cast:
- if ITER <= PRINT_ITER:
- print("ACTION: pitching endurance")
- self.hand = temp_hand
- self.untapped += 1
- if can_cast:
- if ITER <= PRINT_ITER:
- print("ACTION: chording for", n)
- if self.untapped < 3+n and "fetch" in self.lands and "arbor" in self.deck:
- self.lands.remove("fetch")
- self.trigger_landfall()
- self.add_creature()
- while self.untapped < 3+n and "1-drop" in self.hand and self.try_cast_spell("1-drop", 0, 1, 0):
- self.add_creature()
- if self.untapped < 3:
- if self.try_cast_spell("chord", n, 3-self.untapped, 0):
- self.untapped = 0
- elif self.untapped <= 3+n:
- if self.try_cast_spell("chord", 3+n-self.untapped, 0, 0):
- self.untapped = 0
- else:
- if self.try_cast_spell("chord", 0, 0, 0):
- self.untapped -= 3+n
- return True
- return False
- def try_cast_spell(self, name, c_cost, g_cost, u_cost, cast=True):
- if name not in self.hand:
- return False
- temp = self.lands.copy()
- temp_deck = self.deck.copy()
- num_fetched = 0
- if u_cost > 0:
- if "u" in temp:
- temp.remove("u")
- elif "ug" in temp:
- temp.remove("ug")
- elif "fetch" in temp and "u" in temp_deck:
- temp.remove("fetch")
- temp_deck.remove("u")
- num_fetched += 1
- elif "fetch" in temp and "ug" in temp_deck:
- temp.remove("fetch")
- temp_deck.remove("ug")
- num_fetched += 1
- else:
- return False
- if self.yavimaya:
- c_cost += g_cost
- g_cost = 0
- for g in range(g_cost):
- if "g" in temp:
- temp.remove("g")
- elif "woodland" in temp:
- temp.remove("woodland")
- elif "yavimaya" in temp:
- temp.remove("yavimaya")
- elif "ug" in temp:
- temp.remove("ug")
- elif "fetch" in temp and "g" in temp_deck:
- temp.remove("fetch")
- temp_deck.remove("g")
- num_fetched += 1
- elif "fetch" in temp and "ug" in temp_deck:
- temp.remove("fetch")
- temp_deck.remove("ug")
- num_fetched += 1
- else:
- return False
- for c in range(c_cost):
- if "saga" in temp:
- temp.remove("saga")
- elif "g" in temp:
- temp.remove("g")
- elif "woodland" in temp:
- temp.remove("woodland")
- elif "yavimaya" in temp:
- temp.remove("yavimaya")
- elif "fetch" in temp and self.yavimaya:
- temp.remove("fetch")
- elif "u" in temp:
- temp.remove("u")
- elif "ug" in temp:
- temp.remove("ug")
- elif "fetch" in temp and "g" in temp_deck:
- temp.remove("fetch")
- temp_deck.remove("g")
- elif "fetch" in temp and "u" in temp_deck:
- temp.remove("fetch")
- temp_deck.remove("u")
- num_fetched += 1
- elif "fetch" in temp and "ug" in temp_deck:
- temp.remove("fetch")
- temp_deck.remove("ug")
- num_fetched += 1
- else:
- return False
- if cast:
- self.lands = temp
- self.deck = temp_deck
- for i in range(num_fetched):
- self.trigger_landfall()
- self.hand.remove(name)
- if ITER <= PRINT_ITER:
- print("ACTION: cast", name)
- return True
- def log(self):
- if ITER <= PRINT_ITER:
- print("remaining deck:", len(self.deck))
- print("hand:", self.hand)
- print("lands:", self.lands)
- print("nantukos:", self.nantuko)
- print("untapped:", self.untapped)
- success = 0
- for it in range(ITER):
- i = Iteration(INIT_CREATURES, INIT_HAND, INIT_LANDS, INIT_REMOVE)
- while i.triggers > 0 and len(i.deck) > 0:
- i.resolve_nadu_trigger()
- # try generate more triggers
- if i.triggers == 0:
- # try play nadu
- if i.try_cast_spell("nadu", 1, 1, 1):
- i.reset_nadu()
- # try chord for nadu
- if "nadu" in i.deck and i.try_cast_chord(3):
- i.deck.remove("nadu")
- i.reset_nadu()
- # try play nantuko
- if i.try_cast_spell("nantuko", 1, 1, 0):
- i.nantuko += 1
- i.add_creature()
- # try chord for nantuko
- if "nantuko" in i.deck and i.try_cast_chord(2):
- i.deck.remove("nantuko")
- i.nantuko += 1
- i.add_creature()
- if i.triggers != 0:
- continue
- # try fetch arbor
- if "fetch" in i.lands and "arbor" in i.deck:
- if ITER <= PRINT_ITER:
- print("ACTION: fetch arbor")
- i.deck.remove("arbor")
- i.lands.remove("fetch")
- i.add_creature()
- i.trigger_landfall()
- continue
- # try cast 1-drop
- if i.try_cast_spell("1-drop", 0, 1, 0):
- i.add_creature()
- continue
- # try cast mumble
- if i.try_cast_spell("mumble", 1, 1, 0):
- i.add_creature()
- i.lands.append("saga")
- # TODO: SELECTION
- continue
- # try cast stormdrake
- if i.try_cast_spell("stormdrake", 1, 0, 1):
- i.add_creature()
- continue
- # try chord for arbor
- if "arbor" in i.deck and i.try_cast_chord(0):
- i.deck.remove("arbor")
- i.add_creature()
- continue
- # try chord for 1
- if "1-drop" in i.deck and i.try_cast_chord(1):
- i.deck.remove("1-drop")
- i.add_creature()
- continue
- # try cast endurance
- if i.try_cast_spell("endurance", 1, 2, 0):
- i.add_creature()
- continue
- # try cast outrider
- if i.try_cast_spell("outrider", 2, 0, 1):
- i.add_creature()
- continue
- # try cast venser
- if i.try_cast_spell("venser", 2, 0, 2):
- i.add_creature()
- continue
- if len(i.deck) == 0:
- success += 1
- if ITER <= PRINT_ITER:
- print("SUCCESS")
- else:
- i.log()
- print(success / ITER)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement