Beispiel #1
0
def test_agent_once(one, other = None):
	#print("game_started")
	generator = RandomDeckGenerator()
	deck1 = generator.generate()
	deck2 = deck1.copy()

	if other is None:
		other = TradeAgent()
		#other = RandomAgent()
	game = Game([deck1, deck2], [one, other])
	new_game = game.copy()
	try:
		new_game.start()
		# new_data = GameHistoryGenerator.process_history(history, new_game)
		# Data = open("data.txt", "a")
		# for i in new_data:
			# tmp = i[0]
			# tmp.append(i[1])
			# for j in range(len(tmp)):
				# tmp[j] = str(tmp[j])
			# Data.write(" ".join(tmp))
			# Data.write("\n")
		# Data.close()
		print("Game lasted: " + str(new_game._turns_passed))
		print("winning agent: " + new_game.winner.agent.name)
	except Exception as e:
		print("Game error: " + str(e))
		# raise e
		return False
	
	# spark_weights(ql.weights)
	return new_game.winner.agent.name
def enshelf_one(index):
    loader = DeckLoader()
    generator = RandomDeckGenerator()
    # deck1 = loader.load_deck("zoo.hsdeck")
    # deck2 = loader.load_deck("zoo.hsdeck")
    deck1 = generator.generate()
    deck2 = generator.generate()
    game = Game([deck1, deck2], [TradeAgent(), TradeAgent()])
    new_game = game.copy()
    game_log = Hearthlogger()
    game_log.attach(new_game)
    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)
       del new_game
       del game_log
       print(e)
       return False
    # print("winning agent: " + new_game.winner.agent.__class__.__name__)
    game_log.shelf(index)
    del new_game
    del game_log
    return True
def generate_replays():
    loader = DeckLoader()
    deck1 = loader.load_deck("patron.hsdeck")
    deck2 = loader.load_deck("patron.hsdeck")
    game = Game([deck1, deck2], [RandomAgent(), RandomAgent()])
    new_game = game.copy()
    replay = record(new_game)
    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

    replay.write_json("replay_text.hsreplay")
    del new_game
    print("done!")
Beispiel #4
0
def test_agent_once(one, other):
    generator = RandomDeckGenerator()
    deck1 = generator.generate()
    deck2 = deck1.copy()

    if other is None:
        other = TradeAgent()
        #other = RandomAgent()
    game = Game([deck1, deck2], [one, other])
    new_game = game.copy()
    try:
        new_game.start()
    except Exception as e:
        print("Game error: " + str(e))
        raise e
        # raise
        #print(json.dumps(new_game.__to_json__(), default=lambda o: o.__to_json__(), indent=1))
        # new_game
        return False
    print("Game lasted: " + str(new_game._turns_passed))
    print("winning agent: " + new_game.winner.agent.name)
    # spark_weights(ql.weights)
    return new_game.winner.agent.name