Sunday, November 13, 2022
HomeGame Developmentunity - Eradicating duplicates/ignoring them from a 2 dimensional Array

unity – Eradicating duplicates/ignoring them from a 2 dimensional Array


enter image description here
I’ve a bool[,] Array for conserving monitor of Nations which can be both at battle(true) or impartial(false).

The issue Im having is that when going over the matrix, to show al wars in UI components, it can really shwo duplicates of all wars, that is ofcourse apparent as a result of:
Nation 1 is at battle with Nation 2.
Nation 2 is at battle with Nation 1.
So it can ofcourse show each, however I simply need one.

So how do I take away/ignore the duplicates?

Heres my code for producing the matrix:

It wont let me submit photos or code.


    public static void Init(Nation[] nationsArray)
    {
        nations = new Listing<Nation>(nationsArray);
        int numNations = nations.Depend;

        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 issue, it shows the wars doubly so!

I admire any assist, thanks upfront!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments