static void Main() { var arbiter = new GameProcessor(); var commandsParser = new GameCommandsParser(arbiter); foreach (var gameResult in arbiter.RunGames(ReadAllLines().Select(commandsParser.ParseCommand))) { Console.WriteLine("Turn: {0}, cards: {1}, with risk: {2}", gameResult.TurnsCount, gameResult.PlayedCardsCount, gameResult.RiskedTurnsCount); } }
public GameCommandsParser(GameProcessor processor) { inputDataProсessing = new Dictionary<Regex, Action<Match>>(); inputDataProсessing[startNewGameRegex] = match => { processor.StartNewGame( match.Groups[1].Value.Split(' ') .Select(Card.SelectAbbreviationToCard) .ToList()); }; inputDataProсessing[tellColorRegex] = match => { processor.TellColor(ParseColorString(match.Groups[1].Value), match.Groups[2].Value.Split(' ').Select(int.Parse).ToList()); }; inputDataProсessing[tellRankRegex] = match => { processor.TellRank(int.Parse(match.Groups[1].Value), match.Groups[2].Value.Split(' ').Select(int.Parse).ToList()); }; inputDataProсessing[playCardRegex] = match => { processor.PlayCard(int.Parse(match.Groups[1].Value)); }; inputDataProсessing[dropCardRegex] = match => { processor.DropCard(int.Parse(match.Groups[1].Value)); }; }