Esempio n. 1
0
        public void TestRobots()
        {
            Mars world = Mars.GetInstance().InitializeWorld(_initialization);
            var  bot1  = new MarsBot(1);
            var  bot2  = new MarsBot(2);
            var  bot3  = new MarsBot(3);

            foreach (var inst in _bot1Instructions)
            {
                bot1.ProcessInstructions(inst);
            }

            foreach (var inst in _bot2Instructions)
            {
                bot2.ProcessInstructions(inst);
            }

            foreach (var inst in _bot3Instructions)
            {
                bot3.ProcessInstructions(inst);
            }

            Assert.AreEqual(new Tuple <int, int>(1, 1), bot1.State.CurrPosition);
            Assert.AreEqual(Orientation.E, bot1.State.CurrOrientation);
            Assert.AreEqual(new Tuple <int, int>(3, 3), bot2.State.CurrPosition);
            Assert.AreEqual(Orientation.N, bot2.State.CurrOrientation);
            Assert.AreEqual(new Tuple <int, int>(2, 3), bot3.State.CurrPosition);
            Assert.AreEqual(Orientation.S, bot3.State.CurrOrientation);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Mars world = Mars.GetInstance().InitializeWorld(_initialization);
            var  bot1  = new MarsBot(1);
            var  bot2  = new MarsBot(2);
            var  bot3  = new MarsBot(3);
            var  bots  = new List <MarsBot>();

            foreach (var inst in _bot1Instructions)
            {
                bot1.ProcessInstructions(inst);
            }
            bots.Add(bot1);

            foreach (var inst in _bot2Instructions)
            {
                bot2.ProcessInstructions(inst);
            }
            bots.Add(bot2);

            foreach (var inst in _bot3Instructions)
            {
                bot3.ProcessInstructions(inst);
            }
            bots.Add(bot3);

            foreach (var bot in bots)
            {
                var sb = new StringBuilder();
                sb.AppendFormat("{0} {1} {2}", bot.State.CurrPosition.Item1, bot.State.CurrPosition.Item2, bot.State.CurrOrientation);
                if (!bot.Active)
                {
                    sb.Append(" LOST");
                }
                Console.WriteLine(sb.ToString());
            }
            Console.ReadLine();
        }