Exemplo n.º 1
0
    static void Main(string[] args)
    {
        Random r = new Random();

        string[] inputs;
        int opponentCount = int.Parse(Console.ReadLine()); // Opponent count

        // game loop
        while (true)
        {
            int gameRound = int.Parse(Console.ReadLine());
            inputs = Console.ReadLine().Split(' ');
            var player = new Combatant { X = int.Parse(inputs[0]), Y = int.Parse(inputs[1]), BackInTimeLeft = int.Parse(inputs[2]) };

            var opponents = new Combatant[opponentCount];
            for (int i = 0; i < opponentCount; i++)
            {
                inputs = Console.ReadLine().Split(' ');
                opponents[i] = new Combatant { X = int.Parse(inputs[0]), Y = int.Parse(inputs[1]), BackInTimeLeft = int.Parse(inputs[2]) };
            }

            var map = new string[MAP_HEIGHT+2];
            map[0] = string.Join("", Enumerable.Repeat(CELL_WALL, MAP_WIDTH+2).ToArray());
            for (int i = 0; i < MAP_HEIGHT; i++)
            {
                map[i+1] = CELL_WALL +  Console.ReadLine() + CELL_WALL; // One line of the map ('.' = free, '0' = you, otherwise the id of the opponent)
            }
            map[MAP_HEIGHT+1] = string.Join("", Enumerable.Repeat(CELL_WALL, MAP_WIDTH+2).ToArray());

            //printMap(map);
            var mapChars = map.SelectMany(row=>row.Select(col=>col)).ToArray();
            for (int i = 0; i < opponentCount; i++)
            {
                opponents[i].Score = mapChars.Where(x => x.ToString() == (i + 1).ToString()).Count();
                Console.Error.WriteLine("Opponent " + 1 + " has score " + opponents[i].Score);
            }

            //Prefer any neutral cell
            Console.Error.WriteLine("I'm at " + player);
            var directions = directionsTo(map, player, CELL_NEUTRAL).ToArray();
            Console.Error.WriteLine("Neutral cells at: " + string.Join(", ", (directions.Select(d => d.ToString()).ToArray())));
            //if (!directions.Any())
            //{
            //	Console.Error.WriteLine("No neutrals found");
            //	//No neutral, so prefer an opponents cell, so we cross paths
            //	var visited = directionsTo(map, player, CELL_PLAYER);
            //	var walls = directionsTo(map, player, CELL_WALL[0]);
            //	directions = new Direction[] { Direction.TOP, Direction.RIGHT, Direction.BOTTOM, Direction.LEFT }.Except(walls).Except(visited).ToArray();
            //}
            if (directions.Any())
            {
                //Go in one of the available directions
                var nextDirection = (Direction)directions[r.Next(directions.Count())];
                var newLocation = player + nextDirection;
                Console.Error.WriteLine("Walking " + nextDirection.ToString() + " to " + newLocation);
                Console.WriteLine(newLocation.ToString());
            }
            else
            {
                //I'm trapped. Get out!
                Console.Error.WriteLine("Heading for leader");
                var point = opponents.OrderByDescending(x => x.Score).First();
                if (Math.Abs(point.X - player.X) > Math.Abs(point.Y - player.Y))
                    Console.WriteLine(point);
                else
                {
                    Console.WriteLine(new Point(player.X, point.Y));
                }
            }

            //Console.WriteLine("17 10"); // action: "x y" to move or "BACK rounds" to go back in time
        }
    }