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; } }
public override void Execute(Dwarf d, World w) { int rocks = w.Cave[d.Position].Rocks; if (d.Rocks > rocks) { new Dump().Execute(d, w); } }
public World Execute(string consoleInput) { World world = new World(dwarves, routines); world.Run(consoleInput); return world; }
public World Execute(string consoleInput, ParallelType pType = ParallelType.Sequential) { World world = new World(dwarves, routines); world.Run(consoleInput, pType); return world; }
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; }
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); }
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); }
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; } }
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); }
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; }
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); }
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; } } }
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; }
public abstract bool Execute(Dwarf dwarf, World world);
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; }
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; }
public World Debug(ParallelType pType = ParallelType.Sequential) { World world = new World(dwarves, routines); return world; }
public abstract void Execute(Dwarf d, World w);