Ejemplo n.º 1
0
    def get_action(self, team, actions):
        # optimizations, plus a heuristic.
        if len(actions) == 1:
            return actions[0]

        children = list(map(lambda x : [x, 0, 0], actions))

        fblu = 0
        fred = 0

        with Timer() as t:
            while t.get_secs() < self.budget:
                child = random.choice(children)
                action = child[0]
                
                board = self.board.get_cpy()

                if action:
                    self.actionhash[action[0]](board, action[1], action[2])

                gm = GameMaster(board, Player(), Player())
                gm.play(loud=False)

                if self.utility(gm.board, team) > 0.5:
                    fred += 1
                else:
                    fblu += 1

                child[1] += self.utility(gm.board, team)
                child[2] += 1

        # print("\n\n!!! Simulations Complete: " + str(fblu+fred) + " !!!")
        # print("!!! \tFavor blu: " + str(fblu) + " !!!")
        # print("!!! \tFavor red: " + str(fred) + " !!!\n\n")


        bestaction = children[0][0]
        bestscore = 0

        for child in children:
            # Not sure if this is the best way to handle no data.
            if child[2] != 0 and bestscore < child[1]/child[2]:
                bestaction = child[0]
                bestscore = child[1]/child[2]

        return bestaction
Ejemplo n.º 2
0
from player import Player
from mcts import MCTS
from board import Board
from gm import GameMaster

import cProfile
import sys

dim = int(sys.argv[1])
budget = (float(sys.argv[2])/1000)

board = Board(dim, dim)

# initialize units

for team in [("red", 0), ("blu", dim-1)]:
    for i in range(0, dim):
        board.add_unit(i, team[1], team[0], 4)

gm = GameMaster(board, MCTS(budget), Player())
#cProfile.run('gm.play(loud=True)')
print(gm.play(loud=False))
Ejemplo n.º 3
0
from player import Player
from mcts import MCTS
from board import Board
from gm import GameMaster

import cProfile
import sys

dim = int(sys.argv[1])
budget = (float(sys.argv[2])/1000)

board = Board(dim, dim)

# initialize units

for team in [("red", 0), ("blu", dim-1)]:
    for i in range(0, dim):
        board.add_unit(i, team[1], team[0], 4)

gm = GameMaster(board, MCTS(budget), Player())
#cProfile.run('gm.play(loud=True)')
print(gm.play(loud=True))
Ejemplo n.º 4
0
from player import Player
from mcts import MCTS
from board import Board
from gm import GameMaster

import cProfile
import sys

dim = int(sys.argv[1])
budget = (float(sys.argv[2]) / 1000)

board = Board(dim, dim)

# initialize units

for team in [("red", 0), ("blu", dim - 1)]:
    for i in range(0, dim):
        board.add_unit(i, team[1], team[0], 4)

gm = GameMaster(board, MCTS(budget), Player())
#cProfile.run('gm.play(loud=True)')
print(gm.play(loud=True))
Ejemplo n.º 5
0
from player import Player
from mcts import MCTS
from board import Board
from gm import GameMaster

import cProfile
import sys

dim = int(sys.argv[1])
budget = (float(sys.argv[2]) / 1000)

board = Board(dim, dim)

# initialize units

for team in [("red", 0), ("blu", dim - 1)]:
    for i in range(0, dim):
        board.add_unit(i, team[1], team[0], 4)

gm = GameMaster(board, MCTS(budget), Player())
#cProfile.run('gm.play(loud=True)')
print(gm.play(loud=False))