def wrapWindowUI(m, worldColors, legalInputs, windowName='Belief', initBelief=None): """ @param m: A machine created by applying C{se.makeStateEstimationSimulation} to a hallway world, which take movement commands as input and generates as output structures of the form C{(b, (o, a))}, where C{b} is a belief state, C{a} is the action command, and C{o} is the observable output generated by the world. @param worldColors: A list of the colors of the rooms in the hallway, from left to right. @returns: A composite machine that prompts the user for input to, and graphically displays the output of C{m} on each step. """ def drawWorld(size): y = 0 for x in range(size): window.drawRect((x, y), (x + 1, y + 1), color=worldColors[x]) def processOutput(stuff): (dist, (o, a)) = stuff drawWorld(dim) drawBelief(dist, window, dim) return (o, a) def processInput(stuff): if stuff == 'quit': print 'Taking action 0 before quitting' return 0 else: return int(stuff) dim = len(worldColors) if not initBelief: initBelief = dist.UniformDist(range(dim)) ydim = 1 window = DrawingWindow(dim * 50, ydim * 50 + 10, -0.2, dim + 0.2, -0.2, ydim + 0.2, windowName) drawWorld(dim) drawBelief(initBelief, window, dim) return sm.Cascade( sm.Cascade( sm.Cascade(TextInputSM(legalInputs), sm.PureFunction(processInput)), m), sm.PureFunction(processOutput))
def wrapTextUI(m): """ @param m: An instance of C{sm.SM} @returns: A composite machine that prompts the user for input to, and prints the output of C{m} on each step. """ return sm.Cascade(sm.Cascade(TextInputSM(), m), sm.PureFunction(textOutput))