diff --git a/.gitignore b/.gitignore index 7191ceb..9e76dae 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Created by .ignore support plugin (hsz.mobi) *.pdf +*.pkl todo.txt check_kbbot.py diff --git a/api/engine.py b/api/engine.py index a581b54..e1998e6 100644 --- a/api/engine.py +++ b/api/engine.py @@ -5,11 +5,12 @@ from multiprocessing import Process, Manager def play( - player1, - player2, + player1, # type: Bot + player2, # type: Bot state, # type: State max_time=5000, # type: int - verbose=True # type: bool + verbose=True, # type: bool + fast=False # type: bool ): """ Play a game between two given players, from the given starting state. @@ -25,7 +26,7 @@ def play( # We introduce a state signature which essentially obscures the deck's perfect knowledge from the player given_state = state.clone(signature=state.whose_turn()) if state.get_phase() == 1 else state.clone() - move = get_move(given_state, player, max_time, verbose) + move = player.get_move(given_state) if fast else get_move(given_state, player, max_time, verbose) if is_valid(move, player): # check for common mistakes diff --git a/tournament.py b/tournament.py index 1322de2..8b43ee2 100644 --- a/tournament.py +++ b/tournament.py @@ -8,7 +8,7 @@ from argparse import ArgumentParser from api import State, util, engine -import random +import random, time def run_tournament(options): @@ -35,21 +35,20 @@ def run_tournament(options): p = [b, a] # Generate a state with a random seed - start = State.generate(phase=int(options.phase)) + state = State.generate(phase=int(options.phase)) - winner = engine.play(bots[p[0]], bots[p[1]], start, options.max_time*1000, verbose=False) + winner, score = engine.play(bots[p[0]], bots[p[1]], state, options.max_time*1000, verbose=False, fast=options.fast) - #TODO: ALSO IMPLEMENT POINTS FOR WINNING if winner is not None: - winner = p[winner[0] - 1] - wins[winner] += 1 + winner = p[winner - 1] + wins[winner] += score playedgames += 1 print('Played {} out of {:.0f} games ({:.0f}%): {} \r'.format(playedgames, totalgames, playedgames/float(totalgames) * 100, wins)) print('Results:') for i in range(len(bots)): - print(' bot {}: {} wins'.format(bots[i], wins[i])) + print(' bot {}: {} points'.format(bots[i], wins[i])) if __name__ == "__main__": @@ -77,6 +76,11 @@ def run_tournament(options): help="maximum amount of time allowed per turn in seconds (default: 5)", type=int, default=5) + parser.add_argument("-f", "--fast", + dest="fast", + action="store_true", + help="This option forgoes the engine's check of whether a bot is able to make a decision in the allotted time, so only use this option if you are sure that your bot is stable.") + options = parser.parse_args() run_tournament(options)