public void LinkTile(GameTile nextTile) { PreviousTile = (_tileStack.Count > 0) ? _tileStack.Peek() : null; _tileStack.Push(nextTile); nextTile.FillTile(_goalTotal, PreviousTile); if (nextTile.GetType() == typeof(NumberTile)) { PathTotal = (int)_stf.Eval(_equationGenerator.GetEquationString(this, true)); _goalTotal.CheckComplete(); } pathUpdatedEvent.Invoke(); }
private long EvaluateExpressionAdvanced(string expression) { StringToFormula stf = new StringToFormula(); long result = stf.Eval(expression); return(result); }
private void TextBox_LostFocus(object sender, RoutedEventArgs e) { TextBox t = (TextBox)sender; t.Text = StringToFormula.Eval(t.Text).ToString("0.00"); UpdateVariable(); }
/// <summary> /// Mohamad Fahrizal /// 2018 01 31 /// Untuk merubah semua rumus, menjadi nilai /// Contoh : Nilai PPN adalah : {{ @@NilaiKontrak - @@NilaiDPP }} /// Maka akan menghasilkan : 55.000.000 - 50.000.000 /// Hasil Akhir Nilai PPN adalah : 5.000.000 /// /// Note : Rumusan perhitungan hanya bisa di eksekusi apabila berada di dalam double kurung kurawal {{ a + b }} /// </summary> public static string HitungRumus(string SMS) { string output = SMS; //Cari teks yg di apit oleh {{ }} var formulas = Regex.Matches(SMS, @"\{{(.*?)\}}"); if (formulas.Count > 0) { foreach (Match m in formulas) { StringToFormula stf = new StringToFormula(); double hasilHitung = 0; try { hasilHitung = stf.Eval(m.Groups[1].Value); } catch { } output = output.Replace(m.Groups[1].Value, Cf.Num(hasilHitung)); } } return(output.Replace("{{", "").Replace("}}", "")); }
public static int GetDiceResult(string input) { var fixedInput = input.Replace('x', '*'); var stf = new StringToFormula(); var db = stf.Eval(fixedInput); var number = (int)Math.Round(db); return(_random.Next(1, number)); }
public void CalculateTotals() { Material.CalculateTotals(); //Clear Values MaterialName = Material.Name; //EEI = Material.EEI; ECI = Material.ECI + Additional; Density = Material.Density; if (AllElements != null) { if (AllElements.Count > 0) { Volume = 0; foreach (CarboElement ce in AllElements) { ce.Calculate(Material); Volume += ce.Volume; } } } double wasteFact = 1 + (Waste / 100); Volume = Math.Round(Volume, 3); //Calculate the real volume based on a correction if required. if (Utils.isValidExpression(Correction) == true) { string volumeStr = Volume.ToString(); StringToFormula stf = new StringToFormula(); double result = stf.Eval(volumeStr + Correction); TotalVolume = Math.Round((B4Factor * (result * wasteFact)), 3); } else { TotalVolume = Math.Round(B4Factor * (Volume * wasteFact), 3); } //Calculate corrected mass Mass = TotalVolume * Density; //EC = Total corrected Mass * EE;I EC = (Mass * ECI) / 1000; }
public static decimal HitungRumus2(string SMS) { StringToFormula stf = new StringToFormula(); double hasilHitung = 0; try { hasilHitung = stf.Eval(SMS); } catch { } if (Double.IsInfinity(hasilHitung)) { hasilHitung = 0; } return(Convert.ToDecimal(hasilHitung)); }
private static void FindEquationAnswers(double startInterval, double endInterval, string equation) { Console.WriteLine("{0} {1} {2}", "x", "F(x)", "F'(x)"); double steps = 0.01; double i = startInterval; while (i <= endInterval) { string newEquation1 = equation.Replace("x", Convert.ToString(i)); StringToFormula stf1 = new StringToFormula(); double Fx = stf1.Eval(newEquation1); string newEquation2 = equation.Replace("x", Convert.ToString(i)); StringToFormula stf2 = new StringToFormula(); double Fx1 = stf2.Eval(newEquation2); Console.WriteLine("{0} {1} {2}", i, Fx, Fx1); i += steps; } }
public void CalculateTotals() { Material.CalculateTotals(); //Clear Values MaterialName = Material.Name; //EEI = Material.EEI; ECI = Material.ECI; Density = Material.Density; if (AllElements != null) { if (AllElements.Count > 0) { Volume = 0; foreach (CarboElement ce in AllElements) { Volume += ce.Volume; } } } //Calculate the real volume based on a correction if required. if (Utils.isValidExpression(Correction) == true) { string volumeStr = Volume.ToString(); StringToFormula stf = new StringToFormula(); double result = stf.Eval(volumeStr + Correction); TotalVolume = result; } else { TotalVolume = Volume; } //Calculate Valuesl Mass = TotalVolume * Density; //EE = Mass * EEI; EC = (Mass * ECI) / 1000; }
private void SliderText_LostFocus(object sender, RoutedEventArgs e) { SliderValue.Value = (float)StringToFormula.Eval(SliderText.Text); SliderText.Text = SliderValue.Value.ToString("0.00"); UpdateVariable(); }
public async Task <bool> process(Result result) { return(await Task.Run(() => { MainListener.Instance.StopListening(); for (int i = 0; i < result.SubQueries.Count; i++) { SubQuery query = result.SubQueries[i]; Intent intent = query.IdentId; if (intent.StartPrgramsFromList) { bool found = false; foreach (string star in query.InputStar) { string keyName = star.ToLower().Trim(); if (database.ContainsKey(keyName)) { lastProgramFound = database[keyName]; if (intent.hasConfirmDialog) { MainListener.Instance.StartConfirm(new string[] { intent.ConfirmWord, intent.ConfirmWord }); if (!intent.hasAnswer) { MouthManager.Instance.Speak("Are you sure you want to open " + keyName + " ?"); } lastActivatedTime = Time.time + listenTime; isConfirmActivated = true; } else { processConfirmOpenProgram(intent.ConfirmWord); } found = true; break; } else { if (keyName.Equals("settings") || keyName.Equals("setting")) { TaskPanel.Instance.openSettings(); return false; } if (keyName.Equals("config") || keyName.Equals("configs")) { TaskPanel.Instance.openConfigs(); return false; } if (keyName.Equals("test processor")) { TaskPanel.Instance.openTests(); return false; } } } if (!found && intent.LearnDialog) { openLearningSystem(LearnType.program); } } if (intent.hasSearchInWeb) { bool found = false; if (query.InputStar.Count == 2) { string keyName = query.InputStar[1].ToLower().Trim(); string value = query.InputStar[0].ToLower().Trim(); if (sites.ContainsKey(keyName)) { IProgram dummy = new IProgram(); dummy.Name = sites[keyName].Name; dummy.Path = sites[keyName].Url; dummy.Path += sites[keyName].Parameters + value; lastProgramFound = dummy; if (intent.hasConfirmDialog) { MainListener.Instance.StartConfirm(new string[] { intent.ConfirmWord, intent.ConfirmWord }); if (!intent.hasAnswer) { MouthManager.Instance.Speak("Are you sure you want to open " + keyName + " ?"); } lastActivatedTime = Time.time + listenTime; isConfirmActivated = true; } else { processConfirmOpenProgram(intent.ConfirmWord); } } } if (!found && intent.LearnDialog) { openLearningSystem(LearnType.search); } } if (intent.isMathQuestion) { string formula = FixResult(query.FullPath.ToUpper()); //or get it from DB int index = formula.IndexOf("<THAT>"); if (index > 0) { formula = formula.Substring(0, index); } formula = RemoveUnwantedCharacters(formula, "0123456789+-*/.".ToCharArray()); StringToFormula stf = new StringToFormula(); double resultx = stf.Eval(formula); TaskPanel.Instance.setClipBoardText(resultx.ToString()); MouthManager.Instance.Speak(resultx.ToString() + "! For your convenience result was copy to clipboard."); } if (intent.hasAnswer) { MouthManager.Instance.Speak(result.Output); } } return true; })); }