Ejemplo n.º 1
0
 /// <summary>
 /// Determines whether a series of points are with
 /// the board, and if there is a square on that point.
 /// </summary>
 /// <param name="points"></param>
 /// <returns></returns>
 public bool IsSquareWithinBoard(Point[] points)
 {
     Contract.Requires(points != null);
     return points.All(IsSquareWithinBoard);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Is all points in the array standable?
 /// </summary>
 /// <param name="points"></param>
 /// <returns></returns>
 public bool IsStandable(Point[] points)
 {
     Contract.Requires(points != null);
     return points.All(p => IsStandable(p.X, p.Y));
 }
Ejemplo n.º 3
0
    static void Main(string[] args)
    {
        //tdd();

        string[] inputs;
        inputs = Console.ReadLine().Split(' ');
        int TX = int.Parse(inputs[0]);
        int TY = int.Parse(inputs[1]);

        var thor = new Point { X = TX, Y = TY };

        // game loop
        while (true)
        {
            inputs = Console.ReadLine().Split(' ');
            int H = int.Parse(inputs[0]); // the remaining number of hammer strikes.
            int N = int.Parse(inputs[1]); // the number of giants which are still present on the map.

            var giants = new Point[N];
            for (int i = 0; i < N; i++)
            {
                inputs = Console.ReadLine().Split(' ');
                int X = int.Parse(inputs[0]);
                int Y = int.Parse(inputs[1]);
                giants[i] = new Point { X = X, Y = Y };
            }

            if (giants.All(giant => giant.InKillZoneOf(thor)))
            {
                Console.Error.WriteLine("Thor strikes to kill all giants left");
                thorStrike();
            }
            else
            {
                var possibleDirections = excludeWalkingOffMap(thor, allDirections());

                var criticalDirections = giants.SelectMany(giant => critical(thor, giant)).ToArray();
                possibleDirections = possibleDirections.Except(criticalDirections).ToArray();
                Console.Error.WriteLine("Thor's survives to: {0}", string.Join(", ", possibleDirections.Select(d => d.ToString()).ToArray()));

                if (!possibleDirections.Any())
                {
                    Console.Error.WriteLine("Thor strikes because no other moves are left");
                    thorStrike();
                }
                else
                {
                    var target = calculateGiantsMedianPoint(giants);
                    Console.Error.WriteLine("Thor's target location is at {0}", target);

                    var scoredDirections = possibleDirections
                        .Select(d => new { Direction = d, Score = scoreDirection(d, thor, target) })
                        .OrderByDescending(x => x.Score);

                    var nextDirection = scoredDirections.Select(x => x.Direction).First();
                    Console.Error.WriteLine("Thor's best move is to: {0}", nextDirection);
                    moveThorTo(thor, nextDirection);
                }
            }
        }
    }