Esempio n. 1
0
        public void Battle2()
        {
            var config = new Config(3, 3)
                    .AddMission(0, 0, Direction.E, "MMLMRMLMM")
                    .AddMission(3, 3, Direction.S, "MRMRMLMLMMRRMLMRM");

            var battle = new Battle(config);
            var results = battle.Run();

            Assert.AreEqual(2, results.Count);
            AssertRobot(results[0], 3, 3, Direction.N);
            AssertRobot(results[1], 0, 3, Direction.N);
        }
Esempio n. 2
0
        public void Battle1()
        {
            var config = new Config(5, 5)
                    .AddMission(1, 2, Direction.N, "LMLMLMLMM")
                    .AddMission(3, 3, Direction.E, "MMRMMRMRRM");

            var battle = new Battle(config);
            var results = battle.Run();

            Assert.AreEqual(2, results.Count);
            AssertRobot(results[0], 1, 3, Direction.N);
            AssertRobot(results[1], 5, 1, Direction.E);
        }
Esempio n. 3
0
        public void CanUseSameConfigTwice()
        {
            var config = new Config(3, 3)
                .AddMission(0, 0, Direction.E, "MMLMRMLMM")
                .AddMission(3, 3, Direction.S, "MRMRMLMLMMRRMLMRM");

            // Use same config twice, expecting that it doesn't affect second run (config is not mutated).
            new Battle(config).Run();
            var battle = new Battle(config);
            var results = battle.Run();

            Assert.AreEqual(2, results.Count);
            AssertRobot(results[0], 3, 3, Direction.N);
            AssertRobot(results[1], 0, 3, Direction.N);
        }
Esempio n. 4
0
        public void RobotCannotFallOffInAnyDirection()
        {
            var config = new Config(1, 1)
                    .AddMission(0, 0, Direction.N, "MMMM")
                    .AddMission(0, 0, Direction.E, "MMMM")
                    .AddMission(0, 0, Direction.S, "MMMM")
                    .AddMission(0, 0, Direction.W, "MMMM");

            var battle = new Battle(config);
            var results = battle.Run();

            Assert.AreEqual(4, results.Count);
            AssertRobot(results[0], 0, 1, Direction.N);
            AssertRobot(results[1], 1, 0, Direction.E);
            AssertRobot(results[2], 0, 0, Direction.S);
            AssertRobot(results[3], 0, 0, Direction.W);
        }
Esempio n. 5
0
        /// <summary>
        /// In the best traditions of UNIX command line apps, outputs nothing if successful.
        /// </summary>
        public static void Main(string[] args)
        {
            if (args.Length < 2) {
                Console.WriteLine("Usage: Robots.exe <configFilePath> <outputFilePath>");
            } else {
                // All Exceptions (IO and otherwise) are handled as one.
                try {
                    var configFilePath = args[0];
                    var outputFilePath = args[1];

                    Config config = ReadConfig(configFilePath);
                    List<Robot> results = new Battle(config).Run();
                    WriteResults(outputFilePath, results);
                }
                catch (Exception e) {
                    // qq Does this actually provide good messages for all types of exception,
                    //    from file loading and config parsing?
                    Console.WriteLine(e.Message);
                }
            }
        }