Esempio 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;
        }
Esempio n. 2
0
        public static String MakeMove()
        {
            HiPerfTimer timer = new HiPerfTimer();
            timer.Start();
            int x = Map.MyLocation.X;
            int y = Map.MyLocation.Y;

            GameState g = new GameState(readMap(), Map.MyLocation, Map.OpponentLocation);
            MapAnalyzer ma = new MapAnalyzer(g);

            if (g.getSuccessorStates(Player).Count == 0)
            {
                return randomMove();
            }

            bool separated = !ma.sameField(g.Player, g.Opponent);

            EvaluatorCollection ec = new EvaluatorCollection();
            Search s;
            if (!separated)
            {
                ec.add(new CutOffEvaluator());
                ec.add(new VoronoiEvaluator());
                s = new MiniMaxSearch();
            }
            else
            {
                ec.add(new FloodFillEvaluator());
                s = new MiniMaxSearch();
            }
            MultiplyEvaluators finalEval = new MultiplyEvaluators(new GameWinEvaluator(), ec);

            timer.Stop();
            int depth = 4;
            double time = timer.Duration * 1000;
            GameState best = new GameState();
            while (time < 500)
            {
                depth++;
                timer.Start();
                best = new GameState(s.doSearch(g, finalEval, depth, time));
                timer.Stop();
                time += timer.Duration * 1000;
            }
            //Console.Error.WriteLine(separated + " " + time + " " + depth);
            //ma.printMap();

            if (best.previousPlayerMove == null)
                return "N";
            else
                return intDirectionToString(best.previousPlayerMove.Direction);
        }
Esempio n. 3
0
 private void expand(int depth, double usedTime)
 {
     this.time = usedTime;
     //Console.Error.WriteLine("Timer: "+time);
     if (time <= 500 && depth >0)
     {
         HiPerfTimer timer = new HiPerfTimer();
         timer.Start();
         expand();
         foreach (MiniMaxNode n in Children)
         {
             expand(depth - 1, timer.Duration * 1000);
         }
         timer.Stop();
         time += timer.Duration * 1000;
     }
 }