I have a local multiplayer game with an end of round screen that pops up after each round. I'm trying to figure out the logic to calculate the 1st, 2nd, 3rd place from a maximum of 4 players. I also want draw/tie conditions. It's possible for 2 or 3 players to get the same score. The score is just an int for each player. I've been struggling with this for a while... Any help appreciated, even if its just some pseudo code to point me in the right direction. Also, I'd like to avoid using Linq if possible, as I've heard it doesn't play nice with Unity. Thanks
Edit:
Below is what I've managed to come up with for determining the draw conditions. Doesn't seem to hold up in all cases though... Surely there's a simpler approach?
PlayerScore[] orderedScores = m_scores.OrderByDescending(ps => ps.score).Take(4).ToArray();
_1stPlacePlayers.Add(orderedScores[0].playerNumber);
if (orderedScores[0].score == orderedScores[1].score)
{
// 2 player draw 1st place
_1stPlacePlayers.Add(orderedScores[1].playerNumber);
if(orderedScores[0].score == orderedScores[2].score)
{
// 3 player draw 1st place
_1stPlacePlayers.Add(orderedScores[2].playerNumber);
if(orderedScores[0].score == orderedScores[3].score)
{
// 4 player draw 1st place
_1stPlacePlayers.Add(orderedScores[3].playerNumber);
}
}else if (orderedScores[1].score == orderedScores[2].score)
{
// 2 player draw 2nd place
_2ndPlacePlayers.Add(orderedScores[2].playerNumber);
if (orderedScores[1].score == orderedScores[3].score)
{
// 3 player draw 2nd place
_2ndPlacePlayers.Add(orderedScores[3].playerNumber);
}
}
else if (orderedScores[2].score == orderedScores[3].score)
{
// 2 player draw 3rd place
_3rdPlacePlayers.Add(orderedScores[3].playerNumber);
}
}
else if (orderedScores[1].score == orderedScores[2].score)
{
// 2 player draw 2nd place
_2ndPlacePlayers.Add(orderedScores[2].playerNumber);
if (orderedScores[1].score == orderedScores[3].score)
{
// 3 player draw 2nd place
_2ndPlacePlayers.Add(orderedScores[3].playerNumber);
}
}
else if (orderedScores[2].score == orderedScores[3].score)
{
// 2 player draw 3rd place
_3rdPlacePlayers.Add(orderedScores[3].playerNumber);
}