def runSim(redBot, blueBot): red_bot = __import__(redBot) blue_bot = __import__(blueBot) BOTS = {'red': red_bot, 'blue': blue_bot} ################### End importing bot ############################## for i in range(rounds): print "" print "Round %d, fight!" % i game = Game(4) state = State(game) def make_quipper(who): def quip(what): print who, ">>", what return quip while not state.is_terminal(): move = BOTS[state.whos_turn].think(state.copy(), make_quipper(state.whos_turn)) state.apply_move(move) final_score = state.get_score() winner = max(['red', 'blue'], key=final_score.get) print "The %s bot wins this round! (%s)" % (winner, str(final_score)) wins[winner] = 1 + wins[winner] print "" print "Final win counts:", dict(wins)
def runsim(rounds, redteam=None, blueteam=None, boardSize=4): wins = defaultdict(lambda: 0) # Override the bots if provided global BOARD_SIZE, BOTS if redteam: BOTS['red'] = redteam if blueteam: BOTS['blue'] = blueteam BOARD_SIZE = boardSize for i in range(rounds): print "" print "Round %d, fight!" % (i + 1) game = Game(BOARD_SIZE) state = State(game) def make_quipper(who): def quip(what): print who, ">>", what return quip while not state.is_terminal(): move = BOTS[state.whos_turn].think(state.copy(), make_quipper(state.whos_turn)) state.apply_move(move) final_score = state.get_score() winner = max(['red','blue'],key=final_score.get) print "The %s bot wins this round! (%s)" % (winner, str(final_score)) wins[winner] = 1 + wins[winner] print "" print "Final win counts:", dict(wins)
def runSim(redBot, blueBot): red_bot = __import__(redBot) blue_bot = __import__ (blueBot) BOTS = {'red': red_bot, 'blue': blue_bot} ################### End importing bot ############################## for i in range(rounds): print "" print "Round %d, fight!" % i game = Game(4) state = State(game) def make_quipper(who): def quip(what): print who, ">>", what return quip while not state.is_terminal(): move = BOTS[state.whos_turn].think(state.copy(), make_quipper(state.whos_turn)) state.apply_move(move) final_score = state.get_score() winner = max(['red','blue'],key=final_score.get) print "The %s bot wins this round! (%s)" % (winner, str(final_score)) wins[winner] = 1 + wins[winner] print "" print "Final win counts:", dict(wins)
from collections import defaultdict import greedy_bot as red_bot import uct_bot as blue_bot BOTS = {'red': red_bot, 'blue': blue_bot} rounds = 5 wins = defaultdict(lambda: 0) for i in range(rounds): print "" print "Round %d, fight!" % i game = Game(4) state = State(game) def make_quipper(who): def quip(what): print who, ">>", what return quip while not state.is_terminal(): move = BOTS[state.whos_turn].think(state.copy(), make_quipper(state.whos_turn)) state.apply_move(move) final_score = state.get_score() winner = max(['red', 'blue'], key=final_score.get) print "The %s bot wins this round! (%s)" % (winner, str(final_score))
if hasattr(red_bot, 'num_nodes'): red_bot.num_nodes = 1000 if hasattr(blue_bot, 'num_nodes'): blue_bot.num_nodes = 1000 rounds = 100 wins = {} start = time() # To log how much time the simulation takes. for i in range(rounds): print("") print("Round %d, fight!" % i) game = create_game(4) # Specify the size of the grid in vertices. In this case, 4x4 state = State(game) # Create a state from the instance of the game while not state.is_terminal(): move = BOTS[state.player_turn].think(state.copy()) state.apply_move(move) final_score = state.score winner = state.winner print("The %s bot wins this round! (%s)" % (winner, str(final_score))) wins[winner] = wins.get(winner, 0) + 1 print("") print("Final win counts:", dict(wins)) # Also output the time elapsed. end = time()
def restart(): game = Game(4) initial_state = State(game) UNDO_STACK[:] = [initial_state] display(initial_state)
red_bot.num_nodes = 1000 if hasattr(blue_bot, 'num_nodes'): blue_bot.num_nodes = 1000 rounds = 100 wins = {} start = time() # To log how much time the simulation takes. for i in range(rounds): print("") print("Round %d, fight!" % i) game = create_game( 4) # Specify the size of the grid in vertices. In this case, 4x4 state = State(game) # Create a state from the instance of the game while not state.is_terminal(): move = BOTS[state.player_turn].think(state.copy()) state.apply_move(move) final_score = state.score winner = state.winner print("The %s bot wins this round! (%s)" % (winner, str(final_score))) wins[winner] = wins.get(winner, 0) + 1 print("") print("Final win counts:", dict(wins)) # Also output the time elapsed. end = time()
from collections import defaultdict import greedy_bot as red_bot import uct_bot as blue_bot BOTS = {'red': red_bot, 'blue': blue_bot} rounds = 5 wins = defaultdict(lambda: 0) for i in range(rounds): print "" print "Round %d, fight!" % i game = Game(4) state = State(game) def make_quipper(who): def quip(what): print who, ">>", what return quip while not state.is_terminal(): move = BOTS[state.whos_turn].think(state.copy(), make_quipper(state.whos_turn)) state.apply_move(move) final_score = state.get_score() winner = max(['red','blue'],key=final_score.get) print "The %s bot wins this round! (%s)" % (winner, str(final_score)) wins[winner] = 1 + wins[winner]