public void Simplify() { var simp = new Simplify(new Pow(Variable.X, new Number(0))); var expected = new Number(1); SimpleTest(simp, expected); }
public override void SelectMenu(MouseState mouseState, MouseState oldState) { for (int i = 0; i < selected.Length; i++) { selected[i] = false; } if (isShowing) { if (Simplify.MouseSelect(font, mouseState, Simplify.GetCenterText(font, "Single Player"), Game.Height / 3, "Single Player")) { selected[0] = true; } else if (Simplify.MouseSelect(font, mouseState, Simplify.GetCenterText(font, "Multiplayer"), Game.Height / 3 + 35, "Multiplayer")) { selected[1] = true; } else if (Simplify.MouseSelect(font, mouseState, Simplify.GetCenterText(font, "Options"), Game.Height / 3 + 70, "Options")) { selected[2] = true; } else if (Simplify.MouseSelect(font, mouseState, Simplify.GetCenterText(font, "Credits"), Game.Height / 3 + 105, "Credits")) { selected[3] = true; } else if (Simplify.MouseSelect(font, mouseState, Simplify.GetCenterText(font, "Exit"), Game.Height / 3 + 140, "Exit")) { selected[4] = true; } } }
public void CloneTest() { var exp = new Simplify(null, new Sin(Variable.X)); var clone = exp.Clone(); Assert.Equal(exp, clone); }
public void CloneTest() { var exp = new Simplify(new Sin(new Variable("x"))); var clone = exp.Clone(); Assert.Equal(exp, clone); }
public void TestPowersOfOne() { var p = new Parser("x^1").Parse(); Simplify.PowersOfOne(p); if (p.ToString() != "x") { Assert.Fail(); } p = new Parser("37^1").Parse(); Simplify.PowersOfOne(p); if (p.ToString() != "37") { Assert.Fail(); } p = new Parser("1+2*x^1+1").Parse(); Simplify.PowersOfOne(p); if (p.ToString() != "1+2*x+1") { Assert.Fail(); } p = new Parser("1+x^2").Parse(); Simplify.PowersOfOne(p); if (p.ToString() != "1+x^2") { Assert.Fail(); } }
// List of Init when game start void InitList() { InitService(); InitGameInfo(); Simplify.InitLargeNumName(); InitGame(); }
public void SimplifyFloor() { var simple = new Simplify(); simple.vertices = FloorVerts.Select(x => new MSVertex() { p = x.Position, t = x.TextureCoordinate }).ToList(); for (int t = 0; t < FloorIndices.Length; t += 3) { simple.triangles.Add(new MSTriangle() { v = new int[] { FloorIndices[t], FloorIndices[t + 1], FloorIndices[t + 2] } }); } simple.simplify_mesh(2, agressiveness: 3, iterations: 300); FloorVerts = simple.vertices.Select(x => { //DGRP3DVert return(new VertexPositionTexture(x.p, x.t)); }).ToArray(); var indices = new List <int>(); foreach (var t in simple.triangles) { indices.Add(t.v[0]); indices.Add(t.v[1]); indices.Add(t.v[2]); } FloorIndices = indices.ToArray(); }
public override void Show(SpriteBatch sb, MouseState mouseState) { Simplify.DarkenCenterText(sb, font, selected[0], Game.Height / 3, "Single Player"); Simplify.DarkenCenterText(sb, font, selected[1], Game.Height / 3 + 35, "Multiplayer"); Simplify.DarkenCenterText(sb, font, selected[2], Game.Height / 3 + 70, "Options"); Simplify.DarkenCenterText(sb, font, selected[3], Game.Height / 3 + 105, "Credits"); Simplify.DarkenCenterText(sb, font, selected[4], Game.Height / 3 + 140, "Exit"); }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns> /// The result of analysis. /// </returns> public override IExpression Analyze(Simplify exp) { if (!Helpers.HasVariable(exp, Variable)) { return(new Number(0)); } return(exp.Argument.Analyze(this)); }
public void Show(SpriteBatch sb) { if (!isTrading) { Simplify.DarkenCenterText(sb, chatFont, selected[0], 20, "Talk"); Simplify.DarkenCenterText(sb, chatFont, selected[1], 40, "Buy/Sell"); Simplify.DarkenCenterText(sb, chatFont, selected[2], 60, "Close"); } }
public void SimplifyInjectTest() { var simp = new Simplify(new Number(2)); resolver.Resolve(simp); Assert.NotNull(simp.Simplifier); Assert.Equal(this.simplifier, simp.Simplifier); }
// Update game info panel // update time and total currency earn public void UpdateGameInfoUI() { timeCount += Time.deltaTime; TimeSpan timeSpan = TimeSpan.FromSeconds((int)timeCount); infoTxt.text = "Total Game Time: " + string.Format("{0:D2}:{1:D2}:{2:D2}:{3:D2}", timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds) + "\n" + "Total Currency Earn: " + Simplify.LargeNumConvert(totalCurrencyEarn); }
public void ExecuteTest() { var mock = new Mock <ISimplifier>(); mock.Setup(x => x.Analyze(It.IsAny <Simplify>())).Returns <IExpression>(x => x); var exp = new Simplify(mock.Object, new Sin(Variable.X)); Assert.Equal(exp, exp.Execute()); }
public void TestZeroAdditionSimplify() { var p = new Parser("0+1+3").Parse(); Simplify.ZeroAddition(p); if (p.ToString() != "1+3") { Assert.Fail(); } }
public static string[] ConvertToExtensionList(JsonConfig prefs) { string[] extensionList = prefs.Extensions.Split(','); for (int i = 0; i < extensionList.Length; i++) { Simplify.ReduceWhitespace(ref extensionList[i]); extensionList[i] = $"*.{extensionList[i]}"; } return(extensionList); }
public static void Draw(SpriteBatch sb, MouseState mouseState) { Simplify.CenterText(sb, ContentLoader.Font(0), Game.Height / 5, "ECalpha1.1 - C#"); foreach (Menu m in menu) { if (m.IsShowing) { m.Show(sb, mouseState); } } }
public void ExitGame(MouseState mouseState, MouseState oldState, Game game) { if (isShowing) { if (Simplify.MouseSelect(font, mouseState, Simplify.GetCenterText(font, "Exit"), Game.Height / 3 + 140, "Exit")) { if (mouseState.LeftButton == ButtonState.Released && oldState.LeftButton == ButtonState.Pressed) { game.Exit(); } } } }
private static void _Main(string[] args) { // input "x = 2*(3+3)" ICharStream input; if (args.Length > 0) { if (args[0].Equals("-i")) { if (args.Length > 1) { input = new ANTLRFileStream(args[1]); } else { throw new Exception("No input file specified."); } } else { input = new ANTLRStringStream(args[0]); } } else { input = new ANTLRInputStream(Console.OpenStandardInput()); } var lex = new VecMathLexer(input); var tokens = new CommonTokenStream(lex); var g = new VecMathParser(tokens); IAstRuleReturnScope <CommonTree> r = g.prog(); CommonTree t = r.Tree; Console.WriteLine("Original tree: " + t.ToStringTree()); var simplify = new Simplify(new CommonTreeNodeStream(t)); t = (CommonTree)simplify.Downup(t); var reduce = new Reduce(new CommonTreeNodeStream(t)); t = (CommonTree)reduce.Downup(t); Console.WriteLine("Simplified tree: " + t.ToStringTree()); Console.ReadKey(); }
// When pointer enter service upgrade button, tool tip will be appear public void ToolTipPointerEnter(int buttonInd) { if (upgradeCost[buttonInd] == -1 || upgradeCost[buttonInd] == -2) { return; } toolTip = (GameObject)GameManager.Instantiate(Resources.Load("ToolTip"), GameObject.Find("Canvas").GetComponent <Canvas>().transform); toolTip.transform.position = new Vector3(upgradeBtn[buttonInd].transform.position.x, upgradeBtn[buttonInd].transform.position.y + 20, 0); Text ToolTipTxt = toolTip.transform.Find("ToolTipTxt").gameObject.GetComponent <Text>(); ToolTipTxt.text = title + " produce twice\n" + "Cost: " + Simplify.LargeNumConvert(upgradeCost[buttonInd]); toolTip.GetComponent <RectTransform>().sizeDelta = new Vector2(ToolTipTxt.preferredWidth, ToolTipTxt.preferredHeight); }
public override void Show(SpriteBatch sb, MouseState mouseState) { Simplify.DarkenText(sb, font, selected[0], Game.Width - 75, Game.Height - 50, "OK"); Simplify.DarkenText(sb, font, selected[1], 20, Game.Height - 50, "Back"); Simplify.DarkenText(sb, font, selected[2], Game.Width / 2 - 250, Game.Height - 100, "New Character"); Simplify.DarkenText(sb, font, selected[3], Game.Width / 2 + 50, Game.Height - 100, "Delete Character"); for (int i = 0; i < highlightedCharacter.Length; i++) { if (i == selectedCharacter) { sb.DrawString(font, "Character one", new Vector2(Game.Width / 8, (Game.Height / 4) + (35 * i)), Color.Beige); } else { Simplify.DarkenText(sb, font, highlightedCharacter[i], Game.Width / 8, (Game.Height / 4) + (35 * i), "Character one"); } } }
private static void _Main(string[] args) { // input "x = 2*(3+3)" ICharStream input; if (args.Length > 0) { if (args[0].Equals("-i")) { if (args.Length > 1) { input = new ANTLRFileStream(args[1]); } else { throw new Exception("No input file specified."); } } else { input = new ANTLRStringStream(args[0]); } } else { input = new ANTLRInputStream(Console.OpenStandardInput()); } var lex = new VecMathLexer(input); var tokens = new CommonTokenStream(lex); var g = new VecMathParser(tokens); IAstRuleReturnScope<CommonTree> r = g.prog(); CommonTree t = r.Tree; Console.WriteLine("Original tree: " + t.ToStringTree()); var simplify = new Simplify(new CommonTreeNodeStream(t)); t = (CommonTree)simplify.Downup(t); var reduce = new Reduce(new CommonTreeNodeStream(t)); t = (CommonTree)reduce.Downup(t); Console.WriteLine("Simplified tree: " + t.ToStringTree()); Console.ReadKey(); }
public void TestSimplify() { var p = new Parser("3*x*x*x").Parse(); Simplify.SimplifyExpression(p); if (p.ToString() != "3*x^3") { throw new Exception("Simplification failed"); } p = new Parser("(3x^2)(2x^2)").Parse(); Simplify.SimplifyExpression(p); if (p.ToString() != "6*x^4") { throw new Exception("Simplification failed"); } }
public override void SelectMenu(MouseState mouseState, MouseState oldState) { for (int i = 0; i < selected.Length; i++) { selected[i] = false; } if (isShowing) { if (Simplify.MouseSelect(font, mouseState, Simplify.GetCenterText(font, "Video"), Game.Height / 3, "Video")) { selected[0] = true; } else if (Simplify.MouseSelect(font, mouseState, Simplify.GetCenterText(font, "Audio"), Game.Height / 3 + 35, "Audio")) { selected[1] = true; } else if (Simplify.MouseSelect(font, mouseState, Simplify.GetCenterText(font, "Exit"), Game.Height / 3 + 70, "Exit")) { selected[2] = true; } } }
public void TestPowersOfZero() { var p = new Parser("x^0").Parse(); Simplify.PowersOfZero(p); if (p.ToString() != "1") { Assert.Fail(); } p = new Parser("2^0").Parse(); Simplify.PowersOfZero(p); if (p.ToString() != "1") { Assert.Fail(); } p = new Parser("1+2^0").Parse(); Simplify.PowersOfZero(p); if (p.ToString() != "1+1") { Assert.Fail(); } p = new Parser("1+x^0").Parse(); Simplify.PowersOfZero(p); if (p.ToString() != "1+1") { Assert.Fail(); } p = new Parser("1+(x+5)^0").Parse(); Simplify.PowersOfZero(p); if (p.ToString() != "1+1") { Assert.Fail(); } }
private static void ApplySimplificationFunctions(ref string rename, JsonConfig prefs) { // Order sensitive operations (first) [NOTE: all are call by reference] Simplify.RemoveNumbers(ref rename, prefs); Simplify.AppendYearPre(ref rename, prefs); // Order insensitive operations [NOTE: all are call by reference] Simplify.RemoveCurvedBracket(ref rename, prefs); Simplify.RemoveSquareBracket(ref rename, prefs); Simplify.RemoveBlacklistedWords(ref rename, prefs); Simplify.RemoveNonASCII(ref rename, prefs); // Order sensitive operations (last) [NOTE: all are call by reference] Simplify.AppendYearPost(ref rename, prefs); Simplify.SmartEpisodeDash(ref rename, prefs); Simplify.ReduceWhitespace(ref rename); Simplify.ConvertToSentenceCase(ref rename, prefs); Simplify.OptimizeArticles(ref rename, prefs); Simplify.ConvertToCliFriendly(ref rename, prefs); Simplify.ConvertToLowercase(ref rename, prefs); }
public override void SelectMenu(MouseState mouseState, MouseState oldState) { for (int i = 0; i < selected.Length; i++) { selected[i] = false; } for (int i = 0; i < highlightedCharacter.Length; i++) { highlightedCharacter[i] = false; } if (isShowing) { if (Simplify.MouseSelect(font, mouseState, Game.Width - 75, Game.Height - 50, "OK")) { selected[0] = true; } else if (Simplify.MouseSelect(font, mouseState, 20, Game.Height - 50, "Back")) { selected[1] = true; } else if (Simplify.MouseSelect(font, mouseState, Game.Width / 2 - 250, Game.Height - 100, "New Character")) { selected[2] = true; } else if (Simplify.MouseSelect(font, mouseState, Game.Width / 2 + 50, Game.Height - 100, "Delete Character")) { selected[3] = true; } for (int i = 0; i < highlightedCharacter.Length; i++) { if (Simplify.MouseSelect(font, mouseState, Game.Width / 8, (Game.Height / 4) + (35 * i), "Character one")) { highlightedCharacter[i] = true; } } } }
public void SelectMenu(MouseState mouseState, MouseState oldState) { for (int i = 0; i < selected.Length; i++) { selected[i] = false; } if (Simplify.MouseSelect(chatFont, mouseState, Simplify.GetCenterText(chatFont, "Talk"), 20, "Talk")) { selected[0] = true; if (mouseState.LeftButton == ButtonState.Released && oldState.LeftButton == ButtonState.Pressed) { PlayState.Player.MerchantChatting = false; PlayState.Player.AddChatLine("For just a cup of coffee a day, you can experience some of my finest weapons."); PlayState.Player.Chat(); } } else if (Simplify.MouseSelect(chatFont, mouseState, Simplify.GetCenterText(chatFont, "Buy/Sell"), 40, "Buy/Sell")) { selected[1] = true; if (mouseState.LeftButton == ButtonState.Released && oldState.LeftButton == ButtonState.Pressed) { PlayState.Player.MerchantChatting = false; PlayState.Player.Chat(); isTrading = true; } } else if (Simplify.MouseSelect(chatFont, mouseState, Simplify.GetCenterText(chatFont, "Close"), 60, "Close")) { selected[2] = true; if (mouseState.LeftButton == ButtonState.Released && oldState.LeftButton == ButtonState.Pressed) { PlayState.Player.MerchantChatting = false; PlayState.Player.Chat(); } } }
public void TestZeroMultiplicationSimplify() { var x = new Parser("0*1*3+1"); var n = x.Parse(); Simplify.ZeroMultiplication(n); if (n.ToString() != "0+1") { Assert.Fail(); } n = new Parser("1*0*3+1").Parse(); Simplify.ZeroMultiplication(n); if (n.ToString() != "0+1") { Assert.Fail(); } n = new Parser("1*3*0+1").Parse(); Simplify.ZeroMultiplication(n); if (n.ToString() != "0+1") { Assert.Fail(); } n = new Parser("1*3+1*0").Parse(); Simplify.ZeroMultiplication(n); if (n.ToString() != "1*3+0") { Assert.Fail(); } }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns>The result of analysis.</returns> public string Analyze(Simplify exp) { return(ToString(exp, "simplify({0})")); }
/// <summary> /// Analyzes the specified expression. /// </summary> /// <param name="exp">The expression.</param> /// <returns> /// The result of analysis. /// </returns> /// <exception cref="System.NotSupportedException">Always.</exception> public virtual TResult Analyze(Simplify exp) { throw new NotSupportedException(); }
/// <summary> /// Creates an expression object from <see cref="FunctionToken"/>. /// </summary> /// <param name="token">The function token.</param> /// <returns>An expression.</returns> protected virtual IExpression CreateFunction(FunctionToken token) { IExpression exp; switch (token.Function) { case Functions.Add: exp = new Add(); break; case Functions.Sub: exp = new Sub(); break; case Functions.Mul: exp = new Mul(); break; case Functions.Div: exp = new Div(); break; case Functions.Pow: exp = new Pow(); break; case Functions.Absolute: exp = new Abs(); break; case Functions.Sine: exp = new Sin(); break; case Functions.Cosine: exp = new Cos(); break; case Functions.Tangent: exp = new Tan(); break; case Functions.Cotangent: exp = new Cot(); break; case Functions.Secant: exp = new Sec(); break; case Functions.Cosecant: exp = new Csc(); break; case Functions.Arcsine: exp = new Arcsin(); break; case Functions.Arccosine: exp = new Arccos(); break; case Functions.Arctangent: exp = new Arctan(); break; case Functions.Arccotangent: exp = new Arccot(); break; case Functions.Arcsecant: exp = new Arcsec(); break; case Functions.Arccosecant: exp = new Arccsc(); break; case Functions.Sqrt: exp = new Sqrt(); break; case Functions.Root: exp = new Root(); break; case Functions.Ln: exp = new Ln(); break; case Functions.Lg: exp = new Lg(); break; case Functions.Lb: exp = new Lb(); break; case Functions.Log: exp = new Log(); break; case Functions.Sineh: exp = new Sinh(); break; case Functions.Cosineh: exp = new Cosh(); break; case Functions.Tangenth: exp = new Tanh(); break; case Functions.Cotangenth: exp = new Coth(); break; case Functions.Secanth: exp = new Sech(); break; case Functions.Cosecanth: exp = new Csch(); break; case Functions.Arsineh: exp = new Arsinh(); break; case Functions.Arcosineh: exp = new Arcosh(); break; case Functions.Artangenth: exp = new Artanh(); break; case Functions.Arcotangenth: exp = new Arcoth(); break; case Functions.Arsecanth: exp = new Arsech(); break; case Functions.Arcosecanth: exp = new Arcsch(); break; case Functions.Exp: exp = new Exp(); break; case Functions.GCD: exp = new GCD(); break; case Functions.LCM: exp = new LCM(); break; case Functions.Factorial: exp = new Fact(); break; case Functions.Sum: exp = new Sum(); break; case Functions.Product: exp = new Product(); break; case Functions.Round: exp = new Round(); break; case Functions.Floor: exp = new Floor(); break; case Functions.Ceil: exp = new Ceil(); break; case Functions.Derivative: exp = new Derivative(); break; case Functions.Simplify: exp = new Simplify(); break; case Functions.Del: exp = new Del(); break; case Functions.Define: exp = new Define(); break; case Functions.Vector: exp = new Vector(); break; case Functions.Matrix: exp = new Matrix(); break; case Functions.Transpose: exp = new Transpose(); break; case Functions.Determinant: exp = new Determinant(); break; case Functions.Inverse: exp = new Inverse(); break; case Functions.If: exp = new If(); break; case Functions.For: exp = new For(); break; case Functions.While: exp = new While(); break; case Functions.Undefine: exp = new Undefine(); break; case Functions.Im: exp = new Im(); break; case Functions.Re: exp = new Re(); break; case Functions.Phase: exp = new Phase(); break; case Functions.Conjugate: exp = new Conjugate(); break; case Functions.Reciprocal: exp = new Reciprocal(); break; case Functions.Min: exp = new Min(); break; case Functions.Max: exp = new Max(); break; case Functions.Avg: exp = new Avg(); break; case Functions.Count: exp = new Count(); break; case Functions.Var: exp = new Var(); break; case Functions.Varp: exp = new Varp(); break; case Functions.Stdev: exp = new Stdev(); break; case Functions.Stdevp: exp = new Stdevp(); break; default: exp = null; break; } if (exp is DifferentParametersExpression diff) { diff.ParametersCount = token.CountOfParams; } return(exp); }