Skip to content

Instantly share code, notes, and snippets.

@ItsMeThom-zz
Created January 22, 2019 17:08
Show Gist options
  • Select an option

  • Save ItsMeThom-zz/f63f517d53e21b465a4686e103f8ab86 to your computer and use it in GitHub Desktop.

Select an option

Save ItsMeThom-zz/f63f517d53e21b465a4686e103f8ab86 to your computer and use it in GitHub Desktop.
rough state machine with actions and states
from abc import abstractmethod, ABC
class State(ABC):
actions = [] # action(s) to take in this state
next_states = [] # all states reachable from this state
def test(self, entity):
"""
Perform some test using the entity data
to see if this state is valid
"""
return True
def next(self, entity):
"""
Perform some test of entity data to determine which state to
return from the transitions. The returned state is the new state for
this entity.
"""
return self.next_states[0]
class Action(ABC):
@abstractmethod
def do(self, entity):
# perform some transformation on the
# entity or world
pass
class StateMachine:
current_state = None
def think(self, entity):
# test all states in current_state and select.
pass
class Entity:
x_pos = 1
y_pos = 1
hunger = 0.5
tiredness = 0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment