예제 #1
0
        void LoadLogs(string replayFrom)
        {
            _actions.Clear();
            _nextAction = 0;

            GameLogParser logParser = new GameLogParser();

            logParser.OnGameRecord += new GameLogParser.OnGameRecordHandler(logParser_OnGameRecord);
            logParser.OnError      += new GameLogParser.OnErrorHandler(logParser_OnError);
            logParser.ParsePath(replayFrom);
        }
예제 #2
0
        /// <summary>
        /// Plays a ring game session or one subsession of seat-permutation session.
        /// </summary>
        void PlaySimpleSession(int rngSeed)
        {
            _dealer = new SequenceRng(CreateUnderlyingRng(rngSeed), _gameDef.DeckDescr.FullDeckIndexes);
            int gamesCount = _sessionCfg.GamesCount;

            if (IsReplaying())
            {
                _dealLog.Clear();
                GameLogParser gameLogParser = new GameLogParser();
                gameLogParser.OnGameRecord += new GameLogParser.OnGameRecordHandler(gameLogParser_OnGameRecord);
                gameLogParser.OnError      += new GameLogParser.OnErrorHandler(gameLogParser_OnError);

                gameLogParser.ParsePath(_sessionCfg.ReplayFrom.Get(Props.Global));
                gamesCount = Math.Min(_sessionCfg.GamesCount, _dealLog.Count);
            }

            for (int gameNumber = 0; gameNumber < gamesCount; gameNumber++)
            {
                if (_sessionCfg.Kind == SessionKind.RingGame && QuitAtNextPossiblePoint)
                {
                    break;
                }

                GameRecord dealRecord;

                if (IsReplaying())
                {
                    dealRecord = _dealLog[gameNumber];
                    for (int a = 0; a < dealRecord.Actions.Count;)
                    {
                        switch (dealRecord.Actions[a].Kind)
                        {
                        case Ak.d:
                            // Keep these actions.
                            ++a;
                            break;

                        default:
                            // Remove these actions
                            dealRecord.Actions.RemoveAt(a);
                            break;
                        }
                    }
                }
                else
                {
                    dealRecord    = DealCards();
                    dealRecord.Id = gameNumber.ToString();
                }

                GameRunner game            = new GameRunner(_gameDef, _sessionPlayers, dealRecord);
                GameRecord finalGameRecord = game.Run();

                if (IsLoggingEnabled)
                {
                    _gameLog.WriteLine(finalGameRecord.ToString());
                    _gameLog.Flush();
                }

                if (OnGameEnd != null)
                {
                    OnGameEnd(finalGameRecord);
                }

                if (!_sessionCfg.FixButton)
                {
                    // Move button: [0, 1, 2] -> [1, 2, 0]
                    _sessionPlayers.RotateMinCopy(_sessionPlayers.Count - 1);
                }
            }
        }
예제 #3
0
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                return(1);
            }

            char[] sep = new char[] { '=' };
            foreach (string param in _cmdLine.ReportParameters)
            {
                string[] nameVal = param.Split(sep, StringSplitOptions.RemoveEmptyEntries);
                if (nameVal.Length != 2)
                {
                    Console.Error.WriteLine("Wrong report parameter: {0}", param);
                    return(1);
                }
                _reportParameters.Set(nameVal[0], nameVal[1]);
            }

            if (!String.IsNullOrEmpty(_cmdLine.Output))
            {
                _output = new StreamWriter(_cmdLine.Output);
            }

            DateTime start = DateTime.Now;

            GameLogParser logParser = new GameLogParser {
                Verbose = _cmdLine.Verbose, IncludeFiles = _cmdLine.IncludeFiles
            };

            logParser.OnGameRecord += new GameLogParser.OnGameRecordHandler(logParser_OnGameRecord);
            logParser.OnMetaData   += new GameLogParser.OnMetaDataHandler(logParser_OnMetaData);

            if (_cmdLine.TotalResult)
            {
                _totalResult = CreateGameLogReport("Total result");
            }
            if (_cmdLine.SessionResult)
            {
                _sessionResult = CreateGameLogReport("Unnamed session");
            }
            if (_isHelpShown)
            {
                return(0);
            }
            _sessionGamesCount = 0;

            if (_cmdLine.CountGames || _cmdLine.TotalResult || _cmdLine.SessionResult)
            {
                foreach (string path in _cmdLine.InputPaths)
                {
                    try
                    {
                        logParser.ParsePath(path);
                    }
                    catch (GameLimitException)
                    {
                    }
                }
            }

            if (_cmdLine.SessionResult && _sessionGamesCount > 0)
            {
                // There was an incomplete session.
                _sessionResult.Print(_output);
            }

            if (_cmdLine.TotalResult)
            {
                _totalResult.Print(_output);
            }

            // Print game count after session result, so that results are not interrupted.
            if (_cmdLine.CountGames)
            {
                _output.WriteLine("{0} games in {1} files, {2} errors", logParser.GamesCount, logParser.FilesCount, logParser.ErrorCount);
            }

            double sec = (DateTime.Now - start).TotalSeconds;

            if (_cmdLine.Time)
            {
                _output.WriteLine("Run time {0:0.0} seconds", sec);
            }

            _output.Flush();

            return(0);
        }