private static decimal CalculatePayout(GameTicket ticket, Game game) { var amount = CalculatePayout(ticket.NumbersToBetPerGame, NumberOfMatches(ticket.NumbersPlayed, game.NumbersDrawn)); if (ticket.BetKicker) { amount *= 2; } return amount; }
private IEnumerable<GameResult> ProcessResults(Game currentGame) { var results = new List<GameResult>(); foreach (GameTicket registeredTicket in currentGame.RegisteredTickets) { decimal amount = CalculatePayout(registeredTicket, currentGame); results.Add(new GameResult(currentGame.NumbersDrawn, amount > 0, amount, currentGame.GameId, registeredTicket.NumbersToBetPerGame, NumbersMatched(registeredTicket.NumbersPlayed, currentGame.NumbersDrawn).ToArray())); } _completedGames.Add(currentGame); return results.AsReadOnly(); }
public IEnumerable<GameResult> Run() { while (_availableGames.Peek().RegisteredTickets.Count > 0) { _currentGame = _availableGames.Dequeue(); _currentGame.GameState = GameState.Active; _currentGame.NumbersDrawn = DrawNumbers(); _currentGame.GameState = GameState.Complete; IEnumerable<GameResult> gameResults = ProcessResults(_currentGame); _currentGame = null; RefreshAvailableGames(); foreach (GameResult gameResult in gameResults) { yield return gameResult; } } }