public IEnumerator GetWorldLeaderboardByTeam() { var idTeamnameRubbish = new Trictionary(); PlayFabAdminAPI.GetPlayersInSegment( new GetPlayersInSegmentRequest { SegmentId = "CAD8FCF4CF87AD8E" }, result => { foreach (var item in result.PlayerProfiles) { idTeamnameRubbish.Add(item.PlayerId, "-", 0); } }, error => Debug.LogError(error.GenerateErrorReport())); yield return(new WaitForSeconds(6)); foreach (var id in idTeamnameRubbish.Keys) { PlayFabClientAPI.GetUserData( new PlayFab.ClientModels.GetUserDataRequest { PlayFabId = id }, result => { idTeamnameRubbish[id] = new TeamNameRubbish { Value1 = result.Data["TeamName"].Value }; }, error => Debug.LogError(error.GenerateErrorReport())); } yield return(new WaitForSeconds(4f)); Dictionary <string, int> idRubbish = new Dictionary <string, int>(); foreach (var id in idTeamnameRubbish.Keys) { PlayFabClientAPI.GetLeaderboard( new GetLeaderboardRequest { StatisticName = "RubbishCollected" }, result => { foreach (var ldb in result.Leaderboard) { if (ldb.PlayFabId == id) { idTeamnameRubbish[id] = new TeamNameRubbish { Value1 = idTeamnameRubbish[id].Value1, Value2 = ldb.StatValue }; } } }, error => Debug.LogError(error.GenerateErrorReport())); } yield return(new WaitForSeconds(2f)); Dictionary <string, int> results = new Dictionary <string, int>(); foreach (var item in idTeamnameRubbish) { if (!results.ContainsKey(item.Value.Value1)) { results.Add(item.Value.Value1, item.Value.Value2); } else { results[item.Value.Value1] += item.Value.Value2; } } var orderResults = results.OrderByDescending(key => key.Value); for (int i = 0; i < orderResults.Count(); i++) { GameObject obj = Instantiate(listingPrefab, leaderboardPanel.transform); LeaderboardListing leaderboardListing = obj.GetComponent <LeaderboardListing>(); if (i % 2 == 0) { obj.GetComponent <Image>().color = leaderboardListing.evenColor; } else if (i % 2 != 0) { obj.GetComponent <Image>().color = leaderboardListing.oddColor; } leaderboardListing.positionText.text = (i + 1).ToString(); leaderboardListing.playerNameText.text = orderResults.ElementAt(i).Key; leaderboardListing.rubbishText.text = orderResults.ElementAt(i).Value.ToString(); } worldTeam = true; }
/// <summary> /// Berechnet die AllPairsShortestPath => Floyd-Warshall Algorithm /// </summary> /// <typeparam name="T">Der Datentyp.</typeparam> /// <param name="graph">Der Graph.</param> /// <returns>Die AllPairsShortestPath als string.</returns> public static string AllPairsShortestPath <T>(this Graph <T> graph) { if (!graph.IsDirected || !graph.IsWeighted) { throw new ArgumentException("Der AllPairsShortestPath Algorithmus kann nur auf gerichteten Graphen mit gewichteten Kanten durchgeführt werden."); } Trictionary <Vertex <T>, Vertex <T>, int> weights = new Trictionary <Vertex <T>, Vertex <T>, int>(); foreach (Edge <T> edge in graph.Edges) { if (edge.Weight == null) { throw new ArgumentException($"Die Kante {edge.ToString()} besitzt kein Gewicht"); } weights.Add(edge.From, edge.To, edge.Weight.Value); } foreach (Vertex <T> vertex in graph.Vertices) { weights.Add(vertex, vertex, 0); } foreach (Vertex <T> k in graph.Vertices) { foreach (Vertex <T> i in graph.Vertices) { foreach (Vertex <T> j in graph.Vertices) { if (!weights.HasValueForKeys(i, k) || !weights.HasValueForKeys(k, j)) { continue; } if (!weights.HasValueForKeys(i, j)) { weights.Add(i, j, weights.Get(i, k) + weights.Get(k, j)); } else { if ((weights.Get(i, j) > weights.Get(i, k) + weights.Get(k, j))) { weights.Set(i, j, weights.Get(i, k) + weights.Get(k, j)); } } } } } // Den String erstellen string stringMatrix = string.Empty; // Die maximale Länge einer Node-Repräsentation ermitteln. int maxVertexStringLength = graph.Vertices.Select(v => v.ToString()).Max(v => v.Length); if (maxVertexStringLength < weights.GetMaxStringLength()) { maxVertexStringLength = weights.GetMaxStringLength(); } // Die Titelleiste erstellen. stringMatrix += string.Concat(Enumerable.Repeat(" ", maxVertexStringLength)) + "||" + graph.Vertices .Select(v => v.ToString()) .Aggregate((a, b) => a.CenterStringWithinLength(maxVertexStringLength) + "|" + b.CenterStringWithinLength(maxVertexStringLength)) + Environment.NewLine; stringMatrix += string.Concat(Enumerable.Repeat("=", stringMatrix.Length)) + Environment.NewLine; // Die einzelnen Zeilen erstellen. foreach (Vertex <T> v in graph.Vertices) { stringMatrix += v.ToString().CenterStringWithinLength(maxVertexStringLength) + "|"; foreach (Vertex <T> w in graph.Vertices) { if (!weights.HasValueForKeys(v, w)) { stringMatrix += "|" + " ".CenterStringWithinLength(maxVertexStringLength); } else { stringMatrix += "|" + weights.Get(v, w).ToString().CenterStringWithinLength(maxVertexStringLength); } } stringMatrix += Environment.NewLine; } return(stringMatrix); }