Пример #1
0
        /// <summary>
        /// The entry point of the class returns a move in a timely manner..
        /// </summary>
        /// <param name="Position"></param>
        /// <returns></returns>
        public static string Project(int[][] Position /*game State*/)
        {
            timerStart = DateTime.Now;

            endEstimation = DateTime.Now;
            if (remainingTime <= 0)
            {
                return("a1a1");
            }
            endEstimation = endEstimation.AddSeconds(remainingTime / 64);

            //Only for the first turn
            if (start)
            {
                start = false;
                for (int j = 0; j < 8; j++)
                {
                    if (Position[6 /*white startLine*/][j] == 0)
                    {
                        im = false;//I'm black
                        break;
                    }
                }
                timerEnd      = DateTime.Now;
                remainingTime = remainingTime - ((timerEnd - timerStart).TotalSeconds);
                if (!im)//I'm black
                {
                    return("h7h6");
                }
                return("h2h3");
            }

            Cpe480 me = new Cpe480(im);

            move = me.MakeMove(Position);

            timerEnd      = DateTime.Now;
            remainingTime = remainingTime - ((timerEnd - timerStart).TotalSeconds);
            return(move);
        }
Пример #2
0
        /// <summary>
        /// Recursive Alpha Beta Depth Limited Search (if only i had more time {submission due time is in 13 minutes})
        /// </summary>
        /// <param name="Problem"></param>
        /// <param name="State"></param>
        /// <param name="Limit"></param>
        /// <param name="alpha"></param>
        /// <param name="beta"></param>
        /// <returns></returns>
        double RecursiveAlphaBetaDLS(Cpe480 Problem, int[][] State /*position*/, int Limit /*current recursion limit*/, double alpha, double beta)
        {
            if (endEstimation > DateTime.Now)
            {
                return(double.NaN);
            }
            if (pDepthLimit - Limit == (pDepthLimit - 1))
            {
                Cpe480 node = new Cpe480(pWhite);
                node.MakeMove(State);
                fringe.Push(node);
                return(RecursiveAlphaBetaDLS((Cpe480)fringe.Peek(), (int[][])pFringe.Peek(), 0, initialAlpha, initialBeta));
            }
            else
            {
                if (pDepthLimit - Limit != pDepthLimit)
                {
                    if (pWhite == im)
                    {
                        double maxValue = double.MinValue;

                        while (pFringe.Count != 0)
                        {
                            maxValue = Math.Max(maxValue, RecursiveAlphaBetaDLS(this, (int[][])pFringe.Peek(), Limit - 1, alpha, beta));
                            pFringe.Pop();
                            //if (maxValue == double.NaN)
                            //    goto l1;
                            if (endEstimation > DateTime.Now)
                            {
                                return(double.NaN);
                            }

                            if (maxValue >= beta)
                            {
                                pEstimatedMoveEvaluation = maxValue;
                                return(maxValue);
                            }
                            alpha = Math.Max(alpha, maxValue);
                            //l1:
                        }
                        pEstimatedMoveEvaluation = maxValue;
                        return(maxValue);
                    }
                    else
                    {
                        double minValue = double.MaxValue;

                        while (pFringe.Count != 0)
                        {
                            minValue = Math.Min(minValue, RecursiveAlphaBetaDLS(this, (int[][])pFringe.Peek(), Limit - 1, alpha, beta));
                            if (endEstimation > DateTime.Now)
                            {
                                return(double.NaN);
                            }
                            pFringe.Pop();
                            if (minValue <= alpha)
                            {
                                pEstimatedMoveEvaluation = minValue;
                                return(minValue);
                            }
                            beta = Math.Min(beta, minValue);
                        }
                        pEstimatedMoveEvaluation = minValue;
                        return(minValue);
                    }
                }
                return(double.NaN);
            }
        }