这是一个您可以考虑的简单解决方案。
如果我正确理解了您的规则,您希望先按最低分对玩家进行排序,然后对于决胜局 1 名得分更高的玩家先行,然后如果仍然平局,则它只是 rng(掷骰子)。
您可以使用 c# IComparer 来做到这一点。它比听起来简单:
public class PlayerCompare : IComparer<Player>
{
public int Compare(Player x, Player y)
{
int unitComparison = x.Units.CompareTo(y.Units);//Note im comparing X to Y here so its ascending order.
if (unitComparison != 0)
{
//if they have not the same number of unit, return the higher one.
return unitComparison;
}
else
{
//if they have the same number of units, compare the scores
int scoreComparison = y.Score.CompareTo(x.Score);//Note im comparing Y to X here so its descending order.
if (scoreComparison != 0)
{
//If they don't have the same number of units, return the lower one.
return scoreComparison;
}
else
{
//They have the same number of units and score, roll a dice.
if (UnityEngine.Random.value > 0.5f)//this is a straight up 50/50
{
return 1;
}
else
{
return -1;
}
}
}
}
}
public class Player
{
public int Units;
public int Score;
public Player(int units, int score)
{
Units = units;
Score = score;
}
}
//This is an example list of players (6) with assorted scores/units
public List<Player> playerList = new List<Player>() {
new Player(1,10), new Player(8, 2),
new Player(2, 20), new Player(4, 0),
new Player(1, 10), new Player(8, 20)
};
//This is the sorting
private void Sort()
{
playerList.Sort(new PlayerCompare());
}
现在您只需要更新分数/单位并在回合结束时调用 Sort()。我为示例制作了一个虚拟玩家类,显然使用你的。