Esempio n. 1
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];
        }
Esempio n. 2
0
 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;
 }
Esempio n. 3
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;
        }
Esempio n. 4
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. 5
0
 public int getCurrentResult()
 {
     MapAnalyzer ma = new MapAnalyzer(Map);
     int playerFields = ma.fieldSize(Player);
     int opponentFields = ma.fieldSize(Opponent);
     if (Player.X+1 == Opponent.X && Player.Y == Opponent.Y) return -10;
     if (Player.X-1 == Opponent.X && Player.Y == Opponent.Y) return -10;
     if (Player.X == Opponent.X && Player.Y+1 == Opponent.Y) return -10;
     if (Player.X == Opponent.X && Player.Y-1 == Opponent.Y) return -10;
     if (playerFields <= 1) return -100;
     if (opponentFields <= 1) return 100;
     return 0;
 }
Esempio n. 6
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;
        }
Esempio n. 7
0
 public bool sameField(Point pos1, Point pos2)
 {
     MapAnalyzer ma = new MapAnalyzer(Map);
     int pos1size = ma.fieldSize(pos1);
     int pos2size = ma.fieldSize(pos2);
     //Console.Error.WriteLine("Pos1: " + pos1size + " Pos2: " + pos2size);
     return (pos1size == pos2size);
 }
Esempio n. 8
0
 public int fieldSize(Point position)
 {
     MapAnalyzer ma = new MapAnalyzer(Map);
     int[,] temp = (int[,])Map.Clone();
     return MapManipulator.floodFill(temp, position);
 }
Esempio n. 9
0
        public static int[] voronoiTerritory(int[,] map, Point pos1, Point pos2)
        {
            MapAnalyzer ma = new MapAnalyzer(map);
            Queue<Point> q = new Queue<Point>();
            int player = 5;
            int opponent = 3;
            int temp;
            ma.Map[pos1.X, pos1.Y] = 5;
            ma.Map[pos2.X, pos2.Y] = 3;
            q.Enqueue(pos1);
            q.Enqueue(pos2);
            while (q.Count > 0)
            {

                Point poz = q.Dequeue();
                foreach (Point pozSuccessor in ma.getNeighbours(poz))
                {
                    if (ma.Map[pozSuccessor.X, pozSuccessor.Y] == 0)
                    {
                        if (ma.Map[poz.X, poz.Y] == 5)
                            ma.Map[pozSuccessor.X, pozSuccessor.Y] = 5;
                        if (ma.Map[poz.X, poz.Y] == 3)
                            ma.Map[pozSuccessor.X, pozSuccessor.Y] = 3;
                        q.Enqueue(pozSuccessor);
                    }
                }
                temp = player;
                player = opponent;
                opponent = temp;
                //ma.printMap();
            }
               // ma.printMap();
            //ma.Map[50,199] = 5;
            int[] result = new int[2];
            result[0] = 0;
            result[1] = 0;
            for (int x = 0; x < ma.Map.GetLength(0); x++)
            {
                for (int y = 0; y < ma.Map.GetLength(1); y++)
                {
                    switch (ma.Map[x, y])
                    {
                        case 5: result[0]++;
                            break;
                        case 3: result[1]++;
                            break;
                        default: break;
                    }
                }
            }
            //Console.Error.WriteLine(result[0] + " " + result[1]);
            return result;
        }
Esempio n. 10
0
        public List<GameState> getSuccessorStates()
        {
            List<List<Move>> Moves = getValidSuccessorMoves();
            List<GameState> GameStates = new List<GameState>();
            MapAnalyzer ma = new MapAnalyzer(this.Map);
            //ma.printMap();
            foreach (List<Move> moveList in Moves)
            {
                GameStates.Add(getStateAfterMoves(moveList));
            }

            return GameStates;
        }
Esempio n. 11
0
 public int evaluation(GameState g, int player)
 {
     MapAnalyzer m = new MapAnalyzer(g);
     return m.CountWalls(player == 0 ? g.Player : g.Opponent);
 }