예제 #1
0
파일: Tests.cs 프로젝트: GoodMan93/bot
 public void Test1()
 {
     var stream = new StreamReader("../../1.txt");
     var forest = new Forest();
     var mapLoader = new MapLoader();
     mapLoader.Download(stream, out forest.map);
     var creature = new Creature('A', "Alice", 4, 5, 3, 7);
     forest.AddCreature(creature);
     var bot = new Bot(creature, forest);
     bot.GoToEnd();
     Assert.AreEqual(true, creature.IsExitFound());
 }
예제 #2
0
파일: Tests.cs 프로젝트: DuckGoesQuack/bot
        public void Test1()
        {
            var stream    = new StreamReader("../../1.txt");
            var forest    = new Forest();
            var mapLoader = new MapLoader();

            mapLoader.Download(stream, out forest.map);
            var creature = new Creature('A', "Alice", 4, 5, 3, 7);

            forest.AddCreature(creature);
            var bot = new Bot(creature, forest);

            bot.GoToEnd();
            Assert.AreEqual(true, creature.IsExitFound());
        }
예제 #3
0
        public void GoToEnd()
        {
            Map[Creature.X, Creature.Y]       = new Path();
            Map[Creature.EndX, Creature.EndY] = new Path();

            Visits[Creature.X, Creature.Y]++;

            if (Creature.EndX == Creature.X && Creature.EndY == Creature.Y)
            {
                return;
            }

            Direction dir;

            if (Creature.EndX - Creature.X > 0)
            {
                dir = new Down();
            }
            else
            {
                if (Creature.EndX - Creature.X < 0)
                {
                    dir = new Up();
                }
                else
                {
                    if (Creature.EndY - Creature.Y < 0)
                    {
                        dir = new Right();
                    }
                    else
                    {
                        dir = new Left();
                    }
                }
            }

            var turns = 0;

            while (Creature.X != Creature.EndX || Creature.EndY != Creature.Y)
            {
                if (Forest.TryToMove(Creature, dir))
                {
                    if (OldLifes == Creature.Lifes)
                    {
                        Map[Creature.X, Creature.Y] = new Path();
                    }
                    if (OldLifes > Creature.Lifes)
                    {
                        Map[Creature.X, Creature.Y] = new Trap();
                    }
                    if (OldLifes < Creature.Lifes)
                    {
                        Map[Creature.X, Creature.Y] = new Life();
                    }

                    Visits[Creature.X, Creature.Y]++;

                    if (Visits[Creature.X, Creature.Y] > 4)
                    {
                        Console.WriteLine("There's no way out!!!!");
                        return;
                    }

                    dir = dir.TurnRight();

                    turns = 0;

                    Console.WriteLine("{0}, {1}, dir: {2}, {3}", Creature.X, Creature.Y, dir.dx, dir.dy);
                }
                else
                {
                    if (Creature.Lifes == 0)
                    {
                        Console.WriteLine("We are dead!!!!");
                        return;
                    }

                    Map[Creature.X + dir.dx, Creature.Y + dir.dy] = new Bush();
                    dir = dir.TurnLeft();

                    turns++;

                    if (turns >= 4)
                    {
                        Console.WriteLine("Can't move anywhere!!!!");
                        return;
                    }
                }
            }
            if (Creature.IsExitFound())
            {
                Console.WriteLine("Exit is found!");
            }
        }