本文整理汇总了C#中Randomizer.GetRandomBoolean方法的典型用法代码示例。如果您正苦于以下问题:C# Randomizer.GetRandomBoolean方法的具体用法?C# Randomizer.GetRandomBoolean怎么用?C# Randomizer.GetRandomBoolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Randomizer
的用法示例。
在下文中一共展示了Randomizer.GetRandomBoolean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateLeagueTable
public void UpdateLeagueTable(LeagueTable leagueTable, IEnumerable<Match> matches)
{
foreach (var match in matches)
{
// Determine the home and away team.
var homeTeam = leagueTable.LeagueTablePositions.First(pos => pos.Team.Equals(match.HomeTeam));
var awayTeam = leagueTable.LeagueTablePositions.First(pos => pos.Team.Equals(match.AwayTeam));
// Increment number of played matches.
homeTeam.Matches++;
awayTeam.Matches++;
// Calculate goals scored, conceded and differential for both teams.
homeTeam.GoalsScored += match.HomeScore;
homeTeam.GoalsConceded += match.AwayScore;
homeTeam.GoalDifference = homeTeam.GoalsScored - homeTeam.GoalsConceded;
awayTeam.GoalsScored += match.AwayScore;
awayTeam.GoalsConceded += match.HomeScore;
awayTeam.GoalDifference = awayTeam.GoalsScored - awayTeam.GoalsConceded;
// Determine the number of points for both teams.
// Increment the number of wins, losses and/or draws for both teams.
int homePoints = 1;
int awayPoints = 1;
if (match.HomeScore == match.AwayScore)
{
homeTeam.Draws++;
awayTeam.Draws++;
}
else
{
bool homeTeamWins = match.HomeScore > match.AwayScore;
bool awayTeamWins = match.AwayScore > match.HomeScore;
if (homeTeamWins)
{
homePoints = 3;
awayPoints = 0;
homeTeam.Wins++;
awayTeam.Losses++;
}
else if (awayTeamWins)
{
homePoints = 0;
awayPoints = 3;
homeTeam.Losses++;
awayTeam.Wins++;
}
}
homeTeam.Points += homePoints;
awayTeam.Points += awayPoints;
}
// Sort the league table.
leagueTable.LeagueTablePositions.Sort((x, y) =>
{
// Points will be sorted ascending, hence Y followed by X.
int result = y.Points.CompareTo(x.Points);
// If necessary, matches will be sorted descending, hence X followed by Y.
if (result == 0)
{
result = x.Matches.CompareTo(y.Matches);
}
// If necessary, goal difference will be sorted.
if (result == 0)
{
result = y.GoalDifference.CompareTo(x.GoalDifference);
}
// If necessary, goals scored will be sorted.
if (result == 0)
{
result = y.GoalsScored.CompareTo(x.GoalsScored);
}
//TODO Eigenlijk moet er gekeken worden naar onderling resultaat, maar we doen het eerst maar random...
if (result == 0)
{
var randomizer = new Randomizer();
bool randomBoolean = randomizer.GetRandomBoolean();
if (randomBoolean)
{
result = 1;
}
}
return result;
});
// Update position numbers, starting with 1.
int position = 1;
foreach (var leagueTablePosition in leagueTable.LeagueTablePositions)
{
leagueTablePosition.Position = position;
leagueTablePosition.Team.CurrentLeaguePosition = position;
position++;
}
}