-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_games.py
60 lines (45 loc) · 1.68 KB
/
run_games.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import json
from hearthbreaker.agents.basic_agents import RandomAgent
from hearthbreaker.cards.heroes import hero_for_class
from hearthbreaker.constants import CHARACTER_CLASS
from hearthbreaker.engine import Game, Deck, card_lookup
from hearthbreaker.cards import *
import timeit
def load_deck(filename):
cards = []
character_class = CHARACTER_CLASS.MAGE
with open(filename, "r") as deck_file:
contents = deck_file.read()
items = contents.splitlines()
for line in items[0:]:
parts = line.split(" ", 1)
count = int(parts[0])
for i in range(0, count):
card = card_lookup(parts[1])
if card.character_class != CHARACTER_CLASS.ALL:
character_class = card.character_class
cards.append(card)
if len(cards) > 30:
pass
return Deck(cards, hero_for_class(character_class))
def do_stuff():
_count = 0
def play_game():
nonlocal _count
_count += 1
new_game = game.copy()
try:
new_game.start()
except Exception as e:
print(json.dumps(new_game.__to_json__(), default=lambda o: o.__to_json__(), indent=1))
print(new_game._all_cards_played)
raise e
#winner
#print(new_game.players[0].hero.dead)
del new_game
if _count % 1000 == 0:
print("---- game #{} ----".format(_count))
deck1 = load_deck("zoo.hsdeck")
deck2 = load_deck("zoo.hsdeck")
game = Game([deck1, deck2], [RandomAgent(), RandomAgent()])
print(timeit.timeit(play_game, 'gc.enable()', number=2000))