Exemplo n.º 1
0
        public GameState doSearch(GameState g, Evaluator e, int depth, double time)
        {
            HiPerfTimer timer = new HiPerfTimer();

            List<MiniMaxNode> trees = new List<MiniMaxNode>();
            foreach (GameState gs in g.getSuccessorStates(0))
            {
                timer.Start();
                trees.Add(MiniMaxNode.getGameTree(gs, e, depth, time));
                timer.Stop();
                time += timer.Duration * 1000;
            }

            int eval = 0;
            MiniMaxNode bestNode = new MiniMaxNode(g,e,0);
            foreach (MiniMaxNode tree in trees)
            {
                tree.score = tree.evaluate(int.MinValue, int.MaxValue);
                if (tree.score > eval)
                {
                    eval = tree.score;
                    bestNode = tree;
                }
            }

            return bestNode.State;
        }
Exemplo n.º 2
0
 public MiniMaxNode(GameState g, Evaluator e, int player, MiniMaxNode parent)
 {
     this.State = g;
     this.e = e;
     this.player = player;
     this.Parent = parent;
 }
Exemplo n.º 3
0
 //private volatile bool timesUp;
 //private double time;
 //public void timedSearch(int depth)
 //{
 //    timesUp = false;
 //    var timer = new Timer(800 - _start);
 //    //timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
 //    timer.Elapsed += timer_Elapsed;
 //    timer.Start();
 //    expand(depth);
 //    timer.Stop();
 //}
 public MiniMaxNode(GameState g, Evaluator e, int player)
 {
     this.State = g;
     this.e = e;
     this.player = player;
     Parent = this;
 }
Exemplo n.º 4
0
 public static MiniMaxNode getGameTree(GameState g, Evaluator e, int depth, double usedTime)
 {
     MiniMaxNode n = new MiniMaxNode(g, e, 0);
         n.expand(depth, usedTime);
     return n;
 }