public void RefreshVariable() { this.bVariableDelete.Enabled = (this.lbVariables.Items.Count > 0); MetaVariable metaVariable = (MetaVariable)this.lbVariables.SelectedItem; if (metaVariable != null) { this.pVariables.Enabled = true; this.cbxVariableNullable.Enabled = (metaVariable.Type.CategoryType == ECategoryType.Class); this.tbVariableName.Text = metaVariable.Name; this.cbVariableType.SelectedItem = metaVariable.Type; this.cbVariableAccessType.SelectedIndex = (int)metaVariable.AccessType; this.tbVariableDefault.Text = metaVariable.DefaultValue; this.cbxVariableGetter.Checked = metaVariable.Getter; this.cbxVariableSetter.Checked = metaVariable.Setter; this.cbxVariableNullable.Checked = metaVariable.Nullable; this.cbxVariableSerialize.Checked = metaVariable.CanSerialize; this.tbVariablePrefix.Text = metaVariable.Prefix; } else { this.pVariables.Enabled = false; this.tbVariableName.Text = string.Empty; this.cbVariableType.SelectedIndex = -1; this.cbVariableAccessType.SelectedIndex = -1; this.tbVariableDefault.Text = string.Empty; this.cbxVariableGetter.Checked = false; this.cbxVariableSetter.Checked = false; this.cbxVariableNullable.Checked = false; this.cbxVariableSerialize.Checked = true; this.tbVariablePrefix.Text = string.Empty; } }
private string getCamelCaseVariable(MetaVariable metaVariable) { string name = string.Empty; switch (metaVariable.Type.CategoryType) { case ECategoryType.Integral: name = metaVariable.Type.Name; break; case ECategoryType.List: name = metaVariable.Type.SubType1.Name; break; case ECategoryType.Dictionary: name = metaVariable.Type.SubType2.Name; break; } name = name.ToUpper().Substring(0, 1) + name.Substring(1); if (name.Substring(name.Length - 1) == "y") { name = string.Format("{0}ie", name.Substring(0, name.Length - 1)); } else { name = string.Format("{0}", name); } return(name); }
public List <IPattern> Bind(List <Dictionary <MetaVariable, Expression> > bindings) { List <IPattern> output = new List <IPattern>(); foreach (Dictionary <MetaVariable, Expression> binding in bindings) { bool bound = false; foreach (KeyValuePair <MetaVariable, Expression> kv in binding) { MetaVariable x = kv.Key; Expression e = kv.Value; if (x.localID == this.localID && x.type == this.type) { output.Add(e); bound = true; } } if (!bound) { output.Add(this); } } return(output); }
public static void AddFPExperimentModel(Model m) { MetaVariable xi0 = new MetaVariable(SemanticType.INDIVIDUAL, 0); // // ACTION RULES // m.Add(new ActionRule( // new ExpressionPattern(Expression.EQUIVALENT, // new Phrase(Expression.IN_THE_ROOM, Expression.SELF), // new ExpressionPattern(Expression.IN_THE_ROOM, xi0)), // new ExpressionPattern(Expression.WOULD, // new ExpressionPattern(Expression.AT, Expression.SELF, xi0)), // new ExpressionPattern(Expression.AT, Expression.SELF, xi0))); // m.Add(new ActionRule( // new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR)), // new ExpressionPattern(Expression.WOULD, // new ExpressionPattern(Expression.AT, Expression.SELF, xi0)), // new ExpressionPattern(Expression.AT, Expression.SELF, xi0))); // COMMON KNOWLEDGE m.Add(new Phrase(Expression.PERCEIVE, Expression.SELF, new Phrase(Expression.IN_THE_ROOM, Expression.BOB))); m.Add(new Phrase(Expression.PERCEIVE, Expression.SELF, new Phrase(Expression.IN_THE_ROOM, Expression.EVAN))); m.Add(new Phrase(Expression.PERCEIVE, Expression.SELF, new Phrase(Expression.IN_THE_ROOM, new Phrase(Expression.THE, Expression.DOOR)))); m.Add(new Phrase(Expression.PERCEIVE, Expression.SELF, new Phrase(Expression.NOT, new Phrase(Expression.IN_THE_ROOM, Expression.GOAL)))); m.Add(new Phrase(Expression.CREDIBLE, Expression.PLAYER)); m.Add(new Phrase(Expression.POSSESS, Expression.BOB, Expression.RUBY)); m.Add(new Phrase(Expression.PERCEIVE, Expression.SELF, new Phrase(Expression.POSSESS, Expression.BOB, Expression.RUBY))); m.Add(new Phrase(Expression.PERCEIVE, Expression.SELF, new Phrase(Expression.POSSESS, Expression.EVAN, Expression.SAPPHIRE))); m.Add(new Phrase(Expression.PERCEIVE, Expression.SELF, new Phrase(Expression.POSSESS, Expression.PLAYER, Expression.EMERALD))); }
public static void Clear() { cachedType = null; cachedClass = null; cachedVariable = null; cachedMethod = null; }
public override void RemoveVariable(MetaType metaType, MetaVariable metaVariable) { base.RemoveVariable(type, metaVariable); switch (this.type.CategoryType) { case ECategoryType.Class: if (this.instance != null) { this.instance.RemoveVariable(type, metaVariable); } break; case ECategoryType.List: foreach (MetaValue metaValue in this.list) { metaValue.RemoveVariable(type, metaVariable); } break; case ECategoryType.Dictionary: foreach (KeyValuePair <MetaValue, MetaValue> pair in this.dictionary) { pair.Key.RemoveVariable(type, metaVariable); pair.Value.RemoveVariable(type, metaVariable); } break; } }
public override void UpdateVariable(MetaType metaType, MetaVariable oldVariable, MetaVariable newVariable) { base.UpdateVariable(type, oldVariable, newVariable); foreach (MetaInstanceVariable metaInstanceVariable in this.instanceVariables) { metaInstanceVariable.UpdateVariable(type, oldVariable, newVariable); } }
protected byte _getLS2Type(MetaVariable variable) { byte result = this._getLS2Type(variable.Type); if (result == OBJPTR && !variable.Nullable) { result = OBJECT; } return(result); }
private void tbVariableDefault_TextChanged(object sender, EventArgs e) { if (this.refreshing) { return; } MetaVariable variable = (MetaVariable)this.lbVariables.SelectedItem; variable.DefaultValue = this.tbVariableDefault.Text; }
private void cbxVariableSerialize_CheckedChanged(object sender, EventArgs e) { if (this.refreshing) { return; } MetaVariable variable = (MetaVariable)this.lbVariables.SelectedItem; variable.CanSerialize = this.cbxVariableSerialize.Checked; }
private void cbVariableAccessType_SelectedIndexChanged(object sender, EventArgs e) { if (this.refreshing) { return; } MetaVariable variable = (MetaVariable)this.lbVariables.SelectedItem; variable.AccessType = (EAccessType)this.cbVariableAccessType.SelectedIndex; }
private void tbVariablePrefix_TextChanged(object sender, EventArgs e) { if (this.refreshing) { return; } MetaVariable variable = (MetaVariable)this.lbVariables.SelectedItem; variable.Prefix = this.tbVariablePrefix.Text; this.RefreshData(); }
private void cbVariableType_SelectedIndexChanged(object sender, EventArgs e) { if (this.refreshing) { return; } MetaVariable variable = (MetaVariable)this.lbVariables.SelectedItem; variable.Type = (MetaType)this.cbVariableType.SelectedItem; this.RefreshData(); }
public override void RemoveVariable(MetaType metaType, MetaVariable metaVariable) { this.model.RemoveVariable(metaType, metaVariable); foreach (KeyValuePair <MetaClass, MetaList <MetaValue> > pair in this.values) { foreach (MetaValue value in pair.Value) { value.RemoveVariable(metaType, metaVariable); } } }
public override void UpdateVariable(MetaType metaType, MetaVariable oldVariable, MetaVariable newVariable) { this.model.UpdateVariable(metaType, oldVariable, newVariable); foreach (KeyValuePair <MetaClass, MetaList <MetaValue> > pair in this.values) { foreach (MetaValue value in pair.Value) { value.UpdateVariable(metaType, oldVariable, newVariable); } } }
public IPattern Bind(MetaVariable x, Expression expr) { if (this.Equals(x)) { return(expr); } else { return(this); } }
private void bRemove_Click(object sender, EventArgs e) { MetaVariable metaVariable = (MetaVariable)this.lbOldVariables.SelectedItem; if (metaVariable == null) { return; } this.repository.RemoveVariable(this.oldClass, metaVariable); this.RefreshData(); }
private void generateSerializeVariable(MetaVariable metaVariable) { switch (metaVariable.Type.CategoryType) { case ECategoryType.Integral: this.generateWrite("this->{0}", metaVariable.Name); break; case ECategoryType.Class: if (metaVariable.Type.CanSerialize && metaVariable.Prefix == string.Empty) { this.generateSerialize("this->{0}.", metaVariable.Name); } else { this.writeIf("this->{0} != NULL", metaVariable.Name); this.generateWrite("true"); this.generateWrite("this->{0}->Name", metaVariable.Name); this.writeElse(); this.generateWrite("false"); this.closeBrackets(); } break; case ECategoryType.List: this.generateWrite("this->{0}.size()", metaVariable.Name); this.writeLine("foreach ({0}{1}, it, this->{2})", metaVariable.Type.SubType1.GetNameWithModule(), metaVariable.Type.Prefix, metaVariable.Name); this.openBrackets(); if (metaVariable.Type.SubType1.CategoryType != ECategoryType.Class) { this.generateWrite("(*it)"); } else if (metaVariable.Type.SubType1.CanSerialize) { if (metaVariable.Prefix == string.Empty) { this.generateSerialize("it->"); } else { this.generateSerialize("(*it)->"); } } else { this.generateWrite("(*it)->Name"); } this.closeBrackets(); break; } }
public override void RemoveVariable(MetaType metaType, MetaVariable metaVariable) { base.RemoveVariable(type, metaVariable); for (int i = 0; i < this.instanceVariables.Count; i++) { if (this.instanceVariables[i].Variable.Equals(metaVariable)) { this.instanceVariables.RemoveAt(i); i--; } else { this.instanceVariables[i].RemoveVariable(type, metaVariable); } } }
private void bReplace_Click(object sender, EventArgs e) { MetaVariable oldVariable = (MetaVariable)this.lbOldVariables.SelectedItem; if (oldVariable == null) { return; } MetaVariable newVariable = (MetaVariable)this.lbNewVariables.SelectedItem; if (newVariable == null) { return; } this.repository.UpdateVariable(this.oldClass, oldVariable, newVariable); this.RefreshData(); }
public override void UpdateVariable(MetaType metaType, MetaVariable oldVariable, MetaVariable newVariable) { base.UpdateVariable(metaType, oldVariable, newVariable); if (this.variable.Equals(oldVariable)) { if (this.variable.Type.Equals(newVariable.Type)) { this.value.Reset(this.value); } else { this.value.Reset(this.variable); } this.variable = newVariable; } this.value.UpdateVariable(metaType, oldVariable, newVariable); }
private void validateVariable(MetaClass metaClass, MetaVariable metaVariable, int index) { if (metaVariable.Name.Contains(" ")) { this.validationLog += string.Format(ERROR_VARIABLE_NAME_SPACES, metaClass.Name, metaVariable.Name); } else { for (int i = index + 1; i < metaClass.Variables.Count; i++) { if (metaVariable.Name == metaClass.Variables[i].Name) { this.validationLog += string.Format(ERROR_VARIABLE_NAME_DUPLICATE, metaClass.Name, metaVariable.Name); } } } }
public IPattern Bind(MetaVariable x, Expression expr) { if (!freeMetaVariables.Contains(x)) { return(this); } IPattern[] newArgPatterns = new IPattern[argPatterns.Length]; for (int i = 0; i < argPatterns.Length; i++) { if (argPatterns[i] != null) { newArgPatterns[i] = argPatterns[i].Bind(x, expr); } } return(new ExpressionPattern(headPattern.Bind(x, expr), newArgPatterns)); }
public void Reset(MetaVariable metaVariable) { this.type = metaVariable.Type; switch (this.type.CategoryType) { case ECategoryType.Integral: this.String = metaVariable.DefaultValue; break; case ECategoryType.Class: this.Instance = (!metaVariable.Nullable ? new MetaInstance((MetaClass)this.type) : null); break; case ECategoryType.List: this.List = new MetaList <MetaValue>(); break; case ECategoryType.Dictionary: this.Dictionary = new MetaDictionary <MetaValue, MetaValue>(); break; } }
private void generateDeserializeVariable(MetaVariable metaVariable) { switch (metaVariable.Type.CategoryType) { case ECategoryType.Integral: this.generateRead(metaVariable.Type, "this->{0}", metaVariable.Name); break; case ECategoryType.Class: if (metaVariable.Type.CanSerialize && metaVariable.Prefix == string.Empty) { this.generateDeserialize("this->{0}.", metaVariable.Name); } else { this.generateReadBool("exists"); this.writeIf("exists"); this.generateReadString("name"); if (metaVariable.Type.CanSerialize) { this.writeLine("this->{0} = System::game->{1}ByName(name);", metaVariable.Name, this.getCamelCaseGetter(metaVariable)); } else { this.writeLine("this->{0} = System::dataManager->{1}s[name];", metaVariable.Name, this.getCamelCaseVariable(metaVariable)); } this.writeElse(); this.writeLine("this->{0} = NULL;", metaVariable.Name); this.closeBrackets(); } break; case ECategoryType.List: this.generateReadInt("number"); this.writeLine("{0}{1} _{2};", metaVariable.Type.SubType1.GetNameWithModule(), metaVariable.Type.Prefix, metaVariable.Name); this.writeLine("for (int i = 0; i < number; i++)"); this.openBrackets(); if (metaVariable.Type.SubType1.CategoryType != ECategoryType.Class) { this.generateRead(metaVariable.Type.SubType1, metaVariable.Name); this.writeLine("this->{0} += _{0};", metaVariable.Name); } else if (metaVariable.Type.SubType1.CanSerialize) { if (metaVariable.Prefix == string.Empty) { this.writeLine("_{0} = {1}();", metaVariable.Name, metaVariable.Type.SubType1.GetNameWithModule()); this.generateDeserialize("_{0}.", metaVariable.Name); } else { this.writeLine("_{0} = new {1}();", metaVariable.Name, metaVariable.Type.SubType1.GetNameWithModule()); this.generateDeserialize("_{0}->", metaVariable.Name); } this.writeLine("this->{0} += _{0};", metaVariable.Name); } else { this.generateReadString("name"); this.writeLine("this->{0} += System::dataManager->{1}s[name];", metaVariable.Name, this.getCamelCaseVariable(metaVariable)); } this.closeBrackets(); break; } }
private void generateHeaderVariable(MetaVariable metaVariable) { this.writeLine("{0}{1} {2};", metaVariable.Type.GetNameWithModule(), metaVariable.Prefix, metaVariable.Name); }
protected IEnumerator Do(List <Expression> actionSequence) { actionInProgress = true; if (actionSequence == null) { actionInProgress = false; yield break; } // // UNCOMMENT BELOW TO PRINT OUT THE ACTION SEUQNECE // StringBuilder s = new StringBuilder(); // foreach (Expression a in actionSequence) { // s.Append(a); // s.Append("; "); // } // Debug.Log(s.ToString()); // TODO: make the next action in the sequence wait until the previous // action has been completed. foreach (Expression action in actionSequence) { if (!controller.is2D) { if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, Expression.BOB)))) { GetComponent <NavMeshAgent>().destination = GameObject.Find("Bob").transform.position; yield return(null); while (GetComponent <NavMeshAgent>().remainingDistance > 1) { yield return(null); } this.model.UpdateBelief( new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.AT, Expression.SELF, Expression.BOB))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, Expression.EVAN)))) { GetComponent <NavMeshAgent>().destination = GameObject.Find("Evan").transform.position; yield return(null); while (GetComponent <NavMeshAgent>().remainingDistance > 1) { yield return(null); } this.model.UpdateBelief( new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.AT, Expression.SELF, Expression.EVAN))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, Expression.GOAL)))) { GetComponent <NavMeshAgent>().destination = GameObject.Find("Prize").transform.position; yield return(null); while (GetComponent <NavMeshAgent>().remainingDistance > 1) { yield return(null); } this.model.UpdateBelief( new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.AT, Expression.SELF, Expression.GOAL))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, Expression.DOOR))))) { GetComponent <NavMeshAgent>().destination = GameObject.Find("Door").transform.position; yield return(null); while (GetComponent <NavMeshAgent>().remainingDistance > 1) { yield return(null); } continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR))))) { controller.door.SetActive(false); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR))))) { controller.door.SetActive(true); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.NOT, new Phrase(Expression.POSSESS, Expression.SELF, Expression.RUBY))))) { // Debug.Log("GIVE UP RUBY!!!"); continue; } } // StopCoroutine(GoTo("Bob")); // StopCoroutine(GoTo("Evan")); // StopCoroutine(GoTo("DoorFront")); if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, Expression.BOB)))) { yield return(StartCoroutine(GoTo("Bob"))); // this.model.Add(new Phrase(Expression.AT, Expression.EVAN, Expression.BOB)); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, Expression.EVAN)))) { yield return(StartCoroutine(GoTo("Evan"))); // this.model.Add(new Phrase(Expression.AT, Expression.EVAN, Expression.BOB)); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, Expression.DOOR))))) { yield return(StartCoroutine(GoTo("DoorFront"))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, Expression.DOOR)))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, Expression.COW))))) { yield return(StartCoroutine(GoTo("Cow"))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, Expression.COW)))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, Expression.PLAYER)))) { yield return(StartCoroutine(GoTo("Player(Clone)"))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.PLAYER)))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, Expression.TREE))))) { yield return(StartCoroutine(GoTo("tree"))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, Expression.TREE)))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, Expression.LOG))))) { yield return(StartCoroutine(GoTo("log"))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, Expression.LOG)))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, new Phrase(Expression.POSSESS, new Phrase(Expression.THE, Expression.LOG), 1)))))) { yield return(StartCoroutine(GoTo("Woodcutter"))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.AT, Expression.SELF, new Phrase(Expression.THE, new Phrase(Expression.POSSESS, new Phrase(Expression.THE, Expression.LOG), 1))))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.EXISTS, new Phrase(Expression.THE, Expression.LOG))))) { GameObject.Find("tree").SetActive(false); controller.log.SetActive(true); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.WEAR, Expression.SELF, new Phrase(Expression.THE, new Phrase(Expression.FAKE, Expression.CROWN)))))) { this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.WEAR, Expression.SELF, new Phrase(Expression.THE, new Phrase(Expression.FAKE, Expression.CROWN))))); controller.fakeCrown.SetActive(true); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.NOT, new Phrase(Expression.WEAR, Expression.SELF, new Phrase(Expression.THE, new Phrase(Expression.FAKE, Expression.CROWN))))))) { this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.NOT, new Phrase(Expression.WEAR, Expression.SELF, new Phrase(Expression.THE, new Phrase(Expression.FAKE, Expression.CROWN)))))); controller.fakeCrown.SetActive(false); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.POSSESS, Expression.PLAYER, new Phrase(Expression.THE, new Phrase(Expression.FAKE, Expression.CROWN)))))) { this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.NOT, new Phrase(Expression.POSSESS, Expression.SELF, new Phrase(Expression.THE, new Phrase(Expression.FAKE, Expression.CROWN)))))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.POSSESS, Expression.PLAYER, new Phrase(Expression.THE, new Phrase(Expression.FAKE, Expression.CROWN))))); GameObject player = GameObject.Find("Player(Clone)"); controller.fakeCrown.transform.SetParent(player.transform); controller.fakeCrown.transform.position = new Vector3(player.transform.position.x, player.transform.position.y + 0.25f); Player playerScript = player.GetComponent <Player>(); playerScript.currentWearObject = controller.fakeCrown; if (controller.fakeCrown.activeSelf) { playerScript.isWearing = true; } continue; } // The second "if" clauses are commented out b/c without coroutines, they aren't activated in time. // TODO Uncomment when coroutine stuff is sorted out. if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR))))) { // if (currentInteractObject != null && currentInteractObject.name.Equals("DoorFront")) { this.controller.lowClick.Play(); GameObject.Find("Door").GetComponent <Door>().Open(); // this.model.Remove(new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR)))); // ShowSpeechBubble(new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR))); // } continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR))))) { // if (currentInteractObject != null && currentInteractObject.name.Equals("DoorFront")) { this.controller.lowClick.Play(); GameObject.Find("Door").GetComponent <Door>().Close(); // this.model.Remove(new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR)))); // ShowSpeechBubble(new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR))); // } continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.INTEND, Expression.EVAN, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR)))))) { this.controller.placeExpression.Play(); // the below code works with fromScratch, to a degree yield return(ShowSpeechBubble(new Phrase(Expression.WOULD, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR))))); // yield return ShowSpeechBubble("would"); // yield return new WaitForSeconds(2.0f); GameObject.Find("Evan").GetComponent <NPC>().ReceiveExpression(this.name, new Phrase(Expression.WOULD, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR)))); // this.model.Remove(new Phrase(Expression.INTEND, Expression.EVAN, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR)))); // this.model.Add(new Phrase(Expression.INTEND, Expression.EVAN, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR)))); // this.model.Remove(new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR)))); // ShowSpeechBubble(new Phrase(Expression.INTEND, Expression.EVAN, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR)))); continue; } if (action.Equals(new Phrase(Expression.WOULD, new Phrase(Expression.INTEND, Expression.EVAN, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR)))))) { this.controller.placeExpression.Play(); yield return(ShowSpeechBubble(new Phrase(Expression.WOULD, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR))))); // yield return ShowSpeechBubble("would"); // yield return new WaitForSeconds(2.0f); GameObject.Find("Evan").GetComponent <NPC>().ReceiveExpression(this.name, new Phrase(Expression.WOULD, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR)))); // this.model.Remove(new Phrase(Expression.INTEND, Expression.EVAN, new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR)))); // this.model.Add(new Phrase(Expression.INTEND, Expression.EVAN, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR)))); // this.model.Remove(new Phrase(Expression.OPEN, new Phrase(Expression.THE, Expression.DOOR))); this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR)))); // ShowSpeechBubble(new Phrase(Expression.INTEND, Expression.EVAN, new Phrase(Expression.CLOSED, new Phrase(Expression.THE, Expression.DOOR)))); continue; } MetaVariable xi0 = new MetaVariable(SemanticType.INDIVIDUAL, 0); MetaVariable xt0 = new MetaVariable(SemanticType.TRUTH_VALUE, 0); IPattern assertionSchema = new ExpressionPattern(Expression.WOULD, new ExpressionPattern(Expression.BELIEVE, xi0, xt0)); List <Dictionary <MetaVariable, Expression> > assertionBinding = assertionSchema.GetBindings(action); if (assertionBinding != null) { Expression assertion = new Phrase(Expression.ASSERT, assertionBinding[0][xt0]); yield return(ShowSpeechBubble(assertion)); Expression recipient = assertionBinding[0][xi0]; if (recipient.Equals(Expression.BOB)) { GameObject.Find("Bob").GetComponent <NPC>().ReceiveExpression(this.name, assertion); } if (recipient.Equals(Expression.EVAN)) { GameObject.Find("Evan").GetComponent <NPC>().ReceiveExpression(this.name, assertion); } } MetaVariable xc0 = new MetaVariable(SemanticType.CONFORMITY_VALUE, 0); IPattern conformitySchema = new ExpressionPattern(Expression.WOULD, new ExpressionPattern(Expression.EXPRESS_CONFORMITY, Expression.SELF, xi0, xc0)); List <Dictionary <MetaVariable, Expression> > conformityBinding = conformitySchema.GetBindings(action); if (conformityBinding != null) { Expression conformity = conformityBinding[0][xc0]; yield return(ShowSpeechBubble(conformity)); Expression recipient = conformityBinding[0][xi0]; if (recipient.Equals(Expression.BOB)) { GameObject.Find("Bob").GetComponent <NPC>().ReceiveExpression(this.name, conformity); } if (recipient.Equals(Expression.EVAN)) { GameObject.Find("Evan").GetComponent <NPC>().ReceiveExpression(this.name, conformity); } if (recipient.Equals(new Phrase(Expression.THE, new Phrase(Expression.POSSESS, new Phrase(Expression.THE, Expression.LOG), 1)))) { GameObject.Find("Woodcutter").GetComponent <NPC>().ReceiveExpression(this.name, conformity); } this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.EXPRESS_CONFORMITY, Expression.SELF, recipient, conformity))); } MetaVariable xi1 = new MetaVariable(SemanticType.INDIVIDUAL, 1); IPattern possessionSchema = new ExpressionPattern(Expression.WOULD, new ExpressionPattern(Expression.POSSESS, xi0, xi1)); List <Dictionary <MetaVariable, Expression> > possessionBinding = possessionSchema.GetBindings(action); if (possessionBinding != null) { Expression possessor = possessionBinding[0][xi0]; Expression item = possessionBinding[0][xi1]; GameObject inventory = GameObject.Find(this.gameObject.name + "/Inventory"); foreach (Transform t in inventory.GetComponentsInChildren <Transform>()) { if (t.gameObject.name.ToLower().Equals(item.ToString())) { t.gameObject.transform.SetParent(GameObject.Find(possessor.ToString() + "/Inventory").transform); t.gameObject.transform.position = GameObject.Find(possessor.ToString() + "/Inventory").transform.position; // t.position = new Vector3(5f, 1f, 0f); } } this.model.UpdateBelief(new Phrase(Expression.MAKE, Expression.SELF, new Phrase(Expression.POSSESS, possessor, item))); // if () { // } } } // this.controller.combineSuccess.Play(); // yield return ShowSpeechBubble("yes"); model.ClearGoal(); actionInProgress = false; yield return(true); }
public void ReceiveExpression(Expression utterer, Expression utterance) { // Debug.Log(this.name + " is seeing '" + utterance + "'"); if (this.model == null) { // Debug.Log("No associated model."); this.controller.placeExpression.Play(); StartCoroutine(ShowSpeechBubble("questionMark")); return; } if (utterance.type.Equals(SemanticType.CONFORMITY_VALUE)) { // if (name.Equals(new Phrase(Expression.THE, new Phrase(Expression.POSSESS, new Phrase(Expression.THE, Expression.LOG), 1)))) { // if (!model.Proves(new Phrase(Expression.KING, utterer))) { // StartCoroutine(ShowSpeechBubble(Expression.REFUSE)); // return; // } // } // TODO figure out conditions of refusal, etc. if (utterance.GetHead().Equals(Expression.CONTRACT)) { if (!this.model.Proves(new Phrase(Expression.NOT, new Phrase(Expression.TRUSTWORTHY, utterer)))) { // TODO: check if utilities work out, and if you can uphold your end of the deal. // For now, just accept by default // uphold your end of the bargain model.Add(new Phrase(Expression.BETTER, utterance.GetArg(1), Expression.NEUTRAL)); // model.AddUtility(utterance.GetArg(1), 10f); // hold the other person to account model.UpdateBelief(new Phrase(Expression.BOUND, utterer, utterance.GetArg(0))); // // hold yourself to account?? // model.UpdateBelief(new Phrase(Expression.BOUND, utterer, utterance.GetArg(1))); this.controller.combineSuccess.Play(); StartCoroutine(ShowSpeechBubble(new Phrase(Expression.ACCEPT))); return; } this.controller.lowClick.Play(); StartCoroutine(ShowSpeechBubble(Expression.REFUSE)); return; } if (utterance.GetHead().Equals(Expression.WOULD)) { if (this.model.Proves(new Phrase(Expression.NOT, new Phrase(Expression.TRUSTWORTHY, utterer)))) { this.controller.lowClick.Play(); StartCoroutine(ShowSpeechBubble(new Phrase(Expression.REFUSE))); return; } this.controller.combineSuccess.Play(); StartCoroutine(ShowSpeechBubble(Expression.ACCEPT)); model.Add(new Phrase(Expression.BETTER, utterance.GetArg(0), Expression.NEUTRAL)); model.decisionLock = false; // model.AddUtility(utterance.GetArg(0), 10f); return; } } if (utterance.type.Equals(SemanticType.ASSERTION)) { Expression content = utterance.GetArg(0); // if (this.model.UpdateBelief(new Phrase(Expression.BELIEVE, utterer, content))) { if (this.model.UpdateBelief(content)) { this.controller.combineSuccess.Play(); StartCoroutine(ShowSpeechBubble(new Phrase(Expression.ASSERT, Expression.AFFIRM))); } else { this.controller.failure.Play(); StartCoroutine(ShowSpeechBubble(new Phrase(Expression.ASSERT, Expression.DENY))); } return; } if (utterance.type.Equals(SemanticType.TRUTH_VALUE)) { if (this.model.Proves(utterance)) { this.controller.combineSuccess.Play(); StartCoroutine(ShowSpeechBubble(new Phrase(Expression.ASSERT, Expression.AFFIRM))); } else if (this.model.Proves(new Phrase(Expression.NOT, utterance))) { this.controller.failure.Play(); StartCoroutine(ShowSpeechBubble(new Phrase(Expression.ASSERT, Expression.DENY))); } else { this.controller.lowClick.Play(); StartCoroutine(ShowSpeechBubble(new Phrase(Expression.ASSERT, new Phrase(Expression.OR, Expression.AFFIRM, Expression.DENY)))); } return; } if (utterance.type.Equals(SemanticType.INDIVIDUAL)) { // I imagine this will be an invitation to attend to the individual named // but I'll leave this as a kind of puzzlement for now. this.controller.placeExpression.Play(); StartCoroutine(ShowSpeechBubble("query")); return; } SemanticType outputType = utterance.type.GetOutputType(); if (outputType != null && outputType.Equals(SemanticType.TRUTH_VALUE)) { IPattern[] args = new IPattern[utterance.GetNumArgs()]; Dictionary <SemanticType, int> places = new Dictionary <SemanticType, int>(); int counter = 0; for (int i = 0; i < utterance.GetNumArgs(); i++) { if (utterance.GetArg(i) == null) { SemanticType argType = utterance.type.GetInputType(counter); int place = 0; if (places.ContainsKey(argType)) { place = places[argType]; } places[argType] = place + 1; args[i] = new MetaVariable(argType, place); counter++; } else { args[i] = utterance.GetArg(i); } } // let's see if this doesn't break things. // might have to cycle through the utterance's open args. IPattern question = new ExpressionPattern(utterance.GetHead(), args); List <Dictionary <MetaVariable, Expression> > found = model.Find(false, new List <Expression>(), question); if (found != null) { List <IPattern> bound = question.Bind(found); Expression[] answers = new Expression[bound.Count]; counter = 0; foreach (IPattern p in bound) { Expression answer = new Phrase(Expression.ASSERT, p.ToExpression()); answers[counter] = answer; counter++; } StartCoroutine(ShowSpeechBubbles(answers)); return; } } // this leaves functions with e as output. Not sure what this would amount to. this.controller.placeExpression.Play(); StartCoroutine(ShowSpeechBubble("query")); }
public override bool Equals(Object o) { MetaVariable that = o as MetaVariable; return(this.type.Equals(that.type) && this.localID == that.localID); }
public static extern bool get_meta_variable(MetaVariable variableId, [MarshalAs(UnmanagedType.BStr), Out] out string result);
private string getCamelCaseGetter(MetaVariable metaVariable) { return ("get" + this.getCamelCaseVariable(metaVariable)); }
private string getCamelCaseVariable(MetaVariable metaVariable) { string name = string.Empty; switch (metaVariable.Type.CategoryType) { case ECategoryType.Integral: name = metaVariable.Type.Name; break; case ECategoryType.List: name = metaVariable.Type.SubType1.Name; break; case ECategoryType.Dictionary: name = metaVariable.Type.SubType2.Name; break; } name = name.ToUpper().Substring(0, 1) + name.Substring(1); if (name.Substring(name.Length - 1) == "y") { name = string.Format("{0}ie", name.Substring(0, name.Length - 1)); } else { name = string.Format("{0}", name); } return name; }
private void generateSerializeVariable(MetaVariable metaVariable) { if (!metaVariable.CanSerialize) { return; } MetaType type = metaVariable.Type; MetaType subType1 = metaVariable.Type.SubType1; MetaType subType2 = metaVariable.Type.SubType2; switch (type.CategoryType) { case ECategoryType.Integral: this.generateSer("", metaVariable.Name); break; case ECategoryType.Class: this.generateSer((!metaVariable.Nullable ? "_OBJ" : "_OBJ_PTR"), metaVariable.Name); break; case ECategoryType.List: if (subType1.CategoryType == ECategoryType.Integral) { this.generateSer("_HARRAY", metaVariable.Name); } else if (type.Suffix1 == string.Empty) { this.generateSer("_HARRAY_OBJ", metaVariable.Name); } else { this.generateSer("_HARRAY_OBJ_PTR", metaVariable.Name); } break; case ECategoryType.Dictionary: if (subType1.CategoryType == ECategoryType.Integral) { if (subType2.CategoryType == ECategoryType.Integral) { this.generateSer("_HMAP", metaVariable.Name, subType1.Name, subType2.Name); } else if (type.Suffix2 == string.Empty) { this.generateSer("_HMAP_V_OBJ", metaVariable.Name, subType1.Name, subType2.GetNameWithModule()); } else { this.generateSer("_HMAP_V_OBJ_PTR", metaVariable.Name, subType1.Name, subType2.GetNameWithModule()); } } else if (type.Suffix1 == string.Empty) { if (subType2.CategoryType == ECategoryType.Integral) { this.generateSer("_HMAP_K_OBJ", metaVariable.Name, subType1.GetNameWithModule(), subType2.Name); } else if (type.Suffix2 == string.Empty) { this.generateSer("_HMAP_K_OBJ_V_OBJ", metaVariable.Name, subType1.GetNameWithModule(), subType2.GetNameWithModule()); } else { this.generateSer("_HMAP_K_OBJ_V_OBJ_PTR", metaVariable.Name, subType1.GetNameWithModule(), subType2.GetNameWithModule()); } } else { if (subType2.CategoryType == ECategoryType.Integral) { this.generateSer("_HMAP_K_OBJ_PTR", metaVariable.Name, subType1.GetNameWithModule(), subType2.Name); } else if (type.Suffix2 == string.Empty) { this.generateSer("_HMAP_K_OBJ_PTR_V_OBJ", metaVariable.Name, subType1.GetNameWithModule(), subType2.GetNameWithModule()); } else { this.generateSer("_HMAP_K_OBJ_PTR_V_OBJ_PTR", metaVariable.Name, subType1.GetNameWithModule(), subType2.GetNameWithModule()); } } break; } }
private string getCamelCaseGetter(MetaVariable metaVariable) { return("get" + this.getCamelCaseVariable(metaVariable)); }