public static bool AddUnoWins(string username, int placement, string caller) { username = UtilSaveFile.MakeUsernameCompatible(username); if (placement <= 0) { return(false); } if (placement >= 4) { placement = 4; } switch (placement) { case 1: UtilSaveFile.AddBalanceByUsername(username, "1", "Unowins", "Gold bal change by " + caller, 4); break; case 2: UtilSaveFile.AddBalanceByUsername(username, "1", "Unosilvers", "Silver bal change by " + caller, 4); break; case 3: UtilSaveFile.AddBalanceByUsername(username, "1", "Unobronzes", "Bronze bal change by " + caller, 4); break; case 4: UtilSaveFile.AddBalanceByUsername(username, "1", "Unowhiteflags", "Standard win change by " + caller, 4); break; default: break; } return(true); }
public static List <string> LogCAHGame(List <string> args, string caller) { byte lengthOfCallCommand = 4; //log (with space following) args[0] = args[0].TrimStart(); args[0] = args[0].Substring(lengthOfCallCommand, args[0].Length - lengthOfCallCommand); //EXCLUDED USERS List <string> excludedUsers = new List <string>(); if (Regex.Matches(args[0], @"[a-zA-Z]").Count >= 1) { if (args[0].Contains(",")) //several usernames { excludedUsers = args[0].Split(',').ToList <string>(); } else //one username { excludedUsers.Add(args[0]); } } for (int i = 0; i < excludedUsers.Count; i++) { excludedUsers[i] = UtilSaveFile.MakeUsernameCompatible(excludedUsers[i]); Console.WriteLine(excludedUsers[i]); } //COLLECT USERS int noOfUsersPlayed = -1; List <string> includedUsers = new List <string>(); foreach (string line in args) { if (line.Contains(":")) //implies is a line with a scored user { includedUsers.Add(line); } } throw new NotImplementedException(); }
/// <summary> /// Pass in a username, returns a List(string), elem 0: player score, elem 1: ranking, elem 2: number of users total /// </summary> public static List <string> GetIndvidiualLeaderboardStats(string user) { List <User> unsortedLeaderboard = GetUsersUnoList(); var sortedList = unsortedLeaderboard.OrderByDescending(f => f.unoPointsInt); user = UtilSaveFile.MakeUsernameCompatible(user); int i = 1; int placeTemp = -1; int playerScore = -1; foreach (User person in sortedList) { if (person.name == user) { placeTemp = i; playerScore = person.unoPointsInt; } i++; } if (playerScore == -1) { return(new List <string>()); } string placement = placeTemp.ToString(); string noOfUsers = sortedList.Count().ToString(); List <string> tempList = new List <string>(); tempList.Add(playerScore.ToString()); if (playerScore == 0) { tempList.Add(noOfUsers); } else { tempList.Add(placement); } tempList.Add(noOfUsers); return(tempList); }
/// <summary> /// Updates everyone's Uno points based on the server's algorithm for Uno Points. Returns List(string) of all updates performed / not performed. /// </summary> public static List <string> LogUnoGame(string args, string caller) { byte lengthOfCallCommand = 4; //log (with space following) args = args.TrimStart(); args = args.Substring(lengthOfCallCommand, args.Length - lengthOfCallCommand); /*attempt to retrieve "number of players" who participated. assumes 99 is max possible. * if no int exists, will assume equal to number of players who are listed.*/ sbyte numberOfCountablePlayersStated = 0; if (Int32.TryParse(args.Substring(0, 1), out int ignore2)) { numberOfCountablePlayersStated = (sbyte)Int32.Parse(args.Substring(0, 1)); bool tempbool = Int32.TryParse(args.Substring(0, 2), out int ignore); if (tempbool) { sbyte tempval = (sbyte)Int32.Parse(args.Substring(0, 2)); if (tempval > 9 && tempval < 100) //10+ players { numberOfCountablePlayersStated = tempval; } } } //receive placement stats sbyte numberOfCountablePlayersListed = 0; List <string> orderedWinners = new List <string>(); string winnerNo = "1"; string currentWinner; //put winners inside a string list while (args.Contains(winnerNo + ".")) { numberOfCountablePlayersListed++; string followingVal = (numberOfCountablePlayersListed + 1).ToString(); if (!args.Contains(followingVal + ".")) //last countable player { currentWinner = args.Substring(args.IndexOf(winnerNo + ".")); currentWinner = currentWinner.Replace(winnerNo + ".", ""); currentWinner = UtilSaveFile.MakeUsernameCompatible(currentWinner); orderedWinners.Add(currentWinner); break; } if (args.IndexOf(winnerNo + ".") > args.IndexOf(followingVal + ".")) { Console.WriteLine("At iteration " + numberOfCountablePlayersListed + ", " + winnerNo + " came before " + followingVal); return(new List <string>()); } string temp; currentWinner = args.Substring(args.IndexOf(winnerNo + "."), args.IndexOf(followingVal + ".") - args.IndexOf(winnerNo + ".")); currentWinner = currentWinner.Replace(winnerNo + ".", ""); currentWinner = UtilSaveFile.MakeUsernameCompatible(currentWinner); orderedWinners.Add(currentWinner); int tempInt = Int32.Parse(winnerNo); tempInt++; winnerNo = tempInt.ToString(); } if (numberOfCountablePlayersStated == 0) { numberOfCountablePlayersStated = numberOfCountablePlayersListed; } else if (numberOfCountablePlayersStated < numberOfCountablePlayersListed) { Console.WriteLine("More players were listed than the supposed number stated."); return(new List <string>()); } if (numberOfCountablePlayersStated < 2 || orderedWinners.Count() < 2) //error checking { return(new List <string>()); } //determine point attributes (1's are assumed to be given out to all remainder players) List <string> awards = new List <string>(); awards.Add("5"); if (numberOfCountablePlayersStated >= 3) { awards.Add("10"); } //every 1-2 extra players gives a new first place award of +5 byte newestElem = 10; for (int temp = numberOfCountablePlayersStated - 3; temp > 0; temp -= 2) { awards.Add((newestElem + 5).ToString()); newestElem += 5; } //Add balances byte currWinner = 0; byte maxWinner = (byte)(orderedWinners.Count()); sbyte currAward = (sbyte)(awards.Count() - 1); sbyte maxAward = -1; //when one ooint distrib should come in string returnedval = ""; List <string> result = new List <string>(); while (currWinner < maxWinner) { returnedval = UtilSaveFile.AddBalanceByUsername(orderedWinners[currWinner], awards[currAward], "Unopoints", caller, 4); if (returnedval != "-1") { result.Add(orderedWinners[currWinner] + " has earned " + awards[currAward] + " points," + " bringing their total to " + returnedval + "!"); AddUnoWins(orderedWinners[currWinner], currWinner + 1, caller); } else { result.Add(orderedWinners[currWinner] + " does not have an account, and their " + awards[currAward] + " has not been added. Try deleting symbols that used to be emojis!"); } currWinner++; currAward--; if (currAward == maxAward) { while (currWinner < maxWinner) { returnedval = UtilSaveFile.AddBalanceByUsername(orderedWinners[currWinner], "1", "Unopoints", caller, 4); if (returnedval != "-1") { result.Add(orderedWinners[currWinner] + " has earned 1 point," + " bringing their total to " + returnedval + "!"); AddUnoWins(orderedWinners[currWinner], currWinner + 1, caller); } else { result.Add(orderedWinners[currWinner] + " does not have an account, and their 1 point" + " has not been added."); } currWinner++; } } } return(result); }