-1
我需要幫助。 我創建迷你遊戲插件與地圖投票,我不知道如何做到這一點。Bukkit地圖投票
HashMap<World, Integer> votes = new HashMap<World, Integer>();
比方說,選票已關閉,服務器正在選擇地圖。哪一個? 當2張地圖有相同的最大數量時什麼。的選票?
感謝您的幫助,eNcoo。
我需要幫助。 我創建迷你遊戲插件與地圖投票,我不知道如何做到這一點。Bukkit地圖投票
HashMap<World, Integer> votes = new HashMap<World, Integer>();
比方說,選票已關閉,服務器正在選擇地圖。哪一個? 當2張地圖有相同的最大數量時什麼。的選票?
感謝您的幫助,eNcoo。
搶七投票
有一票,但限制的選擇,以世界頂級等於高分。
隨機決勝
使用一個隨機數發生器,以打破平局,如在以下示出:
Map<World, Integer> votes = new HashMap<>();
...
// Get list of entries and sort descending by value
List<Entry<World, Integer>> entries = new ArrayList<>(votes.entrySet());
Collections.sort(entries, (e1,e2) -> -e1.getValue().compareTo(e2.getValue()));
// Collect top scoring worlds
List<World> topWorlds = new ArrayList<>();
int highScore = entries.get(0).getValue();
for (Entry<World,Integer> e : entries)
if (e.getValue() == highScore)
topWorlds.add(e.getKey());
else
break;
// Pick one at random
World pick = topWorlds.get(new Random().nextInt(topWorlds.size()));
最老或最新投票
跟蹤每個世界最古老的或最新的投票時間戳也可用於打破關係。例如,跟蹤最古老的投票將優先選擇第一次世界投票(在關係集合中),而最新的投票則優先選擇最後投票的世界。我不確定這是否實用,只是將其作爲練習。
我會說,一旦投票結束,您的整數降序排列。然後只需選擇[0](Index Zero)。這將(如果我是正確的)有一個隨機的機會,如果兩個或更多具有相同的計數。 –