public async Task <MMplayerNG> LetmePlay(MMplayerNG sepl) { if (!_startUp.MMplayers.ContainsKey(sepl.Name)) { _startUp.MMplayers.TryAdd(sepl.Name, sepl); await _startUp.Save(); } else { MMplayerNG _sepl = sepl.ShallowCopy(); ExitQ(sepl.Name); _startUp.MMplayers[sepl.Name].Mode = _sepl.Mode; _startUp.MMplayers[sepl.Name].Mode2 = _sepl.Mode2; _startUp.MMplayers[sepl.Name].Server = _sepl.Server; _startUp.MMplayers[sepl.Name].Random = _sepl.Random; _startUp.MMplayers[sepl.Name].Ladder = _sepl.Ladder; _startUp.MMplayers[sepl.Name].Ticks = _sepl.Ticks; } string lobby = _startUp.MMplayers[sepl.Name].Mode + _startUp.MMplayers[sepl.Name].Mode2 + _startUp.MMplayers[sepl.Name].Ladder; lock (Lobbies[lobby]) { Lobbies[lobby].Add(_startUp.MMplayers[sepl.Name]); } return(_startUp.MMplayers[sepl.Name]); }
public MMdbPlayer(MMplayerNG pl) { Name = pl.Name; AuthName = pl.AuthName; if (pl.DBId > 0) { MMdbPlayerId = pl.DBId; } Mode = pl.Mode; Server = pl.Server; Mode2 = pl.Mode2; Ladder = pl.Ladder; Credential = pl.Credential; Deleted = pl.Deleted; MMDeleted = pl.MMDeleted; /** * foreach (var lobby in pl.Rating.Keys) * { * MMdbRating dbrat = new MMdbRating(); * var rat = pl.Rating[lobby]; * dbrat.EXP = rat.EXP; * dbrat.Games = rat.Games; * dbrat.Lobby = lobby; * dbrat.MU = rat.MU; * dbrat.SIGMA = rat.SIGMA; * * MMdbRatings = new List<MMdbRating>(); * MMdbRatings.Add(dbrat); * } **/ }
public static (MMgameNG, MMgameNG) RateGame(dsreplay replay, StartUp _mm, string lobby) { var team1 = new Team(); var team2 = new Team(); var rteam1 = new Team(); var rteam2 = new Team(); //string lobby = _mm.Games.Where(x => x.ID == replay.ID).FirstOrDefault().Lobby; if (lobby == null || lobby == "") { return(null, null); } int i = 0; foreach (var pl in replay.PLAYERS) { MMplayerNG mpl = new MMplayerNG(); if (_mm.MMplayers.ContainsKey(pl.NAME)) { mpl = _mm.MMplayers[pl.NAME]; } else { mpl.Name = "Dummy" + i; } MMplayerNG rpl = _mm.MMraces[pl.RACE]; MMPlRating plrat = mpl.Rating[lobby].LastOrDefault(); if (plrat == null) { plrat = new MMPlRating(); mpl.Rating[lobby].Add(plrat); } MMPlRating cmdrrat = rpl.Rating[lobby].LastOrDefault(); if (cmdrrat == null) { cmdrrat = new MMPlRating(); rpl.Rating[lobby].Add(cmdrrat); } if (pl.TEAM == replay.WINNER) { team1.AddPlayer(new Player(mpl.Name), new Rating(plrat.MU, plrat.SIGMA)); rteam1.AddPlayer(new Player(pl.RACE), new Rating(cmdrrat.MU, cmdrrat.SIGMA)); } else { team2.AddPlayer(new Player(mpl.Name), new Rating(plrat.MU, plrat.SIGMA)); rteam2.AddPlayer(new Player(pl.RACE), new Rating(cmdrrat.MU, cmdrrat.SIGMA)); } i++; } return(RateGame(team1, team2, lobby, _mm), RateGame(rteam1, rteam2, lobby, _mm, true)); }
public async Task Save() { // /** List <MMdbPlayer> temp = new List <MMdbPlayer>(); using (var db = new MMdb(_mmdb)) { foreach (var conf in MMplayers.Values.Where(x => x.DBId == 0)) { MMdbPlayer dbpl = new MMdbPlayer(conf); db.MMdbPlayers.Add(dbpl); temp.Add(dbpl); } foreach (var conf in MMplayers.Values.Where(x => x.DBupdate == true)) { MMdbPlayer pl = new MMdbPlayer(conf); db.MMdbPlayers.Update(pl); } List <MMdbRace> race_temp = new List <MMdbRace>(); /** * foreach (var ent in MMraces.Values) * { * MMdbRace cmdr = new MMdbRace(ent); * db.MMdbRaces.Add(cmdr); * race_temp.Add(cmdr); * } **/ await db.SaveChangesAsync(); foreach (var ent in temp) { MMplayerNG pl = MMplayers.Values.Where(x => x.Name == ent.Name).FirstOrDefault(); pl.DBId = ent.MMdbPlayerId; } foreach (var ent in race_temp) { MMplayerNG pl = MMraces.Values.Where(x => x.Name == ent.Name).FirstOrDefault(); pl.DBId = ent.MMdbRaceId; } } // **/ }
public static MMgameNG RateGame(Team team1, Team team2, string lobby, StartUp _mm, bool cmdr = false) { var gameInfo = GameInfo.DefaultGameInfo; var teams = Teams.Concat(team1, team2); var newRatingsWinLoseExpected = TrueSkillCalculator.CalculateNewRatings(gameInfo, teams, 1, 2); MMgameNG game = new MMgameNG(); game.Lobby = lobby; int i = 0; foreach (var pl in team1.AsDictionary().Keys) { var res = newRatingsWinLoseExpected[pl]; string name = pl.Id.ToString(); MMplayerNG mpl = new MMplayerNG(); MMPlRating plrat = new MMPlRating(); if (_mm.MMplayers.ContainsKey(name)) { mpl = _mm.MMplayers[name]; plrat = mpl.Rating[lobby].LastOrDefault().ShallowCopy(); plrat.Db = false; } else { mpl.Name = "Dummy" + i; } if (cmdr == true) { mpl = _mm.MMraces[name]; plrat = mpl.Rating[lobby].LastOrDefault().ShallowCopy(); plrat.Db = false; } double temp = plrat.EXP; plrat.EXP = res.ConservativeRating; mpl.ExpChange = plrat.EXP - temp; plrat.MU = res.Mean; plrat.SIGMA = res.StandardDeviation; plrat.Games++; plrat.Time = DateTime.UtcNow; mpl.Rating[lobby].Add(plrat); game.Team1.Add(mpl); i++; } foreach (var pl in team2.AsDictionary().Keys) { var res = newRatingsWinLoseExpected[pl]; string name = pl.Id.ToString(); MMplayerNG mpl = new MMplayerNG(); MMPlRating plrat = new MMPlRating(); if (_mm.MMplayers.ContainsKey(name)) { mpl = _mm.MMplayers[name]; plrat = mpl.Rating[lobby].LastOrDefault().ShallowCopy(); plrat.Db = false; } else { mpl.Name = "Dummy" + i; } if (cmdr == true) { mpl = _mm.MMraces[name]; plrat = mpl.Rating[lobby].LastOrDefault().ShallowCopy(); plrat.Db = false; } double temp = plrat.EXP; plrat.EXP = res.ConservativeRating; mpl.ExpChange = plrat.EXP - temp; plrat.MU = res.Mean; plrat.SIGMA = res.StandardDeviation; plrat.Games++; plrat.Time = DateTime.UtcNow; mpl.Rating[lobby].Add(plrat); game.Team2.Add(mpl); i++; } return(game); }
public static (MMgameNG, MMgameNG) RateGame(string result, string lobby, StartUp _mm) { List <RESplayer> pllist = new List <RESplayer>(); var teams = result.Split(new string[] { " vs " }, StringSplitOptions.None); if (teams.Length == 2) { int t = 0; int p = 0; foreach (var team in teams) { Match m = rx_pl.Match(team); while (m.Success) { RESplayer plres = new RESplayer(); plres.Team = t; plres.Pos = p; var plent = m.Groups[1].ToString().Split(',', StringSplitOptions.None); int i = 0; foreach (var ent in plent) { string myent = ent.Trim(); myent = myent.Replace(" ", string.Empty); myent = myent.Replace("(", string.Empty); myent = myent.Replace(")", string.Empty); if (i == 0) { plres.Name = myent; } if (i == 1) { plres.Race = myent; } if (i == 2) { plres.Kills = int.Parse(myent); } i++; } pllist.Add(plres); m = rx_pl.Match(m.Groups[2].ToString()); p++; } t++; } } var team1 = new Team(); var team2 = new Team(); var rteam1 = new Team(); var rteam2 = new Team(); int j = 0; foreach (var pl in pllist) { MMplayerNG mpl = new MMplayerNG(); if (_mm.MMplayers.ContainsKey(pl.Name)) { mpl = _mm.MMplayers[pl.Name]; } else { if (pl.Name.StartsWith("Random") || pl.Name.StartsWith("Dummy")) { mpl.Name = "Dummy" + j; } else { mpl.Name = pl.Name; _mm.MMplayers.TryAdd(mpl.Name, mpl); } } MMplayerNG rpl = _mm.MMraces[pl.Race]; MMPlRating plrat = mpl.Rating[lobby].LastOrDefault(); if (plrat == null) { plrat = new MMPlRating(); mpl.Rating[lobby].Add(plrat); } MMPlRating cmdrrat = rpl.Rating[lobby].LastOrDefault(); if (cmdrrat == null) { cmdrrat = new MMPlRating(); rpl.Rating[lobby].Add(cmdrrat); } if (pl.Team == 0) { team1.AddPlayer(new Player(mpl.Name), new Rating(plrat.MU, plrat.SIGMA)); rteam1.AddPlayer(new Player(pl.Race), new Rating(cmdrrat.MU, cmdrrat.SIGMA)); } else { team2.AddPlayer(new Player(mpl.Name), new Rating(plrat.MU, plrat.SIGMA)); rteam2.AddPlayer(new Player(pl.Race), new Rating(cmdrrat.MU, cmdrrat.SIGMA)); } j++; } return(RateGame(team1, team2, lobby, _mm), RateGame(rteam1, rteam2, lobby, _mm, true)); }
async Task NotifyPlayer(MMplayerNG pl, string changed) { lock (pl) pl.Notify = true; }
async Task <MMgameNG> CheckLobby(ObservableCollection <MMplayerNG> lobby, int lobbysize) { MMgameNG game = new MMgameNG(); var rng = lobby.Where(x => x.Random == true); int minticks = lobby.OrderBy(o => o.Ticks).First().Ticks; if (rng.Count() >= 2) { if (lobby.Count < lobbysize && minticks > Minticks) { int i = 0; while (lobby.Count < lobbysize) { i++; MMplayerNG mm = new MMplayerNG(); mm.Name = "Random" + i; mm.Ticks = Minticks * 3 + 1; mm.Accepted = true; lobby.Add(mm); } } } if (lobby.Count >= lobbysize) { if (minticks > Minticks || lobby.Count > lobbysize) { _logger.LogInformation("Generating Matchup .. " + minticks); game = await MMrating.GenMatch(lobby.ToList(), lobbysize); if (game != null) { Interlocked.Increment(ref MMID); game.ID = MMID; var temp_pl = game.GetPlayers().FirstOrDefault(); game.Lobby = temp_pl.Mode + temp_pl.Mode2 + temp_pl.Ladder; _logger.LogInformation("Game found: {0} ({1}) ", MMID, lobby.Count); Dictionary <string, int> Server = new Dictionary <string, int>(); foreach (var pl in game.GetPlayers()) { Match m = rx_rng.Match(pl.Name); if (m.Success) { continue; } lock (_startUp.MMplayers[pl.Name]) { _startUp.MMplayers[pl.Name].Game = game; } lock (lobby) { lobby.Remove(_startUp.MMplayers[pl.Name]); if (lobby.Count == 0) { int p = 0; foreach (var ent in Lobbies.Values) { if (ent != null && ent.Count > 0) { p++; } } if (p == 0) { LobbyCheck = false; } } } if (!Server.ContainsKey(_startUp.MMplayers[pl.Name].Server)) { Server.Add(_startUp.MMplayers[pl.Name].Server, 1); } else { Server[_startUp.MMplayers[pl.Name].Server]++; } } game.Server = Server.OrderByDescending(o => o.Value).First().Key; game.State.GameID = game.ID; game.State.PropertyChanged += GameChanged; lock (Games) { Games[game.ID] = game; } } } } return(game); }