armeisen
This commit is contained in:
@ -72,39 +72,54 @@ public class Armeise
|
||||
return colony;
|
||||
}
|
||||
|
||||
// public (Armeise, bool) Sex(List<Armeise> 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<Armeise> 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()
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace meise
|
||||
{
|
||||
@ -12,8 +13,17 @@ namespace meise
|
||||
|
||||
List<Armeise> colony = new List<Armeise>();
|
||||
colony = Armeise.PrintColonyStateForEachArmeiseInTheColonyExistingIfItHasPositionAndType();
|
||||
Armeise.ShowStats(colony);
|
||||
|
||||
while (true)
|
||||
{
|
||||
foreach (Armeise meise in colony)
|
||||
{
|
||||
meise.MoveRandom();
|
||||
}
|
||||
mapInstance.DrawMap(colony.ToArray());
|
||||
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user