Exemple #1
0
 public DivEquation(BaseEquation _be) : base(_be.equation_console)
 {
     if (method != METHOD.DIV)
     {
         clear();
     }
     init();
 }
Exemple #2
0
 public AddEquation(BaseEquation _be) : base(_be.equation_console)
 {
     if (method != METHOD.ADD)
     {
         clear();
     }
     init();
 }
Exemple #3
0
 public MulEquation(BaseEquation _be) : base(_be.equation_console)
 {
     if (method != METHOD.MUL)
     {
         clear();
     }
     init();
 }
Exemple #4
0
        public static string get_results(BaseEquation equation)
        {
            string ret = "answer not found\r\n";
            LinkedList <DivEquation> sorted_equation_list     = new LinkedList <DivEquation>();
            List <DivEquation>       calculated_equation_list = new List <DivEquation>();
            DivEquation root = new DivEquation(equation);

            root.fix();
            sorted_equation_list = sorted_insert(sorted_equation_list, calculated_equation_list, root);
            while (true)
            {
                if (sorted_equation_list.Count == 0)
                {
                    break;
                }
                if (sorted_equation_list.First.Value.ans_found)
                {
                    if (ret == "answer not found\r\n")
                    {
                        ret = "";
                    }
                    ret += sorted_equation_list.First.Value.equation_console + "\r\n";
                    break;
                }
                LinkedListNode <DivEquation> now = sorted_equation_list.First;
                sorted_equation_list.RemoveFirst();
                List <char> ava_l = now.Value.available_letters_from_last(1);
                List <int>  ava_n = now.Value.available_nums();
                for (int i = 0; i < ava_n.Count; i++)
                {
                    if (ava_n[i] == 0)
                    {
                        int first_l = now.Value.get_first_in_each_line().IndexOf(ava_l[0]);
                        if (first_l != -1 && now.Value.spilt_string_without_operator[first_l].Length > 1)
                        {
                            continue;
                        }
                    }
                    string      new_eva = now.Value.replace(ava_l[0], ava_n[i]);
                    DivEquation new_eq  = new DivEquation(new_eva);
                    if (new_eq.ans_found)
                    {
                        if (ret == "answer not found\r\n")
                        {
                            ret = "";
                        }
                        ret += new_eq.equation_console + "\r\n";
                        continue;
                    }
                    sorted_equation_list = sorted_insert(sorted_equation_list, calculated_equation_list, new_eq);
                }
            }
            return(ret);
        }
Exemple #5
0
        public async Task <string> get_result(string console)
        {
            console = console.Replace(" ", "");
            console = console.Replace("\r", "");
            console = console.Replace("\n", "");
            for (int i = 0; i < 16; i++)
            {
                if (console.IndexOf((char)('J' + i + 1)) != -1)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        if (console.IndexOf((char)('A' + j)) == -1)
                        {
                            console.Replace((char)('J' + i + 1), (char)('A' + j));
                            break;
                        }
                    }
                }
            }
            BaseEquation be = new BaseEquation(console);

            if (be.method == BaseEquation.METHOD.ADD)
            {
                MazeAdd ma = new MazeAdd();
                ma.callback += upload;
                return(await ma.get_results(be));
            }
            else if (be.method == BaseEquation.METHOD.SUB)
            {
                MazeSub ms = new MazeSub();
                ms.callback += upload;
                return(await ms.get_results(be));
            }
            else if (be.method == BaseEquation.METHOD.MUL)
            {
                MazeMul mm = new MazeMul();
                mm.callback += upload;
                return(await mm.get_results(be));
            }
            else if (be.method == BaseEquation.METHOD.DIV)
            {
                return(MazeDiv.get_results(be));
            }
            return("Wrong input\r\n");
        }
Exemple #6
0
        /// <summary>
        /// 判断对方算式是否与我相同
        /// </summary>
        /// <param name="base_equation">被判断的算式</param>
        /// <returns></returns>
        public bool same_as(BaseEquation base_equation)
        {
            string a = equation_console;
            string b = base_equation.equation_console;

            if (a.Length != b.Length)
            {
                return(false);
            }
            if (this.method != base_equation.method)
            {
                return(false);
            }
            foreach (char c in LETTER_TABLE)
            {
                a = a.Replace(c, 'Z');
                b = b.Replace(c, 'Z');
            }
            return(a == b);
        }
Exemple #7
0
        /// <summary>
        /// 寻找解,找不到时返回"answer not found\r\n"
        /// <para>每个解占一行</para>
        /// </summary>
        /// <param name="equation">要找的方程</param>
        /// <returns></returns>
        public async Task <string> get_results(BaseEquation equation)
        {
            string ret = "answer not found\r\n";
            LinkedList <AddEquation> sorted_equation_list     = new LinkedList <AddEquation>();
            List <AddEquation>       calculated_equation_list = new List <AddEquation>();
            AddEquation root = new AddEquation(equation);

            sorted_equation_list = sorted_insert(sorted_equation_list, calculated_equation_list, root);
            AddEquation first_ans     = null;
            bool        already_first = false;

            while (true)
            {
                if (sorted_equation_list.Count == 0)
                {
                    break;
                }
                ConsoleMazeMain.BaseEquationEventArgs ee = new ConsoleMazeMain.BaseEquationEventArgs();
                ee.be = sorted_equation_list.First.Value;
                callback(this, ee);
                bool bk = false;
                await Task.Run(() =>
                {
                    //if (sorted_equation_list.Count == 0)
                    //{
                    //    bk = true;
                    //    return;
                    //}
                    if (sorted_equation_list.First.Value.ans_found)
                    {
                        if (ret == "answer not found\r\n")
                        {
                            first_ans = sorted_equation_list.First.Value;
                            ret       = "";
                        }
                        ret += sorted_equation_list.First.Value.equation_console + "\r\n";
                        bk   = true;
                        return;
                    }
                    LinkedListNode <AddEquation> now = sorted_equation_list.First;
                    sorted_equation_list.RemoveFirst();
                    List <char> ava_l = now.Value.available_letters_from_last();
                    List <int> ava_n  = now.Value.available_nums();
                    for (int i = 0; i < ava_n.Count; i++)
                    {
                        if (ava_n[i] == 0)
                        {
                            int first_l = now.Value.get_first_in_each_line().IndexOf(ava_l[0]);
                            if (first_l != -1 && now.Value.spilt_string_without_operator[first_l].Length > 1)
                            {
                                continue;
                            }
                        }
                        string new_eva     = now.Value.replace(ava_l[0], ava_n[i]);
                        AddEquation new_eq = new AddEquation(new_eva);
                        if (new_eq.ans_found)
                        {
                            if (ret == "answer not found\r\n")
                            {
                                first_ans = new_eq;
                                ret       = "";
                            }
                            ret += new_eq.equation_console + "\r\n";
                            continue;
                        }
                        sorted_equation_list = sorted_insert(sorted_equation_list, calculated_equation_list, new_eq);
                    }
                });

                if (first_ans != null && !already_first)
                {
                    ConsoleMazeMain.BaseEquationEventArgs ee2 = new ConsoleMazeMain.BaseEquationEventArgs();
                    ee2.be     = first_ans;
                    ee2.is_ans = true;
                    callback(this, ee2);
                    already_first = true;
                }

                if (bk)
                {
                    break;
                }
            }
            return(ret);
        }
Exemple #8
0
 public SubEquation(BaseEquation _be) : base(_be.equation_console)
 {
     init();
 }