Esempio n. 1
0
 def __init__(self, verbose: bool = False, fast: bool = False):
     self._game = Game()
     self._goatAgent: Agent = RandomAgent(self._game, Const.MARK_GOAT)
     self._tigerAgent: Agent = RandomAgent(self._game, Const.MARK_TIGER)
     self._verbose = verbose
     self._fast = fast
     if not self._fast:
         self._shadowGame = Game()
Esempio n. 2
0
def setup(args) -> Playoff:
    game=Game()
    verbose=False
    fast=False
    trials=1
    goats : List[Agent] = []
    tigers : List[Agent] = []
    for i in range(len(args)):
        if args[i] == "--verbose":
            verbose = True
            continue
        if args[i] == "--fast":
            fast = True
            continue
        matched=re.match(r'--trials=([0-9]+)',args[i])
        if matched:
            trials = int(matched.group(1))
            continue
        matched=re.match(r'--goat=(.*)',args[i])
        if matched:
            name=matched.group(1)
            clazz=load_class(name)
            agent=clazz(game,Const.MARK_GOAT)
            goats.append((name + " goat",agent))
            continue
        matched=re.match(r'--metagoat\[(.*)\]',args[i])
        if matched:
            parms=matched.group(1)
            agent=metaagent(game,Const.MARK_GOAT,parms)
            goats.append((" metagoat[" + parms + "]",agent))

            continue
        matched=re.match(r'--tiger=(.*)',args[i])
        if matched:
            name=matched.group(1)
            clazz=load_class(name)
            agent=clazz(game,Const.MARK_TIGER)
            tigers.append((name + " tiger",agent))
            continue
        matched=re.match(r'--metatiger\[(.*)\]',args[i])
        if matched:
            parms=matched.group(1)
            agent=metaagent(game,Const.MARK_TIGER,parms)
            tigers.append((" metatiger[" + parms + "]",agent))
            continue
    
    if len(goats) == 0:
        goats.append(('default random goat',RandomAgent(game,Const.MARK_GOAT)))
    if len(tigers) == 0:
        tigers.append(('default random tiger',RandomAgent(game,Const.MARK_TIGER)))
    playoff=Playoff(trials,verbose, fast)
    for (name,agent) in goats:
        playoff.addGoatAgent(name,agent)
    for (name,agent) in tigers:
        playoff.addTigerAgent(name,agent)
    return playoff
def main():
    agent = RandomAgent()
    env = gym.make('SimpleFetch-v0')
    env.place_objects([
        Block.SMALL,
        #            Block.MEDIUM,
        #            Block.LARGE
    ])
    #env.place_objects([Block.SMALL], [Pose(1, 1, 1)])
    observation = env.reset()
    finish = False
    while not finish:
        action = agent.choose_action(observation)
        observation, _, finish, _ = env.step(action)
        if finish:
            print("Told to finish-- loop will now terminate")
Esempio n. 4
0
def main():
    random.seed(None)
    human_agent = HumanAgent()
    basic_agent = BasicAgent()
    random_agent = RandomAgent()
    game = Game(goal_size=8)
    #game = rig_game(game, 0)
    game = GameRunner(game, [basic_agent, random_agent])
    game.play()
Esempio n. 5
0
from const import Const
from game import Game
import random
from matchup import Matchup
from randomagent import RandomAgent
from shygoatagent import ShyGoatAgent
from playoff import Playoff

game = Game()
playoff = Playoff(trials=10, verbose=False)

playoff.addGoatAgent("shy goat", ShyGoatAgent(game))
playoff.addTigerAgent("random tiger", RandomAgent(game, Const.MARK_TIGER))

playoff.play()
Esempio n. 6
0
 def __init__(self):
     self._game = Game()
     self._goatAgent : Agent = RandomAgent(self._game, Const.MARK_GOAT)
     self._tigerAgent : Agent = RandomAgent(self._game,Const.MARK_TIGER)
def playGameRandom(colour, genes, gamesToPlay, debug):

    win = False
    blackWon = False
    whiteWon = False
    agentColour = ""

    if colour == Piece.Black:
        blackTeam = Agent(genes, 'b')
        whiteTeam = RandomAgent(Piece.White)
        agentColor = "Black"
    else:
        whiteTeam = Agent(genes, 'w')
        blackTeam = RandomAgent(Piece.Black)
        agentColor = "White"

    for gameIndex in range(0, gamesToPlay):
        #initialize empty board
        state = [[0] * 20, 7, 7, 0]
        isBlackTurn = True  # True if it's black's turn, False otherwise

        while not win:
            #roll the die and return the move
            #it's possible to have no moves, in this case
            #return the current state so as to not take a turn
            state[3] = rollDie()
            if (state[3] == 0):
                isBlackTurn = not isBlackTurn  # skip turn if die roll is 0
                continue

            # play Turn
            if isBlackTurn:  # black's turn
                blackMove, extraTurn = blackTeam.playTurn(state, debug)
                state = blackMove if blackMove is not None else state  # handle cases where no moves are available
            else:  # white's turn
                whiteMove, extraTurn = whiteTeam.playTurn(state, debug)
                state = whiteMove if whiteMove is not None else state

            # blackTeam.prettyPrintState(state)

            # check if last turn finished the game
            if winGame(state):
                blackWon = True if isBlackTurn else False
                win = True
                break
            else:  # game not yet over
                isBlackTurn = not isBlackTurn if not extraTurn else isBlackTurn  # swap turns if extraturn == False, grant extra turn if extraTurn == True

        #for sake of fairness, swap agents after each game
        # temp = whiteTeam
        # whiteTeam = blackTeam
        # blackTeam = temp

        if DEBUG:  # debug print
            # if blackWon:
            #     print("Black Genetic Agent Won Game " + str(gameIndex))
            # else: #whiiteWon
            #     print("White Genetic Agent Won Game " + str(gameIndex))

            if (blackWon and agentColour
                    == "Black") or (whiteWon and agentColour == "White"):
                print("Genetic Agent Won Game " + str(gameIndex))
            else:
                print("Random Agent Won Game " + str(gameIndex))

            return blackWon

    return blackWon  # return True if black won, and False if White won
Esempio n. 8
0
 def __init__(self, game: Game, side: int):
     super(MetaAgent, self).__init__(game, side)
     self._goat: Agent = RandomAgent(game, Const.MARK_GOAT)
     self._tiger: Agent = RandomAgent(game, Const.MARK_TIGER)
     self._maxDepth = 2