Ejemplo n.º 1
0
 def __init__(self,
              game: Game,
              side: int,
              maxDepth: int = DEFAULT_MAX_DEPTH):
     super(MinMaxAgent, self).__init__(game, side)
     self._simpleTigerAgent: Agent = HungryTigerAgent(game)
     self._simpleGoatAgent: Agent = AggressiveGoatAgent(game)
     self._maxDepth: int = maxDepth
Ejemplo n.º 2
0
 def __init__(self,
              game: Game,
              side: int,
              maxDepth: int = DEFAULT_MAX_DEPTH,
              maxCacheSize: int = DEFAULT_MAX_CACHE_SIZE):
     super(CachedMinMaxAgent, self).__init__(game, side)
     self._simpleTigerAgent: Agent = HungryTigerAgent(game)
     self._simpleGoatAgent: Agent = AggressiveGoatAgent(game)
     self._maxDepth: int = maxDepth
     self._maxCacheSize: int = maxCacheSize
     self._cache: RedBlackBST[GameState, float] = RedBlackBST[GameState,
                                                              float]()
Ejemplo n.º 3
0
class OccamsGoatAgent(Agent):
    def __init__(self, game: Game):
        super(OccamsGoatAgent, self).__init__(game, Const.MARK_GOAT)
        self._hungryTigerAgent = HungryTigerAgent(game)

    def propose(self) -> Move:
        moves = self.game.goatMoves()
        safe: List[Move] = []
        wins: List[Move] = []
        loses: List[Move] = []
        draws: List[Move] = []
        scared: List[Move] = []
        # returns first possible place for goat to go, starting at a1 each time.
        # one way to make this faster, is if we know a goat has gone and been placed and NOT captured, remove that from list of moves
        # pretty sure this would only affect computation speeds, not really benefit gameplay
        if self.game._turns == 0:
            return moves[1]
        else:
            #return moves[0]
            for move in moves:
                self.game.play(move)
                tigerMove : Optional[Move] = self._hungryTigerAgent.propose() \
                    if self.game.state == Const.STATE_TURN_TIGER else None
                playedState: int = self.game.state
                self.game.unplay(move)

                if playedState == Const.STATE_WIN_GOAT:
                    wins.append(move)
                elif playedState == Const.STATE_TURN_TIGER:
                    loses.append(move)
                elif playedState == Const.STATE_DRAW:
                    draws.append(move)
                elif not tigerMove.capture:
                    safe.append(move)
                else:
                    scared.append(move)

            if len(wins) != 0:
                return random.choice(wins)
            elif len(safe) != 0:
                return random.choice(safe)
            elif len(draws) != 0:
                return random.choice(draws)
            elif len(scared) != 0:
                return random.choice(scared)
            else:
                return random.choice(moves)
Ejemplo n.º 4
0
class ScaredGoatAgent(Agent):
    def __init__(self, game: Game):
        super(ScaredGoatAgent, self).__init__(game, Const.MARK_GOAT)
        self._hungryTigerAgent = HungryTigerAgent(game)

    def propose(self) -> Move:
        moves = self.game.goatMoves()
        safe: List[Move] = []
        wins: List[Move] = []
        loses: List[Move] = []
        draws: List[Move] = []
        scared: List[Move] = []
        for move in moves:
            self.game.play(move)
            tigerMove : Optional[Move] = self._hungryTigerAgent.propose() \
                if self.game.state == Const.STATE_TURN_TIGER else None
            playedState: int = self.game.state
            self.game.unplay(move)

            if playedState == Const.STATE_WIN_GOAT:
                wins.append(move)
            elif playedState == Const.STATE_WIN_TIGER:
                loses.append(move)
            elif playedState == Const.STATE_DRAW:
                draws.append(move)
            elif not tigerMove.capture:
                safe.append(move)
            else:
                scared.append(move)
        if len(wins) != 0:
            return random.choice(wins)
        elif len(safe) != 0:
            return random.choice(safe)
        elif len(draws) != 0:
            return random.choice(draws)
        elif len(scared) != 0:
            return random.choice(scared)
        else:
            return random.choice(moves)
Ejemplo n.º 5
0
 def __init__(self, game: Game):
     super(SmartGoatAgent, self).__init__(game, Const.MARK_GOAT)
     self._hungryTigerAgent = HungryTigerAgent(game)
Ejemplo n.º 6
0
class SmartGoatAgent(Agent):
    #Constructors
    def __init__(self, game: Game):
        super(SmartGoatAgent, self).__init__(game, Const.MARK_GOAT)
        self._hungryTigerAgent = HungryTigerAgent(game)

    #Check Corners
    def checkCorners(self, moves):
        for move in moves:
            if (str(move) == 'Ga1' or str(move) == 'Ge1' or str(move) == 'Ga5'
                    or str(move) == 'Ge5'):
                return move
        return None

    def propose(self) -> Move:
        # Get Moves
        moves = self.game.goatMoves()

        # List of potential moves
        safe: List[Move] = []
        wins: List[Move] = []
        loses: List[Move] = []
        draws: List[Move] = []
        scared: List[Move] = []
        blocks: List[Move] = []
        cornerGrab: List[Move] = []

        # Look ahead
        for move in moves:
            self.game.play(move)
            tigerMove : Optional[Move] = self._hungryTigerAgent.propose() \
                if self.game.state == Const.STATE_TURN_TIGER else None
            playedState: int = self.game.state
            self.game.unplay(move)

            # See if we can block a tiger capture
            blockMove = None
            if tigerMove.capture:
                endPlacement = str(tigerMove)
                endPlacement = "".join([endPlacement[4], endPlacement[5]])
                blockMove = block(moves, endPlacement)

            # Choose a block or corner over a safe move
            if playedState == Const.STATE_WIN_GOAT:
                wins.append(move)
            elif playedState == Const.STATE_WIN_TIGER:
                loses.append(move)
            elif blockMove != None:
                blocks.append(blockMove)
            elif checkCorners(move) != None:
                cornerGrab.append(move)
            elif not tigerMove.capture:
                safe.append(move)
            elif playedState == Const.STATE_DRAW:
                draws.append(move)
            else:
                scared.append(move)

        # Return the Move
        if len(wins) != 0:
            return random.choice(wins)
        elif len(blocks) != 0:
            return random.choice(blocks)
        elif len(cornerGrab) != 0:
            return random.choice(cornerGrab)
        elif len(safe) != 0:
            return random.choice(safe)
        elif len(draws) != 0:
            return random.choice(draws)
        elif len(scared) != 0:
            print(scared)
            return random.choice(scared)
        else:
            return random.choice(moves)
Ejemplo n.º 7
0
from SmartGoatAgent import SmartGoatAgent
from randomagent import RandomAgent
from const import Const
from goatAgrosAgent import GoatAgrosAgent
from occamsgoatagent import OccamsGoatAgent
from minmaxagent import MinMaxAgent

game = Game()
playoff = Playoff(trials=1)

# playoff.addGoatAgent("elusive goat",elusiveGoatAgent(game))
# playoff.addGoatAgent("conservative goat",ConserveGoatAgent(game))
# playoff.addGoatAgent("aggressive goat", AggressiveGoatAgent(game))
# playoff.addGoatAgent("side hugging goat", SideHuggingGoat(game))
# playoff.addGoatAgent("smart goat", SmartGoatAgent(game))
# playoff.addGoatAgent("agros goat",GoatAgrosAgent(game))
# playoff.addGoatAgent("occams goat",OccamsGoatAgent(game))
# playoff.addGoatAgent("random goat",RandomAgent(game,Const.MARK_GOAT))
# playoff.addGoatAgent("minmax 1 goat",MinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=1))
playoff.addGoatAgent("minmax 2 goat",
                     MinMaxAgent(game=game, side=Const.MARK_GOAT, maxDepth=2))
# playoff.addGoatAgent("minmax 3 goat",MinMaxAgent(game=game,side=Const.MARK_GOAT,maxDepth=3))

# playoff.addTigerAgent("random tiger",RandomAgent(game,Const.MARK_TIGER))
playoff.addTigerAgent("hungry tiger", HungryTigerAgent(game))
# playoff.addGoatAgent("minmax 1 tiger",MinMaxAgent(game=game,side=Const.MARK_TIGER,maxDepth=1))
# playoff.addGoatAgent("minmax 2 tiger",MinMaxAgent(game=game,side=Const.MARK_TIGER,maxDepth=2))
# playoff.addGoatAgent("minmax 3 tiger",MinMaxAgent(game=game,side=Const.MARK_TIGER,maxDepth=3))

playoff.play()
Ejemplo n.º 8
0
class SmartGoatAgent(Agent):
    #Constructors
    def __init__(self, game: Game):
        super(SmartGoatAgent, self).__init__(game, Const.MARK_GOAT)
        self._hungryTigerAgent = HungryTigerAgent(game)

    #Check Corners
    def checkCorners(self, moves):
        for move in moves:
            if (str(move) == 'Ga1' or str(move) == 'Ge1' or str(move) == 'Ga5'
                    or str(move) == 'Ge5'):
                return move
        return None

    def propose(self) -> Move:

        # Get Moves
        moves = self.game.goatMoves()

        safe: List[Move] = []
        wins: List[Move] = []
        loses: List[Move] = []
        draws: List[Move] = []
        scared: List[Move] = []
        smartSafe: List[Move] = []

        # Look ahead
        for move in moves:
            self.game.play(move)
            tigerMove : Optional[Move] = self._hungryTigerAgent.propose() \
                if self.game.state == Const.STATE_TURN_TIGER else None
            playedState: int = self.game.state
            self.game.unplay(move)

            # Switched favoring a safe move over a draw
            # Check if corners are avaliable, if so take it
            if playedState == Const.STATE_WIN_GOAT:
                wins.append(move)
            elif playedState == Const.STATE_WIN_TIGER:
                loses.append(move)
            elif checkCorners(move) != None:
                smartSafe.append(move)
            elif not tigerMove.capture:
                safe.append(move)
            elif playedState == Const.STATE_DRAW:
                draws.append(move)
            else:
                scared.append(move)

        # Return the Move
        if len(wins) != 0:
            return random.choice(wins)
        elif len(smartSafe) != 0:
            return random.choice(smartSafe)
        elif len(safe) != 0:
            return random.choice(safe)
        elif len(draws) != 0:
            return random.choice(draws)
        elif len(scared) != 0:
            return random.choice(scared)
        else:
            return random.choice(moves)
 def __init__(self, game: Game):
     super(DontYouDareTiger, self).__init__(game, Const.MARK_GOAT)
     self._hungryTigerAgent = HungryTigerAgent(game)