I have a bool[,] Array for keeping track of Nations that are either at war(true) or neutral(false).
The problem Im having is that when going over the matrix, to display al wars in UI elements, it will actually shwo duplicates of all wars, this is ofcourse obvious because: Nation 1 is at war with Nation 2. Nation 2 is at war with Nation 1. So it will ofcourse display both, but I just want one.
So how do I remove/ignore the duplicates?
Heres my code for generating the matrix:
It wont let me post images or code.
public static void Init(Nation[] nationsArray)
{
nations = new List<Nation>(nationsArray);
int numNations = nations.Count;
enemyMatrix = new bool[numNations - 1, numNations - 1];
for (int i = 0; i < numNations - 1; i++)
nations[i].ID = i;
}
public static bool AreNationsEnemies(Nation nation1, Nation nation2)
{
return enemyMatrix[nation1.ID, nation2.ID];
}
public static void SetAsEnemies(Nation nation1, Nation nation2)
{
enemyMatrix[nation1.ID, nation2.ID] = true;
enemyMatrix[nation2.ID, nation1.ID] = true;
numberOfActiveWars++;
}
public static void SetAsNeutral(Nation nation1, Nation nation2)
{
enemyMatrix[nation1.ID, nation2.ID] = false;
enemyMatrix[nation2.ID, nation1.ID] = false;
numberOfActiveWars--;
}
}
So thats the problem, it displays the wars doubly so!
I appreciate any help, thanks in advance!
List<Nation> atWarWith;
I scrapped that and instead now have a custom class called War.cs, which is created everytime a war is started using @Olivier's answer below. This seems to be the cleanest solution. So then I have a List<War> that is filled up using the answer below, and I just iterate over that List of custom classes(War) to fill in the UI elements. \$\endgroup\$if (enemyMatrix[x, y])
{
War war = new War(nations[x], nations[y]);
wars.Add(war);
\$\endgroup\$