Пример #1
0
 public Blunder(Blunder blunder)
 {
     Location = new Coordinate(blunder.Location);
     Facing   = new Direction(blunder.Facing);
     Breaker  = blunder.Breaker;
     Inverted = blunder.Inverted;
 }
Пример #2
0
        public void ReturnSomethingElseTest()
        {
            Trace.WriteLine($"{DateTime.Now:HH:mm:ss.fff}: ReturnSomethingElseTest Start.");
            var a = new Blunder();

            Assert.AreEqual(a.ReturnSomethingElse(), 200);
            Trace.WriteLine($"{DateTime.Now:HH:mm:ss.fff}: ReturnSomethingElseTest End.");
        }
Пример #3
0
    public override bool Equals(Object obj)
    {
        //Check for null and compare run-time types.
        if ((obj == null) || !this.GetType().Equals(obj.GetType()))
        {
            return(false);
        }
        else
        {
            Blunder blunder = (Blunder)obj;

            // Don't find anything equal when the obstacle paths are being navigated
            return(!blunder._exploringObstaclePaths &&
                   (Location == blunder.Location) &&
                   (Facing == blunder.Facing) &&
                   (Breaker == blunder.Breaker) &&
                   (Inverted == blunder.Inverted));
        }
    }
Пример #4
0
    static void Main(string[] args)
    {
        string[]          inputs      = Console.ReadLine().Split(' ');
        int               L           = int.Parse(inputs[0]);
        int               C           = int.Parse(inputs[1]);
        List <Coordinate> teleporters = new List <Coordinate>();
        Blunder           blunder     = new Blunder();
        List <Blunder>    breadCrumbs = new List <Blunder>();

        for (int rowNum = 0; rowNum < L; rowNum++)
        {
            string row = Console.ReadLine();
            Console.Error.WriteLine(row);

            int colNum = 0;
            foreach (var type in row)
            {
                Coordinate location = new Coordinate(colNum, rowNum);
                _map.Squares.Add(location, GetSquare(type));

                if ((SquareTypes)type == SquareTypes.Teleporter)
                {
                    teleporters.Add(location);
                }
                else if ((SquareTypes)type == SquareTypes.Blunder)
                {
                    blunder = new Blunder(location);
                }

                colNum++;
            }
        }

        // There must be either 0 or 2 teleporters
        if (teleporters.Any())
        {
            ((Teleport)(_map.Squares[teleporters[0]])).Destination = teleporters[1];
            ((Teleport)(_map.Squares[teleporters[1]])).Destination = teleporters[0];
        }

        string output = string.Empty;

        while (true)
        {
            if (breadCrumbs.Contains(blunder))
            {
                Console.WriteLine("LOOP");
                System.Environment.Exit(0);
            }

            breadCrumbs.Add(new Blunder(blunder));

            var currentLocation       = new Coordinate(blunder.Location);
            var nextLocationDirection = new Direction(blunder.Facing);
            var nextLocation          = blunder.LocationAhead;
            var next = _map.Squares[blunder.LocationAhead];

            blunder.Execute(next, nextLocation);

            // If Blunder destroyed an obstacle
            if (_map.Squares[blunder.Location] is Obstacle)
            {
                _map.Squares[blunder.Location] = new Square();
                breadCrumbs.Clear();
                Console.Error.WriteLine("Obstacle destroyed at " + blunder.Location);
            }

            // If move happened, record it
            if (blunder.Location != currentLocation)
            {
                output += nextLocationDirection + "\n";
            }

            if (_map.Squares[blunder.Location] is Goal)
            {
                Console.Error.WriteLine("Goal hit at " + blunder.Location);
                Console.WriteLine(output);
                System.Environment.Exit(0);
            }
        }
    }