I know there's this huge argument out there are "truly random" numbers, but I have a feeling it's more than bad seeds making this work not so great.
public void RandomMovement()
{
int counter = -1;
List<int> moveX = new List<int>();
List<int> moveY = new List<int>();
if (CheckForMovement((mobX - 1), (mobY + 1), Map) && Map.TileMap[(mobX - 1), (mobY + 1)].walkType == this.walkType && CheckForTarget((mobX - 1), (mobY + 1), player.mobX, player.mobY) == false)
{
counter++;
moveX.Add(mobX - 1);
moveY.Add(mobY + 1);
}
if (CheckForMovement((mobX), (mobY + 1), Map) && Map.TileMap[(mobX), (mobY + 1)].walkType == this.walkType && CheckForTarget((mobX), (mobY + 1), player.mobX, player.mobY) == false)
{
counter++;
moveX.Add(mobX);
moveY.Add(mobY + 1);
}
if (CheckForMovement((mobX + 1), (mobY + 1), Map) && Map.TileMap[(mobX + 1), (mobY + 1)].walkType == this.walkType && CheckForTarget((mobX + 1), (mobY + 1), player.mobX, player.mobY) == false)
{
counter++;
moveX.Add(mobX + 1);
moveY.Add(mobY + 1);
}
if (CheckForMovement((mobX - 1), (mobY), Map) && Map.TileMap[(mobX - 1), (mobY)].walkType == this.walkType && CheckForTarget((mobX - 1), (mobY), player.mobX, player.mobY) == false)
{
counter++;
moveX.Add(mobX - 1);
moveY.Add(mobY);
}
if (CheckForMovement((mobX + 1), (mobY), Map) && Map.TileMap[(mobX + 1), (mobY)].walkType == this.walkType && CheckForTarget((mobX + 1), (mobY), player.mobX, player.mobY) == false)
{
counter++;
moveX.Add(mobX + 1);
moveY.Add(mobY);
}
if (CheckForMovement((mobX - 1), (mobY - 1), Map) && Map.TileMap[(mobX - 1), (mobY - 1)].walkType == this.walkType && CheckForTarget((mobX - 1), (mobY - 1), player.mobX, player.mobY) == false)
{
counter++;
moveX.Add(mobX - 1);
moveY.Add(mobY - 1);
}
if (CheckForMovement((mobX), (mobY - 1), Map) && Map.TileMap[(mobX), (mobY - 1)].walkType == this.walkType && CheckForTarget((mobX), (mobY - 1), player.mobX, player.mobY) == false)
{
counter++;
moveX.Add(mobX);
moveY.Add(mobY - 1);
}
if (CheckForMovement((mobX + 1), (mobY - 1), Map) && Map.TileMap[(mobX + 1), (mobY - 1)].walkType == this.walkType && CheckForTarget((mobX + 1), (mobY - 1), player.mobX, player.mobY))
{
counter++;
moveX.Add(mobX + 1);
moveY.Add(mobY - 1);
}
if (counter >= 0)
{
int i = Rand.Next(0, (counter + 1));
mobX = (byte)moveX[i];
mobY = (byte)moveY[i];
return;
}
else
return;
}
If it's not obvious what's going on, the actor checks all eight directions around itself to see if they're unoccupied and of the same 'walkType', puts all the coordinates in a pair of lists, then randomly generates a number between 0 and the number of valid directions to pick a pair of coordinates to set. And it works fine... Except the actors have a pronounced inclination to move south-west and almost never north-east. Since the directions are defined counting "up" as for a numpad arrangement, I imagine the problem is that C#'s default random number generator favors going low or something, but I really don't know. Anyone have any random number tips?
EDIT: Never mind, figured it out. Man, fuck that CheckForTarget nonsense, not only did I forget a False, but it's a stupid method anyway. I have better ideas now.