Ejemplo n.º 1
0
        internal void Turn(World world)
        {
            if (SkipTurn || Dead)
            {
                SkipTurn = false;
                Instructions.RemoveAt(0);
                return;
            }

            if (Instructions.Any())
            {
                var instruction = Instructions.First();
                Instructions.Remove(instruction);
                if (!instruction.Execute(this, world))
                {
                    Dead = true;
                }

            }
            else
            {
                Trace.WriteLine(Name + " was stricken by melancholy!");
                Dead = true;
            }
        }
Ejemplo n.º 2
0
 public override void Execute(Dwarf d, World w)
 {
     int rocks = w.Cave[d.Position].Rocks;
     if (d.Rocks > rocks)
     {
         new Dump().Execute(d, w);
     }
 }
Ejemplo n.º 3
0
        public World Execute(string consoleInput)
        {
            World world = new World(dwarves, routines);

            world.Run(consoleInput);

            return world;
        }
Ejemplo n.º 4
0
        public World Execute(string consoleInput, ParallelType pType = ParallelType.Sequential)
        {
            World world = new World(dwarves, routines);

            world.Run(consoleInput, pType);

            return world;
        }
Ejemplo n.º 5
0
 public override bool Execute(Dwarf dwarf, World world)
 {
     dwarf.Position -= 1;
     if (dwarf.Position == 0)
     {
         Trace.WriteLine(dwarf.Name + " walked into magma and perished");
         return false;
     }
     return true;
 }
Ejemplo n.º 6
0
        public void MoveRightIntoWallTest()
        {
            Dictionary<string, List<Instruction>> routines = new Dictionary<string, List<Instruction>>();
            routines.Add("main", new List<Instruction>() { new MoveRight() });
            World w = new World(new List<Dwarf>() { new Dwarf("Urist", routines["main"]) }, routines);
            w.Dwarves[0].Position = 3;

            Assert.AreEqual(3, w.Dwarves[0].Position);
            w.Run("");
            Assert.AreEqual(3, w.Dwarves[0].Position);
        }
Ejemplo n.º 7
0
        public void DumpTest()
        {
            Dictionary<string, List<Instruction>> routines = new Dictionary<string, List<Instruction>>();
            routines.Add("main", new List<Instruction>() { new Dump() });
            World w = new World(new List<Dwarf>() { new Dwarf("Urist", routines["main"]) }, routines);
            w.Dwarves[0].Position = 3;
            w.Dwarves[0].Rocks = 1;

            w.Run("");
            Assert.AreEqual(0, w.Dwarves[0].Rocks);
            Assert.AreEqual(1, w.Cave[2].Rocks);
        }
Ejemplo n.º 8
0
 public override void Execute(Dwarf d, World w)
 {
     int rocks = w.Cave[d.Position].Rocks;
     if (rocks > 0)
     {
         List<Instruction> toInsert = w.Routines[rocks.ToString()];
         d.Instructions.InsertRange(0, toInsert);
     }
     else
     {
         w.Cave[d.Position].Workshop = null;
     }
 }
Ejemplo n.º 9
0
        public void InitialState()
        {
            Dictionary<string, List<Instruction>> routines = new Dictionary<string,List<Instruction>>();
            routines.Add("main", new List<Instruction>());
            World w = new World(new List<Dwarf>(){ new Dwarf("Urist", routines["main"])}, routines);

            Assert.AreEqual(0, w.Cave[0].Rocks);
            Assert.AreEqual(0, w.Cave[1].Rocks);
            Assert.AreEqual(0, w.Cave[2].Rocks);
            Assert.AreEqual(0, w.Cave[3].Rocks);
            Assert.AreEqual(-1, w.Cave[4].Rocks);
            Assert.AreEqual(1, w.Dwarves[0].Position);
        }
Ejemplo n.º 10
0
        public override bool Execute(Dwarf dwarf, World world)
        {
            if (dwarf.Rocks > 0)
            {
                int placeToDrop = dwarf.Position - 1;
                if (placeToDrop > 0)
                {
                    world.Cave[placeToDrop].Rocks += 1;
                }
                dwarf.Rocks -= 1;
            }

            return true;
        }
Ejemplo n.º 11
0
        public void MineTest()
        {
            Dictionary<string, List<Instruction>> routines = new Dictionary<string, List<Instruction>>();
            routines.Add("main", new List<Instruction>() { new Mine() });
            World w = new World(new List<Dwarf>() { new Dwarf("Urist", routines["main"]) }, routines);
            w.Dwarves[0].Position = 3;

            Assert.AreEqual(0, w.Dwarves[0].Rocks);
            Assert.AreEqual(-1, w.Cave[4].Rocks);
            Assert.AreEqual(5, w.Cave.Count);
            w.Run("");
            Assert.AreEqual(1, w.Dwarves[0].Rocks);
            Assert.AreEqual(63, w.Cave[4].Rocks);
            Assert.AreEqual(-1, w.Cave[5].Rocks);
            Assert.AreEqual(6, w.Cave.Count);
        }
Ejemplo n.º 12
0
 public override void Execute(Dwarf d, World w)
 {
     if (d.Rocks > 0)
     {
         w.WriteChar((char)d.Rocks);
         d.Rocks = 0;
     }
     else
     {
         d.Rocks = w.ReadChar();
         if (d.Rocks == 0)
         {
             Trace.WriteLine(d.Name + " was killed by the traders!");
             d.Dead = true;
         }
     }
 }
Ejemplo n.º 13
0
        public override bool Execute(Dwarf dwarf, World world)
        {
            int placeToMine = dwarf.Position + 1;

            if (world.Cave[placeToMine].Rocks != 0)
            {
                if (world.Cave[placeToMine].Rocks == -1)
                {
                    world.Cave[placeToMine].Rocks = 64;
                    world.Cave.Add(new Tile(){ Rocks= -1});
                }

                world.Cave[placeToMine].Rocks -= 1;
                dwarf.Rocks += 1;
            }

            return true;
        }
Ejemplo n.º 14
0
 public abstract bool Execute(Dwarf dwarf, World world);
Ejemplo n.º 15
0
 public override bool Execute(Dwarf dwarf, World world)
 {
     lock (world.Cave[dwarf.Position].workLock)
     {
         if (world.Cave[dwarf.Position].Workshop == null)
         {
             world.CreateWorkshop(dwarf);
         }
         else
         {
             world.Cave[dwarf.Position].Workshop.Execute(dwarf, world);
         }
     }
     return true;
 }
Ejemplo n.º 16
0
        public override bool Execute(Dwarf dwarf, World world)
        {
            var tile = world.Cave[dwarf.Position + 1];

            if (tile.Rocks != -1)
            {
                dwarf.Position += 1;
                return true;
            }

            Trace.WriteLine(dwarf.Name + " ran into a wall and perished");
            return false;
        }
Ejemplo n.º 17
0
        public World Debug(ParallelType pType = ParallelType.Sequential)
        {
            World world = new World(dwarves, routines);

            return world;
        }
Ejemplo n.º 18
0
 public abstract void Execute(Dwarf d, World w);