Ejemplo n.º 1
0
class GoatAgrosAgent(Agent):
    def __init__(self, game : Game):
        super(GoatAgrosAgent, self).__init__(game,Const.MARK_GOAT)
        self._hungryTigerAgent = HungryTigerAgent(game)
    def propose(self) -> Move:
        moves = self.game.goatMoves()
        hoard : List[Move]=[]
        c = False
        for move in moves:
            self.game.play(move)
            tigerMove : Optional[Move] = self._hungryTigerAgent.propose() \
                if self.game.state == Const.STATE_TURN_TIGER else None #why would this return None??
            playedState : int = self.game.state #will use this to implement
            #get tiger coordinates              #scaredgoatagent if beneficial
            if playedState == Const.STATE_TURN_TIGER:
                tigerCol = tigerMove.fromCol
                tigerRow = tigerMove.fromRow
                tigerPick = (tigerRow, tigerCol)
                if tigerMove.capture != True:
                    c = True
            self.game.unplay(move)
            goatPick = (move.toRow, move.toCol)
            if isClose(goatPick, tigerPick):
                hoard.append(move)
       
        if len(hoard) != 0:
            return random.choice(hoard)
        else:
            return random.choice(moves)
Ejemplo n.º 2
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.º 3
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.º 4
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.º 5
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)