Beispiel #1
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;
        }