Exemple #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;
            }
        }
Exemple #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);
     }
 }
Exemple #3
0
        public World Execute(string consoleInput)
        {
            World world = new World(dwarves, routines);

            world.Run(consoleInput);

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

            world.Run(consoleInput, pType);

            return world;
        }
Exemple #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;
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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;
     }
 }
Exemple #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);
        }
Exemple #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;
        }
Exemple #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);
        }
Exemple #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;
         }
     }
 }
Exemple #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;
        }
Exemple #14
0
 public abstract bool Execute(Dwarf dwarf, World world);
Exemple #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;
 }
Exemple #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;
        }
Exemple #17
0
        public World Debug(ParallelType pType = ParallelType.Sequential)
        {
            World world = new World(dwarves, routines);

            return world;
        }
Exemple #18
0
 public abstract void Execute(Dwarf d, World w);