diff --git a/armeisen/Armeise.cs b/armeisen/Armeise.cs index 06d2c5a..a53092d 100644 --- a/armeisen/Armeise.cs +++ b/armeisen/Armeise.cs @@ -72,39 +72,54 @@ public class Armeise return colony; } - // public (Armeise, bool) Sex(List armeisen) - // { - // foreach (Armeise armeise in armeisen) - // { - // if ((armeise.posX - this.posX == 1 || armeise.posX - this.posX == -1) && (armeise.posY - this.posY == 1 || armeise.posY - this.posY == -1)) - // { - // return new Armeise(); + // public (Armeise, bool) Sex(List armeisen) + // { + // foreach (Armeise armeise in armeisen) + // { + // if ((armeise.posX - this.posX == 1 || armeise.posX - this.posX == -1) && (armeise.posY - this.posY == 1 || armeise.posY - this.posY == -1)) + // { + // return new Armeise(); - // } - // return false; - // } - // } + // } + // return false; + // } + // } + + public void MoveRandom() + { + Random rand = new Random(); + if (rand.Next(0, 5) == 0) + { + this.TurnLeft(); + } + else if (rand.Next(0, 5) == 1) + { + this.TurnRight(); + } + + this.Move(rand.Next(2, 7)); + } public void Move(int steps) + { + switch (directionFacing) { - switch (directionFacing) - { - case Directions.North: - posY -= steps; - break; - case Directions.East: - posX += steps; - break; - case Directions.South: - posY += steps; - break; - case Directions.West: - posX -= steps; - break; - default: - break; - } + case Directions.North: + posY -= steps; + break; + case Directions.East: + posX += steps; + break; + case Directions.South: + posY += steps; + break; + case Directions.West: + posX -= steps; + break; + default: + break; } + } // Moves the direction one up or down in the enum // Prevents ant from U-Turn and need modulo wrapping for north to west public void TurnRight() diff --git a/armeisen/Map.cs b/armeisen/Map.cs index 0df52f0..c9d4397 100644 --- a/armeisen/Map.cs +++ b/armeisen/Map.cs @@ -1,26 +1,27 @@ public class Map - { - public int sizeY = 10; - public int sizeX = 10; +{ + public int sizeY = 100; + public int sizeX = 100; - // Draws map line by line, replacing the V wit A if ant there - public void DrawMap(int armeiseX, int armeiseY) + // Draws map line by line, replacing the V wit A if ant there + public void DrawMap(Armeise[] armeisen) + { + for (int i = 0; i <= sizeY; i++) { - for (int i = 0; i <= sizeY; i++) + for (int j = 0; j <= sizeX; j++) { - for (int j = 0; j <= sizeX; j++) + foreach (Armeise armeise in armeisen) { - if (i == armeiseY && j == armeiseX) + if (i == armeise.posY && j == armeise.posX) { Console.Write('A'); - } - else - { - Console.Write('V'); + break; } } - Console.WriteLine(); + Console.Write('.'); } Console.WriteLine(); } - } \ No newline at end of file + Console.WriteLine(); + } +} \ No newline at end of file diff --git a/armeisen/Program.cs b/armeisen/Program.cs index 547421e..ad88699 100644 --- a/armeisen/Program.cs +++ b/armeisen/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; namespace meise { @@ -12,8 +13,17 @@ namespace meise List colony = new List(); colony = Armeise.PrintColonyStateForEachArmeiseInTheColonyExistingIfItHasPositionAndType(); - Armeise.ShowStats(colony); + while (true) + { + foreach (Armeise meise in colony) + { + meise.MoveRandom(); + } + mapInstance.DrawMap(colony.ToArray()); + + Thread.Sleep(1000); + } } } } \ No newline at end of file