public int evaluation(GameState g, int player)
 {
     MapAnalyzer m = new MapAnalyzer(g);
     int playerFieldSize = m.fieldSize(player == 1 ? g.Opponent : g.Player);
     //Console.Error.WriteLine("Evaluate {0}|{1}: {2} {3}", (player == 1 ? g.Opponent.X : g.Player.X), (player == 1 ? g.Opponent.Y : g.Player.Y), playerFieldSize , opponentFieldSize);
     return playerFieldSize;
 }
Example #2
0
 public GameState(GameState g)
 {
     this.Map = (int[,])g.Map.Clone();
     this.Player = (Point)g.Player.Clone();
     this.Opponent = (Point)g.Opponent.Clone();
     this.previousPlayerMove = g.previousPlayerMove;
 }
Example #3
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;
        }
Example #4
0
 public MiniMaxNode(GameState g, Evaluator e, int player, MiniMaxNode parent)
 {
     this.State = g;
     this.e = e;
     this.player = player;
     this.Parent = parent;
 }
Example #5
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;
 }
Example #6
0
        public int evaluation(GameState g, int player)
        {
            MapAnalyzer ma = new MapAnalyzer(g.Map);
            int[] voronoi = MapManipulator.voronoiTerritory(g.Map, player == 0 ? g.Opponent : g.Player, player == 1 ? g.Opponent : g.Player);

            return voronoi[1] - voronoi[0];
        }
Example #7
0
        public int evaluation(GameState g, int player)
        {
            MapAnalyzer m = new MapAnalyzer(g.Map);

               int playerFieldSize = m.fieldSize(player == 1 ? g.Opponent : g.Player);
               int opponentFieldSize = m.fieldSize(player == 0 ? g.Opponent : g.Player);

               return playerFieldSize - opponentFieldSize;
        }
 public int evaluation(GameState g, int Player)
 {
     int evaluation = 0;
     foreach (Evaluator e in evaluators)
     {
         evaluation += e.evaluation(g, Player);
     }
     return evaluation;
 }
Example #9
0
 public int evaluation(GameState g, int player)
 {
     int winStatus = g.getCurrentResult();
     if (player == MyTronBot.Player && winStatus == 100) return Int16.MaxValue;
     if (player == MyTronBot.Player && winStatus == -10) return 1;
     if (player == MyTronBot.Player && winStatus == 0) return 1;
     if (player == MyTronBot.Opponent && winStatus == -100) return Int16.MaxValue;
     if (player == MyTronBot.Opponent && winStatus == -10) return 2;
     if (player == MyTronBot.Opponent && winStatus == 0) return 1;
     return winStatus;
 }
Example #10
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);
        }
Example #11
0
        public int evaluation(GameState g, int player)
        {
            int direction = g.previousPlayerMove.Direction;
            int[,] map = g.Map;

            //int[,] newMap = MapManipulator.straightLineFromPosition(map, player == 1 ? g.Opponent : g.Player, direction);
            //int distance = MapManipulator.distanceStraightLine(map, player == 1 ? g.Opponent : g.Player, direction);
            MapAnalyzer m = new MapAnalyzer(map);
            //m.printMap();

            //since MapAnalyzer actually clones the arrays and so player reports the wrong size if being part of the wall, manipulate the array directly
            //and fill opponent first, then check the player field size. this will report correct size
            int opponentFieldSize = m.fieldSize(player == 0 ? g.Opponent : g.Player);
            int playerFieldSize = m.fieldSize(player == 1 ? g.Opponent : g.Player);
            bool seperated = m.sameField(g.Player, g.Opponent);
            int score = 0;
            if (seperated && playerFieldSize > opponentFieldSize) return 100;
            if (seperated && opponentFieldSize > playerFieldSize) return -100;
            if (seperated && opponentFieldSize == playerFieldSize) return 5;

            if (g.Player.X + 1 == g.Opponent.X && g.Player.Y == g.Opponent.Y) score -= -50;
            if (g.Player.X - 1 == g.Opponent.X && g.Player.Y == g.Opponent.Y) score -= -50;
            if (g.Player.X == g.Opponent.X && g.Player.Y + 1 == g.Opponent.Y) score -= -50;
            if (g.Player.X == g.Opponent.X && g.Player.Y - 1 == g.Opponent.Y) score -= -50;
            if (g.Player.X +1== g.Opponent.X && g.Player.Y - 1 == g.Opponent.Y) score -= -50;
            if (g.Player.X-1 == g.Opponent.X && g.Player.Y - 1 == g.Opponent.Y) score -= -50;
            if (g.Player.X+1 == g.Opponent.X && g.Player.Y + 1 == g.Opponent.Y) score -= -50;
            if (g.Player.X-1 == g.Opponent.X && g.Player.Y + 1 == g.Opponent.Y) score -= -50;

            //Console.Error.WriteLine(MyTronBot.intDirectionToString(direction));
            //Console.Error.WriteLine("OpponentFieldSize: " + opponentFieldSize + " PlayerFieldSize: " + playerFieldSize);
            //Console.Error.WriteLine("Utility cutoff: " + (playerFieldSize - opponentFieldSize) + "\n");

            //Console.Error.WriteLine("Distance Eval: " + distanceEvaluation + "\nEval: " + evaluation);
            //if (opponentFieldSize < playerFieldSize) finalEval = playerFieldSize + distanceEvaluation;

            //Console.Error.WriteLine("FinalEval: " + finalEval);
            return score;
        }
Example #12
0
 public MapAnalyzer(GameState g)
 {
     this.Map = (int[,])g.Map.Clone();
 }
Example #13
0
 public int evaluation(GameState g, int player)
 {
     return e1.evaluation(g, player) * e2.evaluation(g, player);
 }
Example #14
0
 public int evaluation(GameState g, int player)
 {
     MapAnalyzer m = new MapAnalyzer(g);
     return m.CountWalls(player == 0 ? g.Player : g.Opponent);
 }
Example #15
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;
 }