Skip to content

Commit

Permalink
Added tournament fast mode flag, only use if your bot is stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
ursulean committed Jan 23, 2019
1 parent 2159cda commit 6d23698
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Created by .ignore support plugin (hsz.mobi)

*.pdf
*.pkl

todo.txt
check_kbbot.py
Expand Down
9 changes: 5 additions & 4 deletions api/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand Down
18 changes: 11 additions & 7 deletions tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from argparse import ArgumentParser
from api import State, util, engine
import random
import random, time

def run_tournament(options):

Expand All @@ -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__":
Expand Down Expand Up @@ -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)

0 comments on commit 6d23698

Please sign in to comment.