public static List <PlayerReference> FetchFrom(GroupBase group) { if (group.GetPlayState() == PlayStateEnum.Finished) { PlayerStandingsSolver playerStandingsSolver = new PlayerStandingsSolver(); List <StandingsEntry <PlayerReference> > playerReferences = playerStandingsSolver.FetchFrom(group); playerReferences = FilterAdvancingPlayers(group, playerReferences); if (group.HasProblematicTie()) { playerReferences = FilterTyingPlayers(group, playerReferences); playerReferences.AddRange(group.ChoosenTyingPlayerEntries); } List <PlayerReference> advancingPlayers = new List <PlayerReference>(); foreach (StandingsEntry <PlayerReference> entry in playerReferences) { advancingPlayers.Add(entry.Object); } return(advancingPlayers); } return(new List <PlayerReference>()); }
public bool HasSolvedTie() { bool hasPlayersChosenForSolvingTie = ChoosenTyingPlayerEntries.Count > 0; if (hasPlayersChosenForSolvingTie) { List <StandingsEntry <PlayerReference> > playerStandings = FindProblematiclyTyingPlayers(); int tyingScore = playerStandings.First().Points; PlayerStandingsSolver playerStandingsSolver = new PlayerStandingsSolver(); playerStandings = playerStandingsSolver.FetchFrom(this); int clearWinners = 0; foreach (StandingsEntry <PlayerReference> entry in playerStandings) { if (entry.Points > tyingScore) { clearWinners += 1; } } bool hasEnoughToTransferToNextRound = (clearWinners + ChoosenTyingPlayerEntries.Count) == Round.AdvancingPerGroupCount; return(hasEnoughToTransferToNextRound); } return(false); }
public List <StandingsEntry <PlayerReference> > FindProblematiclyTyingPlayers() { bool notAllMatchesHasBeenPlayed = !AllMatchesPlayStatesAre(PlayStateEnum.Finished); if (notAllMatchesHasBeenPlayed) { return(new List <StandingsEntry <PlayerReference> >()); } PlayerStandingsSolver playerStandingsSolver = new PlayerStandingsSolver(); List <StandingsEntry <PlayerReference> > playerStandings = playerStandingsSolver.FetchFrom(this); List <StandingsEntry <PlayerReference> > problematicPlayers = new List <StandingsEntry <PlayerReference> >(); StandingsEntry <PlayerReference> aboveThresholdPlayer = playerStandings[Round.AdvancingPerGroupCount - 1]; StandingsEntry <PlayerReference> belowThresholdPlayer = playerStandings[Round.AdvancingPerGroupCount]; bool playersPartOfProblematicTie = aboveThresholdPlayer.Points == belowThresholdPlayer.Points; if (playersPartOfProblematicTie) { foreach (StandingsEntry <PlayerReference> entry in playerStandings) { bool isPartOfTie = entry.Points == aboveThresholdPlayer.Points; if (isPartOfTie) { problematicPlayers.Add(entry); } } } return(problematicPlayers); }
public void ThenPlayerStandingsInGroupFromFirstToLastShouldBe(int groupIndex, string commaSeparatedPlayerNames) { GroupBase group = createdGroups[groupIndex]; List <string> expectedPlayerNameOrder = StringUtility.ToStringList(commaSeparatedPlayerNames, ","); PlayerStandingsSolver playerStandingsSolver = new PlayerStandingsSolver(); List <StandingsEntry <PlayerReference> > playerStandings = playerStandingsSolver.FetchFrom(group); playerStandings.Should().HaveCount(expectedPlayerNameOrder.Count); for (int index = 0; index < playerStandings.Count; ++index) { playerStandings[index].Object.Name.Should().Be(expectedPlayerNameOrder[index]); } }