public override MMC.Numbers.CNumber Calc(CEnvironment Env) { Check(); MMC.Numbers.CNumber res = Env.NewNumber(0.0); res.Day(_Terms[0].Calc(Env), _Terms[1].Calc(Env), _Terms[2].Calc(Env)); return(res); }
public override MMC.Numbers.CNumber Calc(CEnvironment Env) { if (_Term == null) { throw new CTermException(_Name + " not initialized!"); } return(_Term.Calc(Env)); }
//------------------------------------------------------------ // try to replace by the 2 subterms public override CTerm_Base Replace(CEnvironment Env) { if (!IsConstant) { return(this); } return(new CTerm_Number(Calc(Env))); }
//------------------------------------------------------------ // replace this by the one and only subterm public override CTerm_Base Replace(CEnvironment Env) { if (_Stack.Count == 1) { return(_Stack.Pop()); } return(this); }
public void TestGet_TryGetValueOfUndeclaredVariable_ThrowsException() { IEnvironment env = new CEnvironment(); string id = "Test"; Assert.Throws <CRuntimeError>(() => { env.Get(id); }); }
public override MMC.Numbers.CNumber Calc(CEnvironment Env) { Check(); MMC.Numbers.CNumber A = _Terms[0].Calc(Env).sqr(); MMC.Numbers.CNumber B = _Terms[1].Calc(Env).sqr(); A.add(B); return(A.sqrt()); }
public void UnPack(BinaryReader reader) { CellId = reader.ReadUInt32(); Flags = reader.ReadUInt32(); reader.Skip(sizeof(uint)); Surfaces = new uint[reader.ReadByte()]; Portals = new CCellPortal[reader.ReadByte()]; VisibleBlocks = new ushort[reader.ReadUInt16()]; for (int i = 0; i < Surfaces.Length; i++) { Surfaces[i] = (uint)reader.ReadUInt16() | 0x08000000; } EnvironmentId = reader.ReadUInt16(); CellStructure = reader.ReadUInt16(); environment = DatastoreManager.PortalDataStore.GetEnvironment(EnvironmentId | 0x0D000000u); structure = environment.Cells[CellStructure]; Position.UnPack(reader); for (int i = 0; i < Portals.Length; i++) { Portals[i] = new CCellPortal(); Portals[i].UnPack(reader); } for (int i = 0; i < VisibleBlocks.Length; i++) { VisibleBlocks[i] = reader.ReadUInt16(); } if ((Flags & 0x02) != 0) { uint numStaticObjects = reader.ReadUInt32(); StaticObjectIds = new uint[numStaticObjects]; StaticObjectFrames = new Frame[numStaticObjects]; for (int i = 0; i < StaticObjectIds.Length; i++) { StaticObjectIds[i] = reader.ReadUInt32(); StaticObjectFrames[i] = new Frame(); StaticObjectFrames[i].UnPack(reader); } } if ((Flags & 0x08) != 0) { reader.ReadUInt32(); } }
//------------------------------------------------------------ public override MMC.Numbers.CNumber Calc(CEnvironment Env) { if (_Term == null || _Variable == null) { throw new CTermException(_Name + " not initialized!"); } _Variable.Set(_Term.Calc(Env)); // intialize the variable Env.SetVariable(_Variable); // define or update it in the environment return(_Variable.Calc(Env)); // return the value }
//------------------------------------------------------------ // simple add the both terms public override MMC.Numbers.CNumber Calc(CEnvironment Env) { if (!_bTermB) { throw new CTermException("Add not initialized!"); } if (!_bTermA) { return(_TermB.Calc(Env)); } return(_TermA.Calc(Env).add(_TermB.Calc(Env))); }
public void TestAssign_TryAssignUndeclaredVariable_NewVariableWillBeCreated() { IEnvironment env = new CEnvironment(); string id = "Test"; int[] value = new[] { 0, 1 }; Assert.DoesNotThrow(() => { env.Assign(id, value); }); Assert.IsTrue(env.Exists(id)); }
public void TestDefine_TryDefineAlreadyDefinedVariable_ThrowsException() { IEnvironment env = new CEnvironment(); string id = "Test"; int[] value = new[] { 0, 1 }; Assert.DoesNotThrow(() => { env.Define(id, value); }); Assert.Throws <CRuntimeError>(() => { env.Define(id, value); }); }
public void updatePrevision(CPopulation pop, CEnvironment env){ Vector2 foodProbs = env.calculateFoodProba (pop.TotalExplorationValue); Vector2 waterProbs = env.calculateWaterProba (pop.TotalExplorationValue); Vector2 materialProbs = env.calculateMaterialProba (pop.TotalExplorationValue); Vector2 electronicProbs = env.calculateElectronicProba (pop.TotalExplorationValue); Vector2 peopleFoundProbs = env.calculatePeopleFoundProba (pop.TotalExplorationValue); Vector2 peopleLostProbs = env.calculatePeopleLostProba (pop.TotalExplorationValue); foodPrevisionText.text = "+ " + foodProbs.x + "-" + foodProbs.y; waterPrevisionText.text = "+ " + waterProbs.x + "-" + waterProbs.y; materialPrevisionText.text = "+ " + materialProbs.x + "-" + materialProbs.y; electronicPrevisionText.text = "+ " + electronicProbs.x + "-" + electronicProbs.y; peopleFoundPrevisionText.text = "+ " + peopleFoundProbs.x + "-" + peopleFoundProbs.y; peopleLostPrevisionText.text = "+ " + peopleLostProbs.x + "-" + peopleLostProbs.y; }
//------------------------------------------------------------ protected override CTerm_Base Compile(ref string Term, Stack <CTerm_Base> Stack, CEnvironment Env) { _Term = null; if ((Stack.Count < 1) || (Stack.Peek().Type != TTermType.Variable)) { throw new CTermException(_Name + " needs a left-side operand!"); } _Variable = (CTerm_Variable)Stack.Pop(); int count = Stack.Count; CTerm_Base Pending = GetNextTerm(ref Term, Stack, Env, TPriority.end); if (Stack.Count <= count) { throw new CTermException(_Name + " needs a right-side operand!"); } _Term = Stack.Pop(); return(Pending); }
//------------------------------------------------------------ // translate the Input string into the Term tree protected override CTerm_Base Compile(ref string Term, Stack <CTerm_Base> Stack, CEnvironment Env) { _Stack.Clear(); CTerm_Base Pending = GetNextTerm(ref Term, _Stack, Env, TPriority.end); if (_Stack.Count < 1) { throw new CTermException("missing operand in brackets!"); } if (Pending == null || Pending.Priotity != TPriority.end) { throw new CTermException("missing closing bracket!"); } return(null); }
public override MMC.Numbers.CNumber Calc(CEnvironment Env) { Check(); return(_Terms[0].Calc(Env).cosh()); }
//------------------------------------------------------------ // translate the Input string into the Term tree protected override CTerm_Base Compile(ref string Term, Stack <CTerm_Base> Stack, CEnvironment Env) { return(null); }
//------------------------------------------------------------ // this is the end ... public override CTerm_Base Replace(CEnvironment Env) { return(this); }
//------------------------------------------------------------ // translate the Input string into the Term tree protected override CTerm_Base Compile(ref string Term, Stack <CTerm_Base> Stack, CEnvironment Env) { _TermA = null; _TermB = null; if (_bTermA || Stack.Count > 0) // take Term A, if it's needed or it's there anyway { if (Stack.Count < 1) { throw new CTermException(_Name + " missing 1st operand!"); } _TermA = Stack.Pop(); _bTermA = true; } ; CTerm_Base Result = GetNextTerm(ref Term, Stack, Env, Priotity); if (_bTermB) { if (Stack.Count < 1) { throw new CTermException(_Name + " missing 2nd operand!"); } _TermB = Stack.Pop(); } return(Result); }
public override CTerm_Base Replace(CEnvironment Env) { return((_Term == null) ? this : _Term.Replace(Env)); }
//------------------------------------------------------------ // extract the parameters protected override CTerm_Base Compile(ref string Term, Stack <CTerm_Base> Stack, CEnvironment Env) { _Terms = new List <CTerm_Base>(); int StackSize = Stack.Count; CTerm_Base Pending = GetNextTerm(ref Term, Stack, Env, Priotity); StackSize = Stack.Count - StackSize; if (StackSize == 1 && Stack.Peek().Type == TTermType.Bracket) { CTerm_Bracket Brackets = (CTerm_Bracket)Stack.Pop(); StackSize = Brackets.CopyTo(Stack); // Brackets = null; } if (StackSize != _TermCount) { string Msg = (StackSize < _TermCount) ? "missing operand(s)" : "too many operands"; Msg += " for " + _Name + "!"; throw new CTermException(Msg); } while (StackSize > 0) { _Terms.Add(Stack.Pop()); StackSize--; } return(Pending); }
protected override CTerm_Base Compile(ref string Term, System.Collections.Generic.Stack <CTerm_Base> Stack, CEnvironment Env) { _Term = null; int size = Stack.Count; CTerm_Base Pending = GetNextTerm(ref Term, Stack, Env, TPriority.separator); if (Stack.Count <= size) { throw new CTermException("a separator has to followed by an operand!"); } _Term = Stack.Pop(); return(Pending); }
public void TestGetLastAssignedVariableId_TryToCallMethodOnEmptyEnvironment_ReturnEmptyString() { IEnvironment env = new CEnvironment(); Assert.IsEmpty(env.GetLastAssignedVariableId()); }