Exemplo n.º 1
0
        void t_Tick(object sender, EventArgs e)
        {
            var document = (IHTMLDocument3)web_browser.Document;

            var last = document.getElementsByName("last_dropIt")
                       .OfType <IHTMLElement>()
                       .Select(element => element.getAttribute("value"))
                       .FirstOrDefault();

            var value = document.getElementsByName("texter")
                        .OfType <IHTMLElement>()
                        .Select(element => element.getAttribute("value"))
                        .FirstOrDefault();
            int idx_tmp;

            if (last != null && last != "")
            {
                int info = int.Parse(last);
                if (info == 8)
                {
                    return;
                }
                if (info == 7)
                {
                    board.clear(Board.RED);
                }
                else
                {
                    board.move(info, out idx_tmp);
                }
            }

            if (value == "User's turn.")
            {
                PerfectMove pm  = new PerfectMove(board);
                int         idx = pm.findPerfectMove(Board.RED, 7);
                board.move(idx, out idx_tmp);
                web_browser.InvokeScript("dropIt", idx);
                zombie.IsEnabled      = false;
                necromancer.IsEnabled = true;
            }
        }
Exemplo n.º 2
0
        public int findPerfectMove(int color, int depth)
        {
            start_color = color;
            List <res> results = new List <res>();
            int        idx;

            for (int i = 0; i < 7; i++)
            {
                if (board.move(i, out idx))
                {
                    res r = new res();
                    r.result = recursiveMinMax(false, depth - 1, -999999, 999999);
                    r.move   = i;
                    results.Add(r);
                    board.retract(i, idx);
                }
            }
            results.Sort(delegate(res r1, res r2){
                return(r1.result > r2.result ? -1 : 1);
            });
            float best  = results[0].result;
            int   count = 0;

            for (count = 1; count < results.Count; count++)
            {
                if (results[count].result < best)
                {
                    break;
                }
            }

            Random random = new Random();

            return(results[random.Next(count)].move);
            //return results[0].move;
        }