public static List <Matchup> ConvertToMatchup(this List <string> lines) { List <Matchup> output = new List <Matchup>(); foreach (string line in lines) { if (line != "") { //Id,id|id,winnerId,Round string[] cols = line.Split(','); Matchup p = new Matchup(); p.Id = int.Parse(cols[0]); p.entriesString = cols[1]; p.winnerId = int.Parse(cols[2]); p.Round = int.Parse(cols[3]); string[] entries = p.entriesString.Split('|'); foreach (string entry in entries) { p.Entries.Add(MatchupEntriesFile.FullFilePath().LoadFile().GetOneMatchupEntry(int.Parse(entry))); } if (p.winnerId != 0) { p.winner = TeamsFile.FullFilePath().LoadFile().GetOneTeam(p.winnerId); } output.Add(p); } } return(output); }
public static List <Matchup> ConvertToMatchupModels(this List <string> lines) { // id=0 // Entries=1(pipe delimited by id) // Winner = 2 // matchupRound =3 List <Matchup> output = new List <Matchup>(); foreach (string line in lines) { string[] cols = line.Split(','); Matchup p = new Matchup(); p.Id = int.Parse(cols[0]); p.Entries = ConvertStringToMatchupEntryModel(cols[1]); if (cols[2].Length == 0) { p.Winner = null; } else { p.Winner = LookupTeamById(int.Parse(cols[2])); } p.MatchupRound = int.Parse(cols[3]); output.Add(p); } return(output); }
public static void AddDataFromMatchupDto(MatchupDto matchupDto) { var gameKey = "399"; var season = _repo.LeagueRepo.Find(includeProperties: "Seasons.ManagerSeasons.Rosters,Seasons.Matchups") .FirstOrDefault()? .Seasons .Where(s => s.SeasonId == $"{gameKey}.l.{matchupDto.YahooLeagueId}") .FirstOrDefault() ?? _repo.LeagueRepo.AddNewSeason(short.Parse(matchupDto.SeasonYear), matchupDto.YahooLeagueId, matchupDto.LeagueName); var managerSeasonLeft = _repo.ManagerRepo.GetManagersSeasons(matchupDto.LeftTeam.YahooManagerId, "MatchupRosters") .Where(team => team.Year == short.Parse(matchupDto.SeasonYear) && team.SeasonId == season.SeasonId) .FirstOrDefault() ?? CreateManagerSeasonFromTeamDto(matchupDto.LeftTeam, ref season); var managerSeasonRight = _repo.ManagerRepo.GetManagersSeasons(matchupDto.RightTeam.YahooManagerId, "MatchupRosters") .Where(team => team.Year == short.Parse(matchupDto.SeasonYear) && team.SeasonId == season.SeasonId) .FirstOrDefault() ?? CreateManagerSeasonFromTeamDto(matchupDto.LeftTeam, ref season); var matchup = new Matchup(byte.Parse(matchupDto.Week)); AddPlayersFromTeamDto(matchupDto.LeftTeam, matchup.Roster1); AddPlayersFromTeamDto(matchupDto.RightTeam, matchup.Roster2); managerSeasonLeft.Rosters.Add(matchup.Roster1); managerSeasonRight.Rosters.Add(matchup.Roster2); season.Matchups.Add(matchup); _repo.Save(); }
public async Task SearchForPlayerAndOpponent_2v2_SameTeam() { var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); var matchFinishedEvent1 = TestDtoHelper.CreateFake2v2AtEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.season = 1; matchFinishedEvent1.match.players[0].battleTag = "peter#123"; matchFinishedEvent1.match.players[1].battleTag = "wolf#456"; matchFinishedEvent1.match.players[2].battleTag = "LostTeam1#456"; matchFinishedEvent1.match.players[3].battleTag = "LostTeam2#456"; matchFinishedEvent2.match.season = 1; matchFinishedEvent2.match.players[0].battleTag = "peter#123"; matchFinishedEvent2.match.players[1].battleTag = "ANDERER#456"; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.LoadFor("peter#123@10", "wolf#456"); var count = await matchRepository.CountFor("peter#123@10", "wolf#456"); Assert.AreEqual(0, count); }
public async Task <IActionResult> Edit(int id, [Bind("Id,TeamQuantity,MatchupDate,FirstTeamName,SecondTimeName")] Matchup matchup) { if (id != matchup.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(matchup); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MatchupExists(matchup.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(matchup)); }
public ActionResult Details(int?id) { MatchupEventTimingViewModel metViewModel = new MatchupEventTimingViewModel(); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Matchup matchup = _db.Matchups.Find(id); if (matchup == null) { return(HttpNotFound()); } metViewModel.matchup = matchup; foreach (var eventTiming in matchup.EventTimings) { metViewModel.eventTimings.Add(eventTiming); metViewModel.eventsOccured.Add(eventTiming.Event); } return(View(metViewModel)); }
public async Task SearchForPlayerAndOpponent_FilterByGateway() { var matchRepository = new MatchRepository(MongoClient, new OngoingMatchesCache(MongoClient)); var matchFinishedEvent1 = TestDtoHelper.CreateFakeEvent(); var matchFinishedEvent2 = TestDtoHelper.CreateFakeEvent(); matchFinishedEvent1.match.gateway = GateWay.America; matchFinishedEvent2.match.gateway = GateWay.Europe; matchFinishedEvent1.match.season = 1; matchFinishedEvent1.match.players[0].battleTag = "peter#123"; matchFinishedEvent1.match.players[1].battleTag = "wolf#456"; matchFinishedEvent2.match.season = 1; matchFinishedEvent2.match.players[0].battleTag = "peter#123"; matchFinishedEvent2.match.players[1].battleTag = "ANDERER#456"; await matchRepository.Insert(Matchup.Create(matchFinishedEvent1)); await matchRepository.Insert(Matchup.Create(matchFinishedEvent2)); var matches = await matchRepository.LoadFor("peter#123", null, GateWay.America); var count = await matchRepository.CountFor("peter#123", null, GateWay.America); Assert.AreEqual(1, count); Assert.AreEqual("peter#123", matches.Single().Teams.First().Players.Single().BattleTag); }
/// <summary> /// Determine the interaction between two objects, based on their types/sizes. /// </summary> /// <param name="origin">GameObject that contains the Collider that triggered the interaction.</param> /// <param name="other">GameObject that collided with the origin's Collider.</param> public static void Interact(GameObject origin, GameObject other) { Debug.Log("ORIGIN:" + origin.name + "OTHER:" + other.transform.gameObject.name); if (origin == null || other == null) { return; } ITypeSize originType; ITypeSize otherType; originType = origin.GetComponent <ITypeSize>(); otherType = other.GetComponent <ITypeSize>(); Matchup matchup = CheckMatchup(originType, otherType); if (matchup == Matchup.ADVANTAGE) { originType.OnAdvantage(origin, other); otherType.OnDisadvantage(origin, other); } else if (matchup == Matchup.DISADVANTAGE) { originType.OnDisadvantage(origin, other); otherType.OnAdvantage(origin, other); } else { originType.OnNeutral(origin, other); otherType.OnNeutral(other, origin); } }
public void SetTeamSchedule(TeamController t) { //gameController = FindObjectOfType<GameController>(); team = t; //Assumes that seasonMatchups == regularSeasonPieces.Count for (int i = 0; i < team.seasonMatchups.Count; i++) { regularSeasonPieces[i].gameObject.SetActive(true); Matchup matchForWeek = team.seasonMatchups[i]; TeamController opponentForWeek = null; if (matchForWeek != null) { if (team == matchForWeek.homeTeam) { opponentForWeek = matchForWeek.awayTeam; } else { opponentForWeek = matchForWeek.homeTeam; } } int weekInt = i; regularSeasonPieces[i].SetSchedulePiece(opponentForWeek, weekInt); } postseasonPiece.gameObject.SetActive(true); }
private List <Matchup> CreateFirstRoundMatchups(int byes, List <Team> teams) { List <Matchup> matchups = new List <Matchup>(); Matchup currentMatchup = new Matchup(); foreach (var team in teams) { currentMatchup.Entries.Add(new MatchupEntry() { TeamCompeting = team }); if (byes > 0 || currentMatchup.Entries.Count > 1) { currentMatchup.MatchupRound = 1; matchups.Add(currentMatchup); currentMatchup = new Matchup(); if (byes > 0) { byes -= 1; } } } return(matchups); }
public static List <Matchup> ConvertToMatchups(this List <string> lines) { //Id,Entries(id|id),Winner,MatchupRound List <Matchup> output = new List <Matchup>(); foreach (string line in lines) { string[] cols = line.Split(','); Matchup m = new Matchup(); m.Id = int.Parse(cols[0]); m.Entries = ConvertStringToMatchupEntry(cols[1]); if (cols[2].Length > 0) { m.Winner = LookupTeamById(int.Parse(cols[2])); } m.MatchupRound = int.Parse(cols[3]); output.Add(m); } return(output); }
public static void SaveMatchupToFile(this Matchup matchup) { List <Matchup> matchups = GlobalConfig.MatchupsFile.FullFilePath().LoadFile().ConvertToMatchups(); int currentId = 1; if (matchups.Count > 0) { currentId = matchups.OrderByDescending(m => m.Id).First().Id + 1; } matchup.Id = currentId; matchups.Add(matchup); foreach (MatchupEntry entry in matchup.Entries) { entry.SaveMatchupEntryToFile(); } List <string> lines = new List <string>(); foreach (Matchup m in matchups) { string entriesString = ConvertMatchupEntriesListToString(m.Entries); string winner = ""; if (m.Winner != null) { winner = m.Winner.Id.ToString(); } lines.Add($"{ m.Id },{ entriesString },{ winner },{ m.MatchupRound }"); } File.WriteAllLines(GlobalConfig.MatchupsFile.FullFilePath(), lines); }
public RatingSystemLogic(Matchup matchup) { double team1Score = matchup.MatchupEntries.First().Score; double team2Score = matchup.MatchupEntries.Last().Score; if (team1Score > team2Score) { resultA = winMultipler; resultB = lossMultipler; } else if (team1Score < team2Score) { resultA = lossMultipler; resultB = winMultipler; } else { resultA = drawMutlipler; resultB = drawMutlipler; } SetNewSettings(Convert.ToDouble(matchup.MatchupEntries.First().Team.TeamRating), Convert.ToDouble(matchup.MatchupEntries.Last().Team.TeamRating), resultA, resultB); var homeId = matchup.MatchupEntries.First().Team.id; var homeTeamRating = Convert.ToDecimal(_newRatingA); var awayId = matchup.MatchupEntries.Last().Team.id; var awayTeamRating = Convert.ToDecimal(_newRatingB); UpdateTeamRatings(homeId, awayId, homeTeamRating, awayTeamRating); }
public Matchup GenerateMatchup(GenerationSettings settings) { var random = new Random(); DowMap map = settings.Maps[random.Next(settings.Maps.Count)]; var info = new GameInfo() { Options = new GameOptions() { Difficulty = (GameDifficulty)RandomOption(settings.GameDifficultyTickets, random), Speed = (GameSpeed)RandomOption(settings.GameSpeedTickets, random), ResourceRate = (GameResourceRate)RandomOption(settings.ResourceRateTickets, random), StartingResources = (GameStartResource)RandomOption(settings.StartResourceTickets, random) } }; info.Rules.Add(settings.Rules[random.Next(settings.Rules.Count)]); var matchup = new Matchup(map, info); if (settings.Teams != null) { // TODO generate the team compositions } return(matchup); }
/// /// Updates the scores in the passed matchup. /// /// The Matchup to update /// Whether User 1 was the winner (false if User 2 is the winner) /// The desired Diff /// The desired KFactor /// public static void UpdateScores(Matchup matchup, bool user1WonMatch, int diff, int kFactor) { double est1 = 1 / Convert.ToDouble(1 + 10 ^ (matchup.User2Score - matchup.User1Score) / diff); double est2 = 1 / Convert.ToDouble(1 + 10 ^ (matchup.User1Score - matchup.User2Score) / diff); int sc1 = 0; int sc2 = 0; if (user1WonMatch) { sc1 = 1; } else { sc2 = 1; } matchup.User1Score = Convert.ToInt32(Math.Round(matchup.User1Score + kFactor * (sc1 - est1))); matchup.User2Score = Convert.ToInt32(Math.Round(matchup.User2Score + kFactor * (sc2 - est2))); }
public async Task <List <PlayerInMatch> > GetMatchups(List <PlayerInMatch> SourcePlayers, List <PlayerInMatch> TargetPlayers) { foreach (var SourcePlayer in SourcePlayers) { foreach (var TargetPlayer in TargetPlayers) { Matchup newMatchup = new Matchup(); newMatchup.TargetHeroID = TargetPlayer.Hero.HeroID; // Get disadvantage data WinRatesVersus WinRateData = await _dbService.WinRatesVersus .Where(x => x.BaseHeroID == SourcePlayer.Hero.HeroID && x.TargetHeroID == newMatchup.TargetHeroID) .FirstOrDefaultAsync(); newMatchup.Advantage = WinRateData.Advantage; //newMatchup.Disadvantage = await _dbService.WinRatesVersus // .Where(x => x.BaseHeroID == SourcePlayer.Hero.HeroInfo.HeroID && x.TargetHeroID == newMatchup.TargetHeroID) // .FirstOrDefaultAsync().Result.Disadvantage; SourcePlayer.Hero.Matchups.Add(newMatchup); SourcePlayer.Hero.InfluenceMatchups += newMatchup.Advantage; //SourcePlayer.Influence += newMatchup.Disadvantage; SourcePlayer.Hero.InfluenceMatchups = Math.Round(SourcePlayer.Hero.InfluenceMatchups, 4); } } return(SourcePlayers); }
public async Task ColossoTrain() { var embed = new EmbedBuilder(); embed.WithColor(Colors.Get("Iodem")); Matchup m = GetRandomMatchup(); embed.WithAuthor(GetTitle(Context.User, m.Enemy)); embed.WithDescription(GetText(Context.User, m)); lastMessageWasNuts = false; if (m.Result.Text.Contains("nuts")) { lastMessageWasNuts = true; } await Context.Channel.SendMessageAsync("", false, embed.Build()); if (m.Result.IsWin) { ServerGames.UserWonColosso((SocketGuildUser)Context.User, (SocketTextChannel)Context.Channel); } else { ServerGames.UserLostColosso((SocketGuildUser)Context.User, (SocketTextChannel)Context.Channel); } }
public void UpdateMatchup(Matchup model) { // spMatchups_Update @Id @WinnerId using (IDbConnection connection = new SqlConnection(GlobalConfig.CnnString(db))) { DynamicParameters param = new DynamicParameters(); if (model.Winner != null) { param.Add("@Id", model.Id); param.Add("@WinnerId", model.Winner.Id); connection.Execute("dbo.spMatchups_Update", param, commandType: CommandType.StoredProcedure); } // spMatchupsEntries_Update foreach (MatchupEntry me in model.Entrys) { if (me.TeamCompeting != null) { param = new DynamicParameters(); param.Add("@Id", me.Id); param.Add("@TeamCompetingId", me.TeamCompeting.Id); param.Add("@Score", me.Score); connection.Execute("dbo.spMatchupEntries_Update", param, commandType: CommandType.StoredProcedure); } } } }
public async void FindAsync(Matchup identifier) { var repository = GW2.V1.WorldVersusWorld.Matches; var result = await repository.FindAsync(new Matchup { MatchId = identifier.MatchId }); Assert.NotNull(result); Assert.StrictEqual(identifier.MatchId, result.MatchId); }
/// <summary> /// Retrieves either the cached matchup details, or requests new matchup details /// </summary> /// <returns>The current WvW matchup</returns> private Matchup GetCurrentMatchup(int worldId) { if (this.currentMatchup == null || (this.cachedWorldID != worldId) || (this.currentMatchup.EndTime.CompareTo(DateTimeOffset.UtcNow) < 0)) { // We've never requested the current matchup, or we've passed the end time for the current matchup var matches = this.matchService.Discover(); this.currentMatchup = matches.FirstOrDefault(match => match.BlueWorldId == worldId || match.GreenWorldId == worldId || match.RedWorldId == worldId); this.cachedWorldID = worldId; } return this.currentMatchup; }
public void FindAll_WithIdList_NotSupported(Matchup[] filter) { var repository = GW2.V1.WorldVersusWorld.Matches; Assert.Throws<NotSupportedException>(() => repository.FindAll(filter)); }
public async void FindAllAsync_WithIdList_NotSupported(Matchup[] filter) { var repository = GW2.V1.WorldVersusWorld.Matches; await Assert.ThrowsAsync<NotSupportedException>(() => repository.FindAllAsync(filter)); }