Thursday, December 15, 2011

Quick state machine in Python

SM = {
  'INTERTRIAL': {'TRIALSTART': 'TSTART0'},
  'TSTART0': {'TRIALSTART': 'TSTART1'},
  'TSTART1': {'TRIALSTART': 'INTRIAL'},
  'INTRIAL': {'TRIALEND': 'TEND0'},
  'TEND0': {'TRIALEND': 'TEND1'},
  'TEND1': {'TRIALEND': 'INTERTRIAL'}
}

nextstate = SM[currentstate].get(input,currentstate)

No comments:

Post a Comment