示例#1
0
        private int negamax(List <AiBoard.Point> candidates, int role, int deep, int alpha, int beta)
        {
            count = 0;
            ABcut = 0;
            PVcut = 0;
            board.currentSteps.Clear();

            for (int i = 0; i < candidates.Count; i++)
            {
                var p = candidates[i];
                board.put(p, role);
                var steps = new List <AiBoard.Point> {
                    p
                };
                var v = r(deep - 1, -beta, -alpha, role == (int)AiConfig.player.com ? (int)AiConfig.player.hum : (int)AiConfig.player.com, 1, steps, 0);
                v.score *= -1;
                alpha    = Math.Max(alpha, v.score);
                board.remove(p);
                // p.v = v;

                if ((long)(DateTime.Now - TimeZoneInfo.ConvertTime(new System.DateTime(1970, 1, 1), TimeZoneInfo.Local)).TotalMilliseconds - start > AiConfig.timeLimit * 1000)
                {
                    break;
                }
            }

            return(alpha);
        }
示例#2
0
        // 电脑下棋
        public int[] begin()
        {
            var p = new AiBoard.Point(-1, -1);

            aiNegamax.init(aiBoard);
            if (aiBoard.allSteps.Count > 1)
            {
                p.p = aiOpening.match(aiBoard);
            }
            if (aiBoard.allSteps.Count <= 1 || p.p[0] == -1)
            {
                p = aiNegamax.deepAll(AiConfig.searchDeep)[0];
            }
            aiBoard.put(p, (int)AiConfig.player.com);
            return(p.p);
        }