tutor.py 3.78 KB
 mrk022 committed Nov 26, 2019 1 ``````import ccm `````` mrk022 committed Nov 27, 2019 2 ``````import re `````` mrk022 committed Nov 26, 2019 3 ``````from ccm.lib.actr import * `````` mrk022 committed Nov 27, 2019 4 ``````from expressionTree import EquationTreeNode `````` mrk022 committed Nov 26, 2019 5 `````` `````` mrk022 committed Nov 27, 2019 6 7 8 9 10 ``````class StepGenerator: def __init__(self,equation): self.equation = equation class UserState(ccm.Model): #ccm.ProductionSystem `````` mrk022 committed Nov 26, 2019 11 12 13 `````` #moveConstants = "0" # move constants is 0 when need to move them, 1 when move variables, 2 when neither ready = False `````` mrk022 committed Nov 27, 2019 14 15 `````` def __init__(self, equation): ccm.Model.__init__(self) `````` mrk022 committed Nov 26, 2019 16 `````` self.equation = equation `````` mrk022 committed Nov 27, 2019 17 18 19 20 21 22 23 `````` self.sides = self.getLeftandRightVals() self.canMoveConstants() #self.generate_tree() #self.moveconstants = ["4x=5x+2-7","4x+7-2=5x", "7-2=1x", "-1x+7-2=0"] #self.movevariables = ["7=5x-4x+2", "4x-5x+7=2"] #self.addconstants = ["4x=5x-5","4x+5=5x"] #self.addvariables = ["7=1x+2", "-1x+7=2"] `````` mrk022 committed Nov 26, 2019 24 25 26 `````` self.state = "none" self.end = False `````` mrk022 committed Nov 27, 2019 27 `````` def get_input(self): `````` mrk022 committed Nov 26, 2019 28 29 30 31 32 `````` user_step = input("Please enter your next step: ") #figure out what user step means # call some get_state() function comparing user step to what state should be self.state = "move_constants" ready = True `````` mrk022 committed Nov 27, 2019 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 `````` '''def generate_tree(self): #equation = "3x+5=2+2x" expressions = self.equation.split("=") rootNode = EquationTreeNode("=", None) leftNode = EquationTreeNode("+") rootNode.addLeftNode(leftNode) leftNode.splitExpression(expressions[0]) rightNode = EquationTreeNode("+") rootNode.addRightNode(rightNode) rightNode.splitExpression(expressions[1]) print("\nEquation Tree is:") print(" ",rootNode.value) print(" ", rootNode.left.value, " ", rootNode.right.value) print(rootNode.left.left.value, rootNode.left.right.value, rootNode.right.left.value, rootNode.right.right.value, "\n")''' def getLeftandRightVals(self): expressions = self.equation.split("=") leftVars = re.split("[+-]", expressions[0]) rightVars = re.split("[+-]", expressions[1]) return [leftVars, rightVars] def canMoveConstants(self): constantsOnLeft = 0 variablesOnLeft = 0 constantsOnRight = 0 variablesOnRight = 0 for value in self.sides[0]: if self.isConstant(value): constantsOnLeft += 1 else: variablesOnLeft += 1 for value in self.sides[1]: if self.isConstant(value): constantsOnRight += 1 else: variablesOnRight += 1 print("There are ", variablesOnLeft, " variables on the left and ", constantsOnLeft, " constants on the left") print("There are ", variablesOnRight, " variables on the right and ", constantsOnRight, " constants on the right") def isConstant(self, value): if 'x' in value: print(value) return False return True def get_state(self, user_input): if user_input in self.moveconstants: return "move_constants" elif user_input in self.movevariables: return "move_variables" def moveConstants(self): `````` mrk022 committed Nov 26, 2019 90 `````` print("Constants moved to one side of equation") `````` mrk022 committed Nov 27, 2019 91 `````` self.state = "move_constants" `````` mrk022 committed Nov 26, 2019 92 `````` `````` mrk022 committed Nov 27, 2019 93 `````` def moveVariables(self): `````` mrk022 committed Nov 26, 2019 94 `````` print("Variables moved to one side of equation") `````` mrk022 committed Nov 27, 2019 95 `````` self.state = "move_variables" `````` mrk022 committed Nov 26, 2019 96 97 `````` `````` mrk022 committed Nov 27, 2019 98 ``````# look at how to structure UserState () to not run every function `````` mrk022 committed Nov 26, 2019 99 100 101 `````` class IntelligentTutor(ACTR): goal = Buffer() `````` mrk022 committed Nov 27, 2019 102 `````` user = UserState("4x+7=5x+2") `````` mrk022 committed Nov 26, 2019 103 `````` `````` mrk022 committed Nov 27, 2019 104 105 `````` def init(): `````` mrk022 committed Nov 26, 2019 106 107 108 `````` user.get_input() goal.set(user.state) `````` mrk022 committed Nov 27, 2019 109 110 111 `````` def moved_constants(goal="move_constants"): #user="ready:True" #user.moveConstants() print("constants") `````` mrk022 committed Nov 26, 2019 112 113 114 `````` goal.set("add_constants") def add_constants(goal= "add_constants"): `````` mrk022 committed Nov 27, 2019 115 116 117 `````` print("add") user.get_input() goal.set(user.state) `````` mrk022 committed Nov 26, 2019 118 `````` `````` mrk022 committed Nov 27, 2019 119 120 121 `````` def moved_variables(goal="move_variables"): #user.moveVariables() print("variables") `````` mrk022 committed Nov 26, 2019 122 123 124 `````` goal.set("add_variables") def add_variables(goal = "add_variables"): `````` mrk022 committed Nov 27, 2019 125 126 `````` print("add") goal.set("end_process") `````` mrk022 committed Nov 26, 2019 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 `````` def end_process(goal = "end_process"): goal.set("Simulation Complete!") self.stop() class EmptyEnvironment(ccm.Model): pass def main(): #eqn = "3x + 4 = 0" env_name = EmptyEnvironment() agent_name = IntelligentTutor() env_name.agent = agent_name ccm.log_everything(env_name) env_name.run() main()``````