This commit is contained in:
2025-06-30 08:48:08 +02:00
parent e0b5a14a55
commit d3ed2d922e
3 changed files with 69 additions and 43 deletions

View File

@ -72,39 +72,54 @@ public class Armeise
return colony; return colony;
} }
// public (Armeise, bool) Sex(List<Armeise> armeisen) // public (Armeise, bool) Sex(List<Armeise> armeisen)
// { // {
// foreach (Armeise armeise in 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)) // 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 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) public void Move(int steps)
{
switch (directionFacing)
{ {
switch (directionFacing) case Directions.North:
{ posY -= steps;
case Directions.North: break;
posY -= steps; case Directions.East:
break; posX += steps;
case Directions.East: break;
posX += steps; case Directions.South:
break; posY += steps;
case Directions.South: break;
posY += steps; case Directions.West:
break; posX -= steps;
case Directions.West: break;
posX -= steps; default:
break; break;
default:
break;
}
} }
}
// Moves the direction one up or down in the enum // Moves the direction one up or down in the enum
// Prevents ant from U-Turn and need modulo wrapping for north to west // Prevents ant from U-Turn and need modulo wrapping for north to west
public void TurnRight() public void TurnRight()

View File

@ -1,26 +1,27 @@
public class Map public class Map
{ {
public int sizeY = 10; public int sizeY = 100;
public int sizeX = 10; public int sizeX = 100;
// Draws map line by line, replacing the V wit A if ant there // Draws map line by line, replacing the V wit A if ant there
public void DrawMap(int armeiseX, int armeiseY) 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'); Console.Write('A');
} break;
else
{
Console.Write('V');
} }
} }
Console.WriteLine(); Console.Write('.');
} }
Console.WriteLine(); Console.WriteLine();
} }
} Console.WriteLine();
}
}

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Threading;
namespace meise namespace meise
{ {
@ -12,8 +13,17 @@ namespace meise
List<Armeise> colony = new List<Armeise>(); List<Armeise> colony = new List<Armeise>();
colony = Armeise.PrintColonyStateForEachArmeiseInTheColonyExistingIfItHasPositionAndType(); colony = Armeise.PrintColonyStateForEachArmeiseInTheColonyExistingIfItHasPositionAndType();
Armeise.ShowStats(colony);
while (true)
{
foreach (Armeise meise in colony)
{
meise.MoveRandom();
}
mapInstance.DrawMap(colony.ToArray());
Thread.Sleep(1000);
}
} }
} }
} }