public async Task SaveRace(MMgameNG game) { // /** using (var _db = new MMdb(_mmdb)) { foreach (var pl in game.GetPlayers()) { var dbpl = _db.MMdbRaces.Where(x => x.Name == pl.Name).FirstOrDefault(); if (dbpl != null) { foreach (var rat in pl.Rating[game.Lobby].Where(x => x.Db == false).OrderBy(o => o.Games).ToArray()) { MMdbRaceRating dbrat; dbrat = new MMdbRaceRating(); dbrat.EXP = rat.EXP; dbrat.Games = rat.Games; dbrat.Lobby = game.Lobby; dbrat.MU = rat.MU; dbrat.SIGMA = rat.SIGMA; dbrat.MMdbRaceId = dbpl.MMdbRaceId; dbrat.MMdbRace = dbpl; dbrat.Time = rat.Time; rat.Db = true; _db.MMdbRaceRatings.Add(dbrat); //dbpl.MMdbRaceRatings.Add(dbrat); } } } await _db.SaveChangesAsync(); } // **/ }
public async Task Save(MMgameNG game) { // /** foreach (var pl in game.GetPlayers()) { if (pl.Name.StartsWith("Random") || pl.Name.StartsWith("Dummy")) { continue; } var dbpl = _db.MMdbPlayers.Where(x => x.Name == pl.Name).FirstOrDefault(); if (dbpl != null) { var dbrat = _db.MMdbRatings.Where(x => x.MMdbPlayerId == dbpl.MMdbPlayerId && x.Lobby == game.Lobby).FirstOrDefault(); if (dbrat == null) { dbrat = new MMdbRating(); } var rat = pl.Rating[game.Lobby]; dbrat.EXP = rat.EXP; dbrat.Games = rat.Games; dbrat.Lobby = game.Lobby; dbrat.MU = rat.MU; dbrat.SIGMA = rat.SIGMA; dbrat.MMdbPlayerId = dbpl.MMdbPlayerId; dbrat.MMdbPlayer = dbpl; if (dbrat.MMdbRatingId == null) { dbpl.MMdbRatings.Add(dbrat); } //_db.MMdbRatings.Add(dbrat); else { _db.MMdbRatings.Update(dbrat); } } } await _db.SaveChangesAsync(); // **/ string output = Program.workdir + "/games/" + game.ID + "_report.json"; if (!File.Exists(output)) { using (FileStream fs = File.Create(output)) { await JsonSerializer.SerializeAsync(fs, game); } } }
public async Task Save(MMgameNG game) { // /** using (var _db = new MMdb(_mmdb)) { foreach (var pl in game.GetPlayers()) { if (pl.Name.StartsWith("Random") || pl.Name.StartsWith("Dummy")) { continue; } var dbpl = _db.MMdbPlayers.Where(x => x.Name == pl.Name).FirstOrDefault(); if (dbpl != null) { var dbrat = _db.MMdbRatings.Where(x => x.MMdbPlayerId == dbpl.MMdbPlayerId && x.Lobby == game.Lobby).FirstOrDefault(); if (dbrat == null) { dbrat = new MMdbRating(); } var rat = pl.Rating[game.Lobby]; dbrat.EXP = rat.EXP; dbrat.Games = rat.Games; dbrat.Lobby = game.Lobby; dbrat.MU = rat.MU; dbrat.SIGMA = rat.SIGMA; dbrat.MMdbPlayerId = dbpl.MMdbPlayerId; dbrat.MMdbPlayer = dbpl; if (dbrat.MMdbRatingId == null) { dbpl.MMdbRatings.Add(dbrat); } //_db.MMdbRatings.Add(dbrat); else { _db.MMdbRatings.Update(dbrat); } } } await _db.SaveChangesAsync(); } // **/ }
public async Task <int> CheckValid(dsreplay replay, MMgameNG game) { int valid = 0; return(await Task.Run(() => { HashSet <string> game_Names = game.GetPlayers().Select(s => s.Name).ToHashSet(); foreach (dsplayer dspl in replay.PLAYERS) { if (game_Names.Contains(dspl.NAME)) { valid++; int rep_team = dspl.TEAM + 1; List <MMplayerNG> game_team = new List <MMplayerNG>(); if (game.Team1.Select(s => s.Name == dspl.NAME).Count() > 0) { game_team = game.Team1; } else { game_team = game.Team2; } foreach (dsplayer tdspl in replay.PLAYERS.Where(x => x.TEAM == dspl.TEAM)) { if (tdspl.NAME == dspl.NAME) { continue; } if (game_Names.Contains(tdspl.NAME)) { if (game_team.Where(x => x.Name == tdspl.NAME).Count() > 0) { valid++; } } } } } return valid; })); }
public async Task Save(MMgameNG game) { // /** foreach (var pl in game.GetPlayers()) { if (pl.Name.StartsWith("Random") || pl.Name.StartsWith("Dummy")) { continue; } var dbpl = _startUp._db.MMdbPlayers.Where(x => x.Name == pl.Name).FirstOrDefault(); if (dbpl != null) { foreach (var rat in pl.Rating[game.Lobby].Where(x => x.Db == false).OrderBy(o => o.Time).ToArray()) { MMdbRating dbrat = new MMdbRating(); dbrat.EXP = rat.EXP; dbrat.Games = rat.Games; dbrat.Lobby = game.Lobby; dbrat.MU = rat.MU; dbrat.SIGMA = rat.SIGMA; dbrat.MMdbPlayerId = dbpl.MMdbPlayerId; dbrat.MMdbPlayer = dbpl; rat.Db = true; _startUp._db.MMdbRatings.Add(dbrat); } } } await _startUp._db.SaveChangesAsync(); // **/ string output = Program.workdir + "/games/" + game.ID + "_report.json"; if (!File.Exists(output)) { using (FileStream fs = File.Create(output)) { await JsonSerializer.SerializeAsync(fs, game); } } }
public async Task SaveRace(MMgameNG game) { // /** foreach (var pl in game.GetPlayers()) { var dbpl = _db.MMdbRaces.Where(x => x.Name == pl.Name).FirstOrDefault(); if (dbpl != null) { var dbrat = _db.MMdbRaceRatings.Where(x => x.MMdbRaceId == dbpl.MMdbRaceId && x.Lobby == game.Lobby).FirstOrDefault(); if (dbrat == null) { dbrat = new MMdbRaceRating(); } var rat = pl.Rating[game.Lobby]; dbrat.EXP = rat.EXP; dbrat.Games = rat.Games; dbrat.Lobby = game.Lobby; dbrat.MU = rat.MU; dbrat.SIGMA = rat.SIGMA; dbrat.MMdbRaceId = dbpl.MMdbRaceId; dbrat.MMdbRace = dbpl; if (dbrat.MMdbRaceRatingId == null) { dbpl.MMdbRaceRatings.Add(dbrat); } else { _db.MMdbRaceRatings.Update(dbrat); } } } await _db.SaveChangesAsync(); // **/ }
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); }