本文整理汇总了Python中statemachine.StateMachine类的典型用法代码示例。如果您正苦于以下问题:Python StateMachine类的具体用法?Python StateMachine怎么用?Python StateMachine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StateMachine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: main
def main():
#This makes it so if you hit CTRL+C curses doesn't eat the terminal alive!
signal.signal(signal.SIGINT, signal_handler)
#Setup curses
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
curses.curs_set(0)
#Create the State Machine instance
s = StateMachine()
win = curses.newwin(20, 40, 2, 2)
win.addstr(1, 7, "CODE:\n")
win.addstr(18, 7, "Press q or CTRL-c to quit.")
win.border()
win.refresh()
#This while loop keeps checking the input you type on the keyboard
while True:
#Get a single keypress and turn it into a string
win.border()
c = chr(win.getch())
win.addstr(13, 7, "Correct PIN: "+" ".join(s.correct_code))
#if you press q, terminate the program
if c == 'q':
break
if c.isalnum():
win.addstr(10, 7, "Prev PIN: "+" ".join(s.cur_code))
old_state = s.state
s.do_event(StateMachine.E_KEYPRESS, c)
new_state = s.state
#Write out some debug data
win.addstr(15, 7, "OLD STATE: %s "%s.STATE_NAMES[old_state])
win.addstr(16, 7, "NEW STATE: %s "%s.STATE_NAMES[new_state])
win.addstr(18, 7, "Press q or CTRL-c to quit.")
if s.state == StateMachine.IDLE:
win.erase()
win.addstr(1, 7, "CODE: ")
win.addstr(2, 7, '* '*len(s.cur_code))
if s.state == StateMachine.CODEOK:
win.addstr(1, 7, "SUCCESS")
elif s.state == StateMachine.CODEBAD:
win.addstr(1, 7, "NO! ")
win.addstr(11, 7, "Curr PIN: "+" ".join(s.cur_code))
#Curses only draws changes to the screen when you ask nicely.
win.refresh()
cleanup_curses()
开发者ID:diamondman,项目名称:StatemachineExample,代码行数:60,代码来源:combolock.py
示例2: test_stateMachine_initialState
def test_stateMachine_initialState(self):
"""Test State Machine Initial set up."""
machine = StateMachine(State1)
self.assertTrue(machine.inState(State1))
self.assertFalse(State1 in machine.state.movesTo)
self.assertTrue(State2 in machine.state.movesTo)
开发者ID:caryt,项目名称:utensils,代码行数:7,代码来源:tests.py
示例3: Miner
class Miner(BaseGameEntity):
def __init__(self, name):
self.name = name
self.location = None
self.gold = 0
self.fatigue = 0
self.thirsty = 0
self.fsm = StateMachine(self)
self.fsm.set_current_state(states.GoHomeAndSleepTilRested())
self.pocket_limit = 10
self.thirsty_limit = 10
self.fatigue_limit = 10
def __repr__(self):
return '<Miner {0}>'.format(self.name)
def change_location(self, location):
self.location = location
def is_pocket_full(self):
return self.gold >= self.pocket_limit
def add_gold_carried(self, n):
self.gold += n
def increase_fatigue(self):
self.fatigue += 1
self.thirsty += 1
def is_thirsty(self):
return self.thirsty >= self.thirsty_limit
开发者ID:xiangxiaobaog3,项目名称:codelab,代码行数:33,代码来源:miner.py
示例4: __init__
def __init__(self, _id=None, level=None, room=None,
speed=50, chance_to_hit=0.5, weapon_damage=5, healing=0, max_health=100,
health=100, ammo=0, morale=100):
self._id = _id if _id else str(uuid.uuid4())
self.level = level
self.room = room
self.speed = speed
self.chance_to_hit = chance_to_hit
self.weapon_damage = weapon_damage # Note: should depend on equipment
self.fight_cooldown = 1.0
self.healing = healing
self.health = health
self.ammo = ammo
self.morale = morale
self._path = deque() # the current path the entity is on
self._vision = set() # the rooms currently visible to the entity
self._timeout = 0
self._fight_timeout = 0
def log_state_change(a, b):
self.log("%s -> %s" % (a, b))
StateMachine.__init__(self, ["IDLE", "MOVING", "FIGHTING", "DEAD"],
on_state_change=log_state_change)
开发者ID:DiscoMountain,项目名称:Controlroom-Blues,代码行数:28,代码来源:entity.py
示例5: test_stateMachine_transitions_byAssignment
def test_stateMachine_transitions_byAssignment(self):
"""Test State Transations from State 1 to State2."""
machine = StateMachine(State1)
self.assertRaises(StateError, machine.goto, State1)
self.assertTrue(machine.inState(State1))
machine.state = State2
self.assertEqual(machine.message, 'Entered State 2')
self.assertTrue(machine.inState(State2))
开发者ID:caryt,项目名称:utensils,代码行数:8,代码来源:tests.py
示例6: reset
def reset(self):
""" UpdateStateMachin override.
"""
StateMachine.reset(self)
if len(self.ctx.orphaned) > 0:
print "BUG?: Abandoning orphaned requests."
self.ctx.orphaned.clear()
self.ctx = ArchiveUpdateContext(self, self.ctx.ui_)
开发者ID:ArneBab,项目名称:infocalypse,代码行数:9,代码来源:archivesm.py
示例7: test_weak_wildcard
def test_weak_wildcard():
machine = StateMachine({
'initial' : 'a',
'transitions': [
# A can only go to b on a 1
{ 'from': 'a', 'on': [1], 'to': 'b'},
# Always stay on b without erroring
{ 'from': 'a', 'on': [ ] }
]
})
machine.step(1)
assert(machine._current == 'b')
开发者ID:Tsukumokun,项目名称:bits-py,代码行数:12,代码来源:test_statemachine.py
示例8: reset
def reset(self):
""" StateMachine override. """
StateMachine.reset(self)
ctx = UpdateContext(self)
ctx.repo = self.ctx.repo
ctx.ui_ = self.ctx.ui_
ctx.bundle_cache = self.ctx.bundle_cache
if len(self.ctx.orphaned) > 0:
print "BUG?: Abandoning orphaned requests."
self.ctx.orphaned.clear()
self.ctx = ctx
开发者ID:ArneBab,项目名称:infocalypse,代码行数:13,代码来源:updatesm.py
示例9: AnimatedGameEntity
class AnimatedGameEntity(GameEntity):
def __init__(self, startCoordinates, name=''):
GameEntity.__init__(self, startCoordinates, name)
self.frameNumber = 1
self.imageFrame = 0
self.frameTime = 0.
self.animationSpeed = 0.5 + randint(-3, 3) / 10.0
self.frameWidth = 0
self.speed = 0
self.width = self.height = 0
self.brain = StateMachine()
self.actionQueue = []
def set_image(self, image, frameNumber=1):
self.image = image
self.frameNumber = frameNumber
self.frameWidth = self.image.get_width() / self.frameNumber
self.width, self.height = self.image.get_size()
def render(self, surface, offset):
surface.blit(self.image,
(self.location.x - offset[0], self.location.y - offset[1]),
(self.frameWidth * self.imageFrame, 0, self.frameWidth, self.height))
def adjustPosition(self, dimension):
self.location.x = min(self.location.x, dimension[0] - 20)
self.location.x = max(self.location.x, 10)
self.location.y = min(self.location.y, dimension[1] - 20)
self.location.y = max(self.location.y, 10)
def handleAction(self, action):
raise NotImplementedError, 'Entity %s cannot handle Action %s' % (self.name, action)
def process(self, time_passed):
self.frameTime += time_passed
if self.frameTime > self.animationSpeed:
self.frameTime = 0.
self.imageFrame = (self.imageFrame + 1) % self.frameNumber
if self.speed > 0. and self.location != self.destination:
vec_to_destination = self.destination - self.location
distance_to_destination = vec_to_destination.get_magnitude()
heading = vec_to_destination.get_normalized()
travel_distance = min(distance_to_destination, time_passed * self.speed)
self.location += heading * travel_distance
if self.actionQueue:
action = self.actionQueue.pop()
self.handleAction(action)
else:
self.brain.think()
开发者ID:jcharra,项目名称:StreetCatz,代码行数:51,代码来源:gameobjects.py
示例10: __init__
def __init__(self):
# These attributes are set by the parse method
self.doc = None
self.para = None
self.current_string = None
self.flow = None
self.stateMachine = StateMachine()
self.stateMachine.add_state("PARA", self._para)
self.stateMachine.add_state("ESCAPE", self._escape)
self.stateMachine.add_state("END", None, end_state=1)
self.stateMachine.add_state("ANNOTATION-START", self._annotation_start)
self.stateMachine.add_state("CITATION-START", self._citation_start)
self.stateMachine.add_state("BOLD-START", self._bold_start)
self.stateMachine.add_state("ITALIC-START", self._italic_start)
self.stateMachine.add_state("CODE-START", self._code_start)
self.stateMachine.add_state("QUOTES-START", self._quotes_start)
self.stateMachine.add_state("INLINE-INSERT", self._inline_insert)
self.stateMachine.add_state("CHARACTER-ENTITY", self._character_entity)
self.stateMachine.set_start("PARA")
self.patterns = {
'escape': re.compile(r'\\', re.U),
'escaped-chars': re.compile(r'[\\\(\{\}\[\]_\*,\.\*`"&]', re.U),
'annotation': re.compile(
r'(?<!\\)\{(?P<text>.*?)(?<!\\)\}(\(\s*(?P<type>\S*?\s*[^\\"\']?)(["\'](?P<specifically>.*?)["\'])??\s*(\((?P<namespace>\w+)\))?\s*(~(?P<language>[\w-]+))?\))?', re.U),
'bold': re.compile(r'\*(?P<text>((?<=\\)\*|[^\*])*)(?<!\\)\*', re.U),
'italic': re.compile(r'_(?P<text>((?<=\\)_|[^_])*)(?<!\\)_', re.U),
'code': re.compile(r'`(?P<text>(``|[^`])*)`', re.U),
'quotes': re.compile(r'"(?P<text>((?<=\\)"|[^"])*)(?<!\\)"', re.U),
'inline-insert': re.compile(r'>\((?P<attributes>.*?)\)', re.U),
'character-entity': re.compile(r'&(\#[0-9]+|#[xX][0-9a-fA-F]+|[\w]+);'),
'citation': re.compile(r'(\[\s*\*(?P<id>\S+)(\s+(?P<id_extra>.+?))?\])|(\[\s*\#(?P<name_name>\S+)(\s+(?P<extra>.+?))?\])|(\[\s*(?P<citation>.*?)\])', re.U)
}
开发者ID:dustinrb,项目名称:sam,代码行数:33,代码来源:samparser.py
示例11: __init__
def __init__(self):
self.screen = pygame.display.get_surface()
self.gamestate = StateMachine()
self.data = None
self.video = Video()
self.audio = Audio(self)
self.running = False
self.all_maps_loaded = False
self.force_bg_music = False
self.clock = pygame.time.Clock()
self.playtime = 0.0
self.dt = 0.0
self.key_timer = 0.0
self.state_timer = 0.0
self.debugfont = pygame.font.SysFont(DEBUGFONT, DEBUGFONTSIZE)
self.key_input = None
self.mouse_input = None
self.show_debug = False
self.debug_mode = True
self.fps = FPS
threading.Thread(target=self.load_all_maps).start()
开发者ID:thomas64,项目名称:pyRPG2,代码行数:26,代码来源:engine.py
示例12: __init__
def __init__(self):
# These attributes are set by the parse method
self.doc = None
self.para = None
self.current_string = None
self.flow = None
self.stateMachine = StateMachine()
self.stateMachine.add_state("PARA", self._para)
self.stateMachine.add_state("ESCAPE", self._escape)
self.stateMachine.add_state("END", None, end_state=1)
self.stateMachine.add_state("ANNOTATION-START", self._annotation_start)
self.stateMachine.add_state("CITATION-START", self._citation_start)
self.stateMachine.add_state("BOLD-START", self._bold_start)
self.stateMachine.add_state("ITALIC-START", self._italic_start)
self.stateMachine.add_state("MONO-START", self._mono_start)
self.stateMachine.add_state("QUOTES-START", self._quotes_start)
self.stateMachine.add_state("INLINE-INSERT", self._inline_insert)
self.stateMachine.set_start("PARA")
self.patterns = {
"escape": re.compile(r"\\"),
"escaped-chars": re.compile(r"[\\\(\{\}\[\]_\*,`]"),
"annotation": re.compile(
r'(?<!\\)\{(?P<text>.*?)(?<!\\)\}(\(\s*(?P<type>\S*?\s*[^\\"\']?)(["\'](?P<specifically>.*?)["\'])??\s*(\((?P<namespace>\w+)\))?\))?'
),
"bold": re.compile(r"\*(?P<text>\S.+?\S)\*"),
"italic": re.compile(r"_(?P<text>\S.*?\S)_"),
"mono": re.compile(r"`(?P<text>\S.*?\S)`"),
"quotes": re.compile(r'"(?P<text>\S.*?\S)"'),
"inline-insert": re.compile(r">>\((?P<attributes>.*?)\)"),
"citation": re.compile(
r"(\[\s*\*(?P<id>\S+)(\s+(?P<id_extra>.+?))?\])|(\[\s*\#(?P<name_name>\S+)(\s+(?P<extra>.+?))?\])|(\[\s*(?P<citation>.*?)\])"
),
}
开发者ID:nakohdo,项目名称:sam,代码行数:34,代码来源:samparser.py
示例13: __init__
def __init__(self):
self.stateMachine = StateMachine()
self.stateMachine.add_state("NEW", self._new_file)
self.stateMachine.add_state("SAM", self._sam)
self.stateMachine.add_state("BLOCK", self._block)
self.stateMachine.add_state("CODEBLOCK-START", self._codeblock_start)
self.stateMachine.add_state("CODEBLOCK", self._codeblock)
self.stateMachine.add_state("PARAGRAPH-START", self._paragraph_start)
self.stateMachine.add_state("PARAGRAPH", self._paragraph)
self.stateMachine.add_state("RECORD-START", self._record_start)
self.stateMachine.add_state("RECORD", self._record)
self.stateMachine.add_state("LIST-ITEM", self._list_item)
self.stateMachine.add_state("NUM-LIST-ITEM", self._num_list_item)
self.stateMachine.add_state("BLOCK-INSERT", self._block_insert)
self.stateMachine.add_state("END", None, end_state=1)
self.stateMachine.set_start("NEW")
self.current_paragraph = None
self.doc = DocStructure()
self.source = None
self.patterns = {
'comment': re.compile(r'\s*#.*'),
'block-start': re.compile(r'(\s*)([a-zA-Z0-9-_]+):(?:\((.*?)\))?(.*)'),
'codeblock-start': re.compile(r'(\s*)```(.*)'),
'codeblock-end': re.compile(r'(\s*)```\s*$'),
'paragraph-start': re.compile(r'\w*'),
'blank-line': re.compile(r'^\s*$'),
'record-start': re.compile(r'\s*[a-zA-Z0-9-_]+::(.*)'),
'list-item': re.compile(r'(\s*)(\*\s+)(.*)'),
'num-list-item': re.compile(r'(\s*)([0-9]+\.\s+)(.*)'),
'block-insert': re.compile(r'(\s*)>>\(.*?\)\w*')
}
开发者ID:dustinrb,项目名称:sam,代码行数:32,代码来源:samsparser.py
示例14: __init__
def __init__(self,argv):
#self.argv=argv
self.params={'-h':'localhost','-d':'','-s':'','-u':'SYSDBA','-p':'masterkey'}
self.ch='UTF8'
self.ch=self.detect_codecs()
self.mydb=None
self.cmd=None
self.sm = StateMachine()
self.create_state(self.sm)
self.parse_cmd(argv)
开发者ID:VladisGol,项目名称:platon-accs,代码行数:10,代码来源:setup.py
示例15: __init__
def __init__(self, startCoordinates, name=''):
GameEntity.__init__(self, startCoordinates, name)
self.frameNumber = 1
self.imageFrame = 0
self.frameTime = 0.
self.animationSpeed = 0.5 + randint(-3, 3) / 10.0
self.frameWidth = 0
self.speed = 0
self.width = self.height = 0
self.brain = StateMachine()
self.actionQueue = []
开发者ID:jcharra,项目名称:StreetCatz,代码行数:11,代码来源:gameobjects.py
示例16: __init__
def __init__(self, name):
self.name = name
self.location = None
self.gold = 0
self.fatigue = 0
self.thirsty = 0
self.fsm = StateMachine(self)
self.fsm.set_current_state(states.GoHomeAndSleepTilRested())
self.pocket_limit = 10
self.thirsty_limit = 10
self.fatigue_limit = 10
开发者ID:xiangxiaobaog3,项目名称:codelab,代码行数:12,代码来源:miner.py
示例17: __init__
def __init__(self):
#Create the State Machine instance
self._sm = StateMachine()
#The following two lines simply create the attributes for the instance
#and assign them blank values so you can read them later and not get
#an error even if you havn't set a real value to them. This is good
#practice for understanding how your class is structured, and avoiding
#errors when returning None means more. None is a special value for
#variables that marks a variable as empty.
self.stdscr = None
self.win = None
开发者ID:diamondman,项目名称:StatemachineExample,代码行数:12,代码来源:combolock.py
示例18: Wife
class Wife(BaseGameEntity):
def __init__(self, name):
self.name = name
self.fsm = StateMachine(self)
self.fsm.set_current_state(states.DoHouseWork())
self.fsm.set_global_state(states.WifeGlobalState())
def update(self):
self.fsm.update()
def handle_msg(self, sender, msg):
return self.fsm.handle_message(sender, self, msg)
开发者ID:xiangxiaobaog3,项目名称:codelab,代码行数:12,代码来源:miner.py
示例19: __init__
def __init__(self,db,file_name,log_file_name=None):
self.sm = StateMachine()
self.db=db
self.cur = self.db.cursor()
file=codecs.open(file_name,'r','utf8')
if log_file_name: self.log=codecs.open(log_file_name,'w','utf8')
self.line=self.get_script_line(file)
self.SQL=u''
self.r=re.compile('SET[\\s]+TERM')
self.ex_term=';'
self.create_state(self.sm)
self.State=''
self.log=None
print "Parse script class"
开发者ID:VladisGol,项目名称:platon-accs,代码行数:14,代码来源:parse_script.py
示例20: test_stateMachine_finalState
def test_stateMachine_finalState(self):
"""Test Final State."""
machine = StateMachine(State1)
self.assertTrue(machine.inState(State1))
machine.goto(State2)
self.assertTrue(machine.inState(State2))
self.assertFalse(State1 in machine.state.movesTo)
self.assertFalse(State2 in machine.state.movesTo)
self.assertRaises(StateError, machine.goto, State1)
self.assertRaises(StateError, machine.goto, State2)
self.assertTrue(machine.inState(State2))
开发者ID:caryt,项目名称:utensils,代码行数:11,代码来源:tests.py
注:本文中的statemachine.StateMachine类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论