private void AdvanceMatch(Match match) { while (match.IsActive) { PerformAttack(match); match.AdvanceTime(); } }
private void PlayPenaltyShootout(Match match) { bool isFirstTeamShooting = randomizer.IsFirstTeamStartingPenaltyShootout(); while (!match.IsConclusive) { Team team = isFirstTeamShooting ? match.Team1 : match.Team2; bool isScored = randomizer.TryPenaltyKick(); match.OnExtraPenaltyKick(team, isScored); isFirstTeamShooting = !isFirstTeamShooting; } }
public void Perform(int matchCount) { var results = new List<MatchResult>(); Team team1 = teamConverter.CreateTeam("Wisla Krakow"); Team team2 = teamConverter.CreateTeam("Polonia Warszawa"); for (int i = 0; i < matchCount; i++) { var match = new Match(team1, team2, isNeutralGround: false, isExtraTimeRequired: false); var simulator = new Simulator(MatchRandomizer.Current); var result = simulator.Play(match); results.Add(result); Console.WriteLine("{0}:{1}\t{2}", result.Score1, result.Score2, string.Join(", ", match.Events.OfType<GoalEvent>())); } PrintStatistics(results, team1); }
public void Perform() { Team team1 = teamConverter.CreateTeam("Real Madrid"); Team team2 = teamConverter.CreateTeam("FC Barcelona"); var match = new Match(team1, team2, isNeutralGround: false, isExtraTimeRequired: true); var simulator = new Simulator(MatchRandomizer.Current); simulator.Play(match); var printingVisitor = new MatchEventPrintingVisitor(); foreach (var group in match.Events.GroupBy(e => Tuple.Create(e.Minute, e.Extended)).OrderBy(g => g.Key)) { if (group.Key.Item2 == 0) { Console.Write("{0,5}: ", group.Key.Item1); } else { Console.Write("{0,3}+{1}: ", group.Key.Item1, group.Key.Item2); } var events = group.ToArray(); for (int i = 0; i < events.Length; i++) { events[i].Visit(printingVisitor); if (i < events.Length - 1) { Console.Write(", "); } } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine(match); Console.WriteLine(); PrintPlayerStats(match.Team1); PrintPlayerStats(match.Team2); }
private void PerformAttack(Match match) { Team team = randomizer.AttackingTeam(match.Team1, match.Team2, match.IsNeutralGround); Player player = team.PickPlayerInitiatingAttack(); match.InitiateAttack(player); int level = 0; bool canContinue = true; while (canContinue) { level++; IMatchAction action = randomizer.NextAction(level, player); action.Perform(match); canContinue = action.CanContinue; } match.CompleteAttack(); }
public MatchResult Play(Match match) { AdvanceMatch(match); int extendedLength = randomizer.ExtendedTime(); match.ExtendTime(extendedLength); AdvanceMatch(match); if (!match.IsConclusive) { match.EnterExtraTime(); AdvanceMatch(match); if (!match.IsConclusive) { PlayPenaltyShootout(match); } } return new MatchResult(match.Team1, match.Team2, match.Winner, match.Score1, match.Score2, match.PenaltyScore1, match.PenaltyScore2, match.Events); }