Skip to content

Instantly share code, notes, and snippets.

@magks
Created November 2, 2018 04:46
Show Gist options
  • Save magks/7f2bd5aa96bdf04759b8a4c2b9092dd1 to your computer and use it in GitHub Desktop.
Save magks/7f2bd5aa96bdf04759b8a4c2b9092dd1 to your computer and use it in GitHub Desktop.
minimal ai scores -10 on average
from Agent import Agent
from collections import deque
from enum import Enum
class MyAI ( Agent ):
class Action (Enum):
CHECK_FOR_GOLD = 1
def __init__ ( self ):
self.actionList = deque( [] )
self.perceptArray = []
def continueActionSequence( self, glitter ):
action = self.actionList.popleft()
if action == self.Action.CHECK_FOR_GOLD:
self.check_gold(glitter)
action = self.actionList.popleft()
return action
def check_gold(self,glitter):
if glitter:
self.actionList.appendleft(Agent.Action.GRAB)
def minimalAction( self ):
self.actionList.append( Agent.Action.FORWARD )
self.actionList.append( self.Action.CHECK_FOR_GOLD )
self.turn_around()
self.actionList.append( Agent.Action.FORWARD )
# back in start tile
self.actionList.append( Agent.Action.TURN_RIGHT )
self.actionList.append( Agent.Action.FORWARD )
self.actionList.append( self.Action.CHECK_FOR_GOLD )
self.turn_around()
self.actionList.append( Agent.Action.FORWARD )
# back in start tile
self.exit_world()
return self.actionList.popleft()
def turn_around(self):
self.actionList.append( Agent.Action.TURN_LEFT )
self.actionList.append( Agent.Action.TURN_LEFT )
def kill_wumpus(self):
self.actionList.append(Agent.Action.SHOOT)
self.exit_world()
def exit_world(self):
self.actionList.append(Agent.Action.CLIMB)
def getAction( self, stench, breeze, glitter, bump, scream ):
if len( self.actionList ) > 0 :
return self.continueActionSequence(glitter)
else :
if stench:
self.kill_wumpus()
return self.actionList.popleft()
elif breeze:
self.exit_world()
return self.actionList.popleft()
else:
# explore two adjacent squares
return self.minimalAction()
'''
if actionSequence
return actionSequence.pop()
else:
Generate Action Sequence based on current knowledge/belief
Strategy:
Agent builds
Agent "explores" unvisited rooms (tile X,Y that agent is currently in but has not visited before).
Exploring a room changes current knowledge/belief state.
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment