import ccm import re from ccm.lib.actr import * from expressionTree import EquationTreeNode class StepGenerator: def __init__(self,equation): self.equation = equation class UserState(ccm.Model): #ccm.ProductionSystem #moveConstants = "0" # move constants is 0 when need to move them, 1 when move variables, 2 when neither ready = False def __init__(self, equation): ccm.Model.__init__(self) self.equation = equation 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"] self.state = "none" self.end = False def get_input(self): 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 '''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): print("Constants moved to one side of equation") self.state = "move_constants" def moveVariables(self): print("Variables moved to one side of equation") self.state = "move_variables" # look at how to structure UserState () to not run every function class IntelligentTutor(ACTR): goal = Buffer() user = UserState("4x+7=5x+2") def init(): user.get_input() goal.set(user.state) def moved_constants(goal="move_constants"): #user="ready:True" #user.moveConstants() print("constants") goal.set("add_constants") def add_constants(goal= "add_constants"): print("add") user.get_input() goal.set(user.state) def moved_variables(goal="move_variables"): #user.moveVariables() print("variables") goal.set("add_variables") def add_variables(goal = "add_variables"): print("add") goal.set("end_process") 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()