private static MatchDay CreateMatchDayOne(List <Team> teams, Team lastTeam) { var matchDay = new MatchDay(); matchDay.Matches = new List <Match>(); var match = new Match(); for (var i = 0; i < teams.Count; i++) { if (i == 0) { match.TeamOne = lastTeam; continue; } if (i % 2 == 1) { match.TeamTwo = teams[i - 1]; matchDay.Matches.Add(match); match = new Match(); } else { match.TeamOne = teams[i - 1]; } } return(matchDay); }
public async Task <MatchDay> UpdateMatchDayHandicaps(MatchDay matchDay) { var playerResults = GetPlayersResults(matchDay); foreach (var playerResult in playerResults) { var player = (await _playerRepository.Find(p => p.Id == playerResult.PlayerId)).FirstOrDefault(); if (player != null) { if (player.Handicap + playerResult.HandicapToAdd > 90) { player.Handicap = 90; } else if (player.Handicap + playerResult.HandicapToAdd < 0) { player.Handicap = 0; } else { player.Handicap += playerResult.HandicapToAdd; } await _playerRepository.AddOrUpdate(player); } } return(matchDay); }
//private const string endpoint = "/v2/competitions/2021/matches?matchday=1"; public IEnumerable <Match> Get() { if (MatchDay == 0) { throw new ArgumentOutOfRangeException(nameof(MatchDay)); } if (CompetitionId == 0) { throw new ArgumentOutOfRangeException(nameof(CompetitionId)); } var request = new RestRequest(endpoint); request.AddHeader("X-Auth-Token", "a969a2868cd54854bdbce65c40eb95f0"); request.AddUrlSegment("competitionid", CompetitionId.ToString()); request.AddUrlSegment("matchday", MatchDay.ToString()); var response = FootballDataApiClient.Execute(request); var content = response.Content; var responseData = JsonConvert.DeserializeObject <JObject>(content); var comps = responseData["matches"].ToString(); var data = JsonConvert.DeserializeObject <List <Match> >(comps); return(data); }
/// <summary>Play a match day.</summary> /// <param name="matchDay">The match day.</param> private static void PlayMatchDay(MatchDay matchDay) { foreach (var match in matchDay.Matches) { match.Play(); } }
public void SetTeamForNextGame() { if (matchNumber >= 1 && matchNumber < 5) { setSemiFinalTeams(matchNumber); } else if (matchNumber >= 5 && matchNumber < 7) { if ((matchNumber - 5) % 2 == 0) { teamA = new TeamScript(semiFinal[matchNumber - 5].MatchDayResult.Winner); string groupName = "Final"; teamA.Flag = SetFlagSpriteoFTeam(groupName, "TeamA", teamA.Flag.sprite); } else { teamB = new TeamScript(semiFinal[matchNumber - 5].MatchDayResult.Winner); string groupName = "Final"; teamB.Flag = SetFlagSpriteoFTeam(groupName, "TeamB", teamB.Flag.sprite); final[(matchNumber - 5) / 2] = new MatchDay(teamA, teamB, groupName); } } else if (matchNumber == 7) { tournamentWinner = new TeamScript(final[0].MatchDayResult.Winner); string groupName = "Winner"; tournamentWinner.Flag = SetFlagSpriteoFTeam(groupName, "winner", tournamentWinner.Flag.sprite); playButton.interactable = false; Debug.Log("And we are done"); } }
public static League CreateLeagueMatches(this List <Team> teams) { var league = new League(); league.Matchdays = new List <MatchDay>(); var lastTeam = teams.Last(); for (var i = 1; i < teams.Count; i++) { _ = new MatchDay(); MatchDay matchDay; if (i == 1) { matchDay = CreateMatchDayOne(teams, lastTeam); } else { matchDay = CreateMatchDay(teams, lastTeam); } teams.CreateNewOrder(matchDay); league.Matchdays.Add(matchDay); } return(league); }
// Use this for initialization void Start() { Debug.Log(matchNumber); flags = Resources.LoadAll <Sprite>("Flags"); if (matchNumber == 0) { for (int i = 0; i < 8; i += 2) { TeamScript teamA = null; TeamScript teamB = null; String groupName = "Group" + (char)('A' + (int)(i / 2)); Image imageTeamA = SetFlagSpriteoFTeam(groupName, "TeamA", flags[i]); Image imageTeamB = SetFlagSpriteoFTeam(groupName, "TeamB", flags[i + 1]); if (i == 0) { teamA = new TeamScript(teamList[i], teamListShort[i], "human", imageTeamA); teamB = new TeamScript(teamList[i + 1], teamListShort[i + 1], "bot", imageTeamB); } else { teamA = new TeamScript(teamList[i], teamListShort[i], "bot", imageTeamA); teamB = new TeamScript(teamList[i + 1], teamListShort[i + 1], "bot", imageTeamB); } MatchDay matchDay = new MatchDay(teamA, teamB, groupName); quarterFinal[i / 2] = matchDay; } } }
private MatchDay GetMatchDay() { var players = GetPlayerQuery().ToArray(); var matchDay = new MatchDay { Date = new DateTimeOffset(), Games = new List <Game> { GetGame() }, Id = "123", MatchDayPlayers = new List <MatchDayPlayer> { new MatchDayPlayer { Player = players[0], PlayerId = players[0].Id, MatchDay = null, MatchDayId = null } }, TenantId = tenantId }; return(matchDay); }
private List <(string PlayerId, int HandicapToAdd)> GetPlayersResults(MatchDay matchDay) { var results = new List <(string PlayerId, int HandicapToAdd)>(); var playerIds = matchDay.Games.Select(g => g.PlayerOneId).ToList(); playerIds.AddRange(matchDay.Games.Select(g => g.PlayerTwoId).ToList()); playerIds = playerIds.Distinct().ToList(); foreach (var playerId in playerIds) { var handicapToAdd = 0; foreach (var game in matchDay.Games) { handicapToAdd += HandicapToAdd(playerId, game); } results.Add((PlayerId: playerId, HandicapToAdd: handicapToAdd)); } return(results); }
public async Task <MatchDay> UpdateMatchDayPlayers(MatchDay matchDay) { if (matchDay == null) { throw new EntityNotFoundException($"Matchday with id {matchDay.Id} does not exist."); } var matchDayPlayers = await _context.MatchDayPlayers .Where(md => md.MatchDayId == matchDay.Id) .AsNoTracking() .ToListAsync(); foreach (var matchDayPlayer in matchDayPlayers) { var existingMatchDayPlayer = matchDay.MatchDayPlayers .FirstOrDefault(md => md.PlayerId == matchDayPlayer.PlayerId); if (existingMatchDayPlayer != null) { continue; } _context.Remove(matchDayPlayer); } _context.Update(matchDay); return(matchDay); }
private static ICollection <Player> GetPlayersByGames(this MatchDay matchDay, ICollection <Game> games) { var players = games.Select(g => g.PlayerOne).ToList(); players.AddRange(games.Select(g => g.PlayerTwo).ToList()); return(players); }
private bool MatchDayHasPlayer(MatchDay matchDay, Player player) { var tstPlayer = matchDay.MatchDayPlayers .Where(p => p.PlayerId == player.Id) .FirstOrDefault(); return(tstPlayer != null); }
/// <summary> /// Get the winner of a match in a specific time of the match /// </summary> /// <param name="md">The match</param> /// <param name="time">The time of the match</param> /// <returns>The winner of the match. 0 (draw), 1 (home team), 2 (away team)</returns> private static int getWinner(MatchDay md, int time) { int? homeGoals = getGoals(md, time, true); int? awayGoals = getGoals(md, time, false); if (homeGoals == awayGoals) return 0; else if (homeGoals > awayGoals) return 1; else return 2; }
public async Task Insert(MatchDay matchDay) { if (_matchDays.SingleOrDefault(md => md.Id == matchDay.Id) != null) { throw new EntityAlreadyExistsException($"MatchDay with id {matchDay.Id} already exists."); } await _matchDays.AddAsync(matchDay); }
/// <summary> /// Get the match title for a fb /// </summary> /// <param name="fb">The football bet</param> /// <param name="_context">The database context</param> /// <returns>The name of the match</returns> private static string getMatchTitle(FootballBet fb, ApplicationDBContext _context) { _context.Entry(fb).Reference("MatchDay").Load(); MatchDay md = fb.MatchDay; _context.Entry(md).Reference("HomeTeam").Load(); _context.Entry(md).Reference("AwayTeam").Load(); return(md.HomeTeam.name + " vs " + md.AwayTeam.name); }
public async Task <MatchDay> Update(MatchDay matchDay) { if (matchDay == null) { throw new EntityNotFoundException($"Matchday with id {matchDay.Id} does not exist."); } _context.Update(matchDay); return(await Task.FromResult(matchDay)); }
public void SetTeam(MatchDay matchDay) { for (int i = 0; i < quarterFinal.Length; i++) { if (quarterFinal[i].CurrButtonName.Equals(matchDay.CurrButtonName)) { quarterFinal[i] = matchDay; } } }
public void SetTeams(MatchDay matchDay) { Debug.Log(matchDay.TeamA.TeamName + " vs " + matchDay.TeamB.TeamName + " in quarter final"); teamAName.text = matchDay.TeamA.ShortName; teamBName.text = matchDay.TeamB.ShortName; teamAMode = matchDay.TeamA.Mode; teamBMode = matchDay.TeamB.Mode; teamAFullName = matchDay.TeamA.TeamName; teamBFullName = matchDay.TeamB.TeamName; }
void PlayMatch() { //here we can assume that this is a matchday MatchDay currentMatchday = MatchDayController.instance.CurrentMatchDay; foreach (Match match in currentMatchday.matches) { match.SimulateMatch(); } MatchDayController.instance.CurrentMachtesPlayed = true; }
public Queue <MatchDay> getSeasonMatchDays() { //here we create the Matchpairs for all Matchdays of one year Queue <MatchDay> allMatches = new Queue <MatchDay>(); //1. create list where all teams have the info about whom they allready //played List <MatchPairTeam> matchTeams = new List <MatchPairTeam>(); List <Team> allTeamsTemp = LeagueController.instance.teams; foreach (Team team in allTeamsTemp) { MatchPairTeam newTeam = new MatchPairTeam(team); //the team has to play all teams execpt itself IEnumerable <Team> iterator = allTeamsTemp.Where(t => t.name != team.name); foreach (Team t in iterator) { newTeam.teamsToPlay.Add(t); } matchTeams.Add(newTeam); } //2. create the 7 games for (int i = 0; i < 7; i++) { MatchDay matchDay = new MatchDay();; List <MatchPairTeam> matchTeamsForDay = new List <MatchPairTeam>(matchTeams); while (matchTeamsForDay.Count != 0) { //take some team MatchPairTeam someTeam = matchTeamsForDay.ElementAtOrDefault(0); MatchPairTeam validOponent = matchTeamsForDay.FirstOrDefault(t => t.teamsToPlay.Contains(someTeam.team)); //create a match with the two teams Match newMatch = new Match(someTeam.team, validOponent.team); matchDay.matches.Add(newMatch); //mark the current combination as done someTeam.teamsToPlay.Remove(validOponent.team); validOponent.teamsToPlay.Remove(someTeam.team); //remove the teams from the candidates for the current matchday matchTeamsForDay.Remove(someTeam); matchTeamsForDay.Remove(validOponent); } allMatches.Enqueue(matchDay); } return(allMatches); }
public async Task <MatchDay> CreateMatchDay(string tenantId) { var matchDay = new MatchDay(); matchDay.TenantId = tenantId; await _matchDayRepository.Insert(matchDay); await _matchDayRepository.SaveChangesAsync(); return(matchDay); }
//Create list of teams based on previous matchday private static List <Team> CreateNewOrder(this List <Team> teams, MatchDay matchDay) { teams.RemoveAll(x => true); var iterableList = matchDay.Matches.ToList(); for (var i = 0; i < iterableList.Count; i++) { teams.Add(iterableList[i].TeamOne); teams.Add(iterableList[i].TeamTwo); } return(teams); }
public void GetNextPlayersReturnsFirstPlayersIfNoGamesExist() { var matchDay = new MatchDay { Date = DateTimeOffset.Now, Id = "md", Games = new List <Game>(), TenantId = "tenant", MatchDayPlayers = new List <MatchDayPlayer>() { new MatchDayPlayer { PlayerId = "p1", Player = new Player { FirstName = "a", LastName = "b", Handicap = 5, TenantId = "tenant", MatchDayPlayers = new List <MatchDayPlayer>(), Id = "1", }, MatchDay = null, MatchDayId = null }, new MatchDayPlayer { PlayerId = "p2", Player = new Player { FirstName = "c", LastName = "d", Handicap = 5, TenantId = "tenant", MatchDayPlayers = new List <MatchDayPlayer>(), Id = "2", }, MatchDay = null, MatchDayId = null } } }; var nextPlayers = matchDay.GetNextPlayers(matchDay.Games); nextPlayers.Should().NotBeNull(); nextPlayers.PlayerOneId.Should().Be("1"); nextPlayers.PlayerTwoId.Should().Be("2"); }
private static ICollection <Player> GetNextRoundPlayers(this MatchDay matchDay, ICollection <Game> games) { var availablePlayers = matchDay.GetAvailablePlayers(); var players = matchDay.GetPlayersByGames(games); foreach (var player in players) { var playerExists = availablePlayers.FirstOrDefault(p => p.Id == player.Id) != null; if (playerExists) { availablePlayers.Add(player); } } return(availablePlayers); }
public void setSemiFinalTeams(int i) { i = (i - 1); if (i % 2 == 0) { teamA = new TeamScript(quarterFinal[i].MatchDayResult.Winner); string groupName = "Semi" + (char)('A' + (int)(i / 2)); teamA.Flag = SetFlagSpriteoFTeam(groupName, "TeamA", teamA.Flag.sprite); } else { teamB = new TeamScript(quarterFinal[i].MatchDayResult.Winner); string groupName = "Semi" + (char)('A' + (int)(i / 2)); teamB.Flag = SetFlagSpriteoFTeam(groupName, "TeamB", teamB.Flag.sprite); semiFinal[i / 2] = new MatchDay(teamA, teamB, groupName); } }
// // ────────────────────────────────────────────────────────────────────────────────── // :::::: P U B L I C F U N C T I O N S : : : : : : : : // ────────────────────────────────────────────────────────────────────────────────── // /// <summary> /// Get the matchday that the fb is going to be /// </summary> /// <param name="match">A new matchday object, to save the matchday on it</param> /// <param name="matchday">The id of the matchday</param> /// <returns>True if the matchday exists, false otherwise</returns> private bool getMatchDay(ref MatchDay match, string matchday) { List <MatchDay> matchs = _context.MatchDays.Where(md => md.id.ToString() == matchday).ToList(); if (matchs.Count() != 1) { return(false); } match = matchs.First(); if (DateTime.Now > match.date || DateTime.Now.AddDays(8) < match.date) { return(false); } return(true); }
private static MatchDay CreateMatchDay(List <Team> teams, Team lastTeam) { var matchDay = new MatchDay(); matchDay.Matches = new List <Match>(); var match = new Match(); var len = teams.Count; for (var i = 0; i < len; i++) { if (i == 0) { match.TeamOne = lastTeam; teams.Remove(lastTeam); continue; } if (i == 1) { match.TeamTwo = teams.Last(); matchDay.Matches.Add(match); match = new Match(); continue; } var firstTeam = teams.First(); if (i % 2 == 1) { match.TeamTwo = firstTeam; matchDay.Matches.Add(match); match = new Match(); } else { match.TeamOne = firstTeam; } teams.Remove(firstTeam); } return(matchDay); }
public virtual ActionResult Create(MatchDayViewModel model) { if (ModelState.IsValid) { var matchDay = new MatchDay() { LeagueId = model.LeagueId, SeasonId = model.SeasonId, Number = model.Number, Round = model.Round }; _matchDayService.Create(matchDay); return(RedirectToAction(MVC.Admin.MatchDays.List(model.SeasonId, model.LeagueId))); } return(View(model)); }
/// <summary> /// Add a football match to the array of available matchdays /// </summary> /// <param name="mainArray">The id with the avaiable matchdays</param> /// <param name="md">The matchday to add</param> /// <param name="allowedTypes">The available fb types on this matchday</param> private void addFootballMatch(List <FootballMatch> mainArray, MatchDay md, List <TypeFootballBet> allowedTypes) { if (allowedTypes.Count() == 0) { return; } _context.Entry(md).Reference("HomeTeam").Load(); _context.Entry(md).Reference("AwayTeam").Load(); _context.Entry(md).Reference("Competition").Load(); mainArray.Add(new FootballMatch { competition = md.Competition.name, match_name = md.HomeTeam.name + " vs " + md.AwayTeam.name, matchday = md.id.ToString(), date = md.date, allowedTypeBets = getIdsFromTypeBets(allowedTypes), }); }
public static (string PlayerOneId, string PlayerTwoId) GetNextPlayers(this MatchDay matchDay, ICollection <Game> games) { var nextPlayers = (PlayerOneId : "", PlayerTwoId : ""); var players = matchDay.GetNextRoundPlayers(games); if (players.Count < 2) { throw new NotEnoughPlayersException($"MatchDay {matchDay.Id} has not enough Players to start a match. Add some players to the MatchDay."); } if (players.Count == 2) { nextPlayers.PlayerOneId = players.ElementAt(0).Id; nextPlayers.PlayerTwoId = players.ElementAt(1).Id; return(nextPlayers); } if (matchDay.Games.Count == 0) { nextPlayers.PlayerOneId = players.ElementAt(0).Id; nextPlayers.PlayerTwoId = players.ElementAt(1).Id; return(nextPlayers); } players = players.GroupBy(p => p.Id) .OrderBy(g => g.Count()) .SelectMany(p => p) .ToList(); nextPlayers.PlayerOneId = players.ElementAt(0).Id; players = players.Where(p => p.Id != nextPlayers.PlayerOneId).ToList(); var groups = players.GroupBy(p => p.Id) .OrderBy(g => g.Count()); nextPlayers.PlayerTwoId = GetRandomSecondPlayer(groups); return(nextPlayers); }