Example #1
0
 private int GetProb(MATH2.IMathPlugin plugin, string raw, Expression e)
 {
     try
     {
         return(plugin.GetProb(raw, e));
     }
     catch (Exception ex)
     {
         Console.WriteLine(@"[SOLVER """ + plugin.GetType().Name.ToUpper() + @""" INSTANTIATION ERROR!] " + ex.Message);
         return(int.MinValue);
     }
 }
Example #2
0
        private static void OnTextChanged(string raw)//or whatever moooooo
        {
            List <int> probs = new List <int>();

            Expression e = null;

            try
            {
                e = Infix.ParseOrThrow(raw);
            }
            catch { }
            foreach (var item in plugins)
            {
                probs.Add(GetProb(Activator.CreateInstance(item) as MATH2.IMathPlugin, raw, e));
            }
            MATH2.IMathPlugin pl = Activator.CreateInstance(plugins[probs.IndexOf(probs.Max())]) as MATH2.IMathPlugin;
            Console.WriteLine("Using the " + plugins[probs.IndexOf(probs.Max())].Name + " solver to solve your question:");
            List <Step> steps = null;

            try
            {
                steps = pl.Solve(raw, e);
                Console.WriteLine("Answer: " + steps.Last());
            }
            catch (Exception exc)
            {
                if (MATH2.MasterForm.Clear)
                {
                    Console.Clear();
                }
                Console.WriteLine("A " + exc.GetType().Name + " error occured whilst the solver was calculating the answer.");
                System.Threading.Thread.Sleep(2000); if (MATH2.MasterForm.Clear)
                {
                    Console.Clear();
                }
                Main();
            }
            if (steps != null)
            {
                //   Console.ReadKey();
                Console.WriteLine("Steps");
                foreach (var step in steps)
                {
                    Console.WriteLine(step);
                }
            }
            // Console.Clear();
        }
Example #3
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (MasterForm.Clear)
            {
                Console.Clear();
            }
            Answers.Controls.Clear();
            this.FinalAnswer.Controls.Clear();
            Console.WriteLine("Using the " + plugins[comboBox1.SelectedIndex].Name + " solver to solve your question:");
            Expression ex = null;

            try
            {
                ex = Infix.ParseOrThrow(fastColoredTextBox1.Text);
            }
            catch { }
            MATH2.IMathPlugin pl = Activator.CreateInstance(plugins[comboBox1.SelectedIndex]) as MATH2.IMathPlugin;
            //LoadArgs(pl);
            List <Step> steps = pl.Solve(fastColoredTextBox1.Text, ex);// ;

            try
            {
                // steps = pl.Solve(fastColoredTextBox1.Text, ex);
                while (steps == null)
                {
                }
                Console.WriteLine("Answer: " + steps.Last());
                int  no        = steps.Count;
                bool shouldtry = true;
tryagain:
                if (no <= 0)
                {
                    shouldtry = false;
                }
                Console.WriteLine("trying");
                try
                {
                    MATH2.Controls.StepUC uc = steps[no].GetControl();
                    //overide these vars
                    uc.needoffset      = false;
                    uc.stepnotevisible = false;
                    //  uc.BackColor = FinalAnswer.BackColor;

                    uc.Dock = DockStyle.None;
                    FinalAnswer.Controls.Add(uc);
                }
                catch
                {
                    no--;
                    if (shouldtry)
                    {
                        goto tryagain;
                    }
                }
            }
            catch (Exception exc)
            {
                if (MATH2.MasterForm.Clear)
                {
                    Console.Clear();
                }
                Console.WriteLine("A " + exc.GetType().Name + " error occured whilst the solver was calculating the answer.");
                //   System.Threading.Thread.Sleep(2000); Console.Clear();// Main();
            }
            if (steps != null)
            {
                //Console.ReadKey();
                Console.WriteLine("Steps");
                foreach (var step in steps)
                {
                    Console.WriteLine(step);
                    try
                    {
                        MATH2.Controls.StepUC uc = step.GetControl();
                        uc.Dock = DockStyle.None;
                        Answers.Controls.Add(uc);
                    }
                    catch { Console.WriteLine("No display defined"); }
                }
            }
        }