Ejemplo n.º 1
0
        private void DoBestStep()
        {
            List <int[]> l   = board.GetEnableSteps(-1);
            int          j   = 0;
            int          max = -Int32.MaxValue;

            for (int i = 0; i < l.Count; i++)
            {
                Board cp = board.Copy();
                cp.AddFig(l[i][1], l[i][0], -1, true);
                int res = Board.GetBestStep(1, max, Int32.MaxValue, 0, cp, panel1);
                if (max < res)
                {
                    j   = i;
                    max = res;
                }
            }
            if (l.Count > j)
            {
                board.AddFig(l[j][1], l[j][0], -1, true);
            }
        }
Ejemplo n.º 2
0
        public static int GetBestStep(int p, int alpha, int beta, int deph, Board brd, Panel pan)
        {
            if (deph > 3 || brd.CompFig + brd.PlayersFig == Board.w * Board.w)
            {
                int k = brd.GetEvaluation(deph);
                return(k);
            }
            List <int[]> l = brd.GetEnableSteps(p);

            if (l.Count == 0 && p == -1)
            {
                return(-Int32.MaxValue);
            }

            int grade = (deph % 2 == 0) ? Int32.MaxValue : -Int32.MaxValue;

            foreach (int[] s in l)
            {
                if (AlphaBeta(alpha, beta, grade, deph))
                {
                    return((deph % 2 == 0) ? -Int32.MaxValue : Int32.MaxValue);
                }
                Board b = brd.Copy();
                b.AddFig(s[1], s[0], p, true);
                int res = GetBestStep(-p, alpha, beta, deph + 1, b, pan);
                grade = MinMax(res, grade, deph);
                if (beta > grade && deph % 2 == 0)
                {
                    beta = grade;
                }
                if (alpha < grade && deph % 2 == 1)
                {
                    alpha = grade;
                }
            }
            return(grade);
        }