예제 #1
0
        static void  logParser_OnMetaData(GameLogParser source, string metaData)
        {
            GameLogMetaData md = GameLogMetaData.Parse(metaData);

            if (md == null)
            {
                source.ErrorCount++;
                Console.Error.WriteLine(source.GetDefaultErrorText("Unknown metadata: " + metaData));
            }
            if (md.Name == "OnSessionBegin")
            {
                if (!md.Properties.ContainsKey("Repetition") || int.Parse(md.Properties["Repetition"]) == 0)
                {
                    // The very first repetition.
                    if (_cmdLine.SessionResult && _sessionGamesCount > 0)
                    {
                        _sessionResult.Print(_output);
                    }
                    if (_cmdLine.SessionResult)
                    {
                        _sessionResult =
                            CreateGameLogReport(md.Properties.ContainsKey("Name")
                                                    ? md.Properties["Name"]
                                                    : "Unnamed session");
                    }
                    _sessionGamesCount = 0;
                }
            }
        }
예제 #2
0
 static void logParser_OnMetaData(GameLogParser source, string metaData)
 {
     //GameLogMetaData md = GameLogMetaData.Parse(metaData);
     if (!_cmdLine.RemoveMetadata)
     {
         _output.WriteLine(metaData);
     }
 }
예제 #3
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);
        }
예제 #4
0
        public void Test_ParseFile()
        {
            string        subdirName        = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            string        testResourcesPath = Path.Combine(Props.Global.Get("bds.TestDir"), subdirName);
            string        logFile           = Path.Combine(testResourcesPath, "gamelog1.log");
            GameLogParser parser            = new GameLogParser();

            parser.OnMetaData   += new GameLogParser.OnMetaDataHandler(parser_OnMetaData);
            parser.OnGameRecord += new GameLogParser.OnGameRecordHandler(parser_OnGameRecord);
            _eventCount          = 0;
            parser.ParseFile(logFile);
        }
예제 #5
0
        static void logParser_OnGameRecord(GameLogParser source, GameRecord gameRecord)
        {
            if (source.GamesCount > _cmdLine.GameLimit)
            {
                throw new GameLimitException();
            }

            if (!_transformer.Transform(gameRecord))
            {
                return;
            }
            _output.WriteLine(gameRecord.ToGameString());
        }
예제 #6
0
        void parser_OnGameRecord(GameLogParser source, GameRecord gameRecord)
        {
            switch (++_eventCount)
            {
            case 2:
                Assert.AreEqual("0", gameRecord.Id);
                break;

            case 4:
                Assert.AreEqual("1", gameRecord.Id);
                break;
            }
        }
예제 #7
0
        void parser_OnMetaData(GameLogParser source, string metaData)
        {
            switch (++_eventCount)
            {
            case 1:
                Assert.AreEqual("Meta-data1", metaData);
                break;

            case 3:
                Assert.AreEqual("Meta-data2", metaData);
                break;
            }
        }
예제 #8
0
        /// <summary>
        /// Compares two logs and returns true if they are equal.
        /// If there is a parsing error, throws an ApplicationException().
        /// </summary>
        /// <param name="hint">Contains a hint text about comparison result, e.g. "Games differ: ..."</param>
        /// <param name="count">Compare up to count logs. Set to int.MaxValue to compare all. Set to a negative value to
        /// compare up to the minimal size of the two logs.</param>
        public static bool Compare(string logFileName1, string logFileName2, out string hint, int count)
        {
            GameLogParser parser = new GameLogParser();

            ParsedLogs[] logs = new ParsedLogs[2] {
                new ParsedLogs(), new ParsedLogs()
            };


            for (int curLog = 0; curLog < 2; curLog++)
            {
                parser.OnError      += new GameLogParser.OnErrorHandler(logs[curLog].OnError);
                parser.OnGameRecord += new GameLogParser.OnGameRecordHandler(logs[curLog].OnGameRecord);
                parser.ParseFile(curLog == 0 ? logFileName1 : logFileName2);
                parser.OnError      -= new GameLogParser.OnErrorHandler(logs[curLog].OnError);
                parser.OnGameRecord -= new GameLogParser.OnGameRecordHandler(logs[curLog].OnGameRecord);
            }

            if (count < 0)
            {
                count = Math.Min(logs[0].Games.Count, logs[1].Games.Count);
            }

            int count0 = Math.Min(logs[0].Games.Count, count);
            int count1 = Math.Min(logs[1].Games.Count, count);

            if (count0 != count1)
            {
                hint = String.Format("Log sizes differ: {0} != {1}", count0, count1);
                return(false);
            }

            string[] gameStrings = new string[2];

            for (int g = 0; g < count0; ++g)
            {
                for (int l = 0; l < 2; l++)
                {
                    gameStrings[l] = logs[l].Games[g].ToString();
                }
                if (gameStrings[0] != gameStrings[1])
                {
                    hint = String.Format("Games differ:\n{0}\n{1}", gameStrings[0], gameStrings[1]);
                    return(false);
                }
            }
            hint = "Logs are equal";
            return(true);
        }
예제 #9
0
 static void logParser_OnGameRecord(GameLogParser source, GameRecord gameRecord)
 {
     if (source.GamesCount > _cmdLine.GameLimit)
     {
         throw new GameLimitException();
     }
     if (_sessionResult != null)
     {
         _sessionResult.Update(gameRecord);
     }
     if (_totalResult != null)
     {
         _totalResult.Update(gameRecord);
     }
     _sessionGamesCount++;
 }
예제 #10
0
        public void Test_Preview()
        {
            GameLogParser parser = new GameLogParser();

            parser.OnGameRecord += new GameLogParser.OnGameRecordHandler(parser_OnGameRecord);

            Props p = new Props(new string[] { "HeroName", "Patience", "PrintNuts", "true" });

            _report = new NutsReport();
            _report.Configure(p);

            parser.ParseFile(Path.Combine(_testResDir, "NutsReport_Log1.log"));
            Assert.AreEqual(0, parser.ErrorCount);

            _report.Print(Console.Out);
        }
예제 #11
0
        void logParser_OnGameRecord(GameLogParser source, GameRecord gameRecord)
        {
            int pos = -1;

            for (int p = 0; p < gameRecord.Players.Count; ++p)
            {
                if (gameRecord.Players[p].Name == _playerToImitate)
                {
                    pos = p;
                    break;
                }
            }

            foreach (PokerAction action in gameRecord.Actions)
            {
                if (action.Position == pos && action.IsPlayerAction())
                {
                    _actions.Add(action);
                }
            }
        }
예제 #12
0
        void logParser_OnGameRecord(GameLogParser source, GameRecord gameRecord)
        {
            if (!gameRecord.IsGameOver)
            {
                return;
            }

            _samplesCount++;
            if (_samplesCount >= _sampleLimit)
            {
                _sampleStep  *= 2;
                _sampleLimit *= 2;
            }

            CurveDescriptor cdKey = new CurveDescriptor();

            for (int pos = 0; pos < gameRecord.Players.Count; ++pos)
            {
                GameRecord.Player player = gameRecord.Players[pos];

                cdKey.Player   = player.Name;
                cdKey.Position = pos;

                CurveDescriptor curveDescriptor;

                if (!_curveDescriptors.TryGetValue(cdKey, out curveDescriptor))
                {
                    if (_autocreateCurveDescriptors)
                    {
                        curveDescriptor = new CurveDescriptor {
                            Player = player.Name, Position = -1
                        };
                        _curveDescriptors.Add(curveDescriptor, curveDescriptor);
                    }
                    else
                    {
                        // No curve for this player and position
                        continue;
                    }
                }


                double total;
                if (!_totalResult.TryGetValue(curveDescriptor, out total))
                {
                    total = 0;
                }
                total += player.Result;
                _totalResult[curveDescriptor] = total;

                curveDescriptor.SamplesCount++;

                // Add to the chart only samples from players from game record,
                // not from all from _totalResult, in order to see where a player
                // stops playing.

                if ((curveDescriptor.SamplesCount % _sampleStep) != 0)
                {
                    continue;
                }

                UpdateChart(curveDescriptor, total);
            }
        }
예제 #13
0
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                return(1);
            }
            _transformer = new TransformGameRecords();

            _outputName = _cmdLine.Output;
            if (String.IsNullOrEmpty(_outputName))
            {
                _outputName  = Path.Combine(Path.GetDirectoryName(_cmdLine.InputFile), Path.GetFileNameWithoutExtension(_cmdLine.InputFile));
                _outputName += "-tr" + Path.GetExtension(_cmdLine.InputFile);
            }

            _output = new StreamWriter(_outputName);

            if (!string.IsNullOrEmpty(_cmdLine.RenameEq))
            {
                string [] parts = _cmdLine.RenameEq.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                _transformer.RenameEqName    = parts[0];
                _transformer.RenameEqNewName = parts[1];
            }
            if (!string.IsNullOrEmpty(_cmdLine.RenameNeq))
            {
                string[] parts = _cmdLine.RenameNeq.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                _transformer.RenameNeqName    = parts[0];
                _transformer.RenameNeqNewName = parts[1];
            }

            _transformer.FinalizeGames = _cmdLine.FinalizeGames;
            if (_cmdLine.RenumerateGames)
            {
                _transformer.RenumerateGames = true;
                _transformer.GameCount       = 0;
            }
            _transformer.HideOpponentCards = _cmdLine.HideOpponentCards;
            _transformer.NormalizeCards    = _cmdLine.NormalizeCards;
            _transformer.ResetStacks       = _cmdLine.ResetStacks;
            _transformer.ResetResults      = _cmdLine.ResetResults;
            if (string.IsNullOrEmpty(_cmdLine.NormalizeStakes))
            {
                _transformer.NormalizeStakes = -1.0;
            }
            else
            {
                _transformer.NormalizeStakes = double.Parse(_cmdLine.NormalizeStakes, CultureInfo.InvariantCulture);
            }
            _transformer.HeroName          = _cmdLine.HeroName;
            _transformer.RemoveNoHeroMoves = _cmdLine.RemoveNoHeroMoves;
            _transformer.RemoveNoShowdown  = _cmdLine.RemoveNoShowdown;

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

            logParser.OnGameRecord += new GameLogParser.OnGameRecordHandler(logParser_OnGameRecord);
            logParser.OnMetaData   += new GameLogParser.OnMetaDataHandler(logParser_OnMetaData);
            try
            {
                logParser.ParseFile(_cmdLine.InputFile);
            }
            catch (GameLimitException)
            {
            }

            _output.Flush();

            _output.Close();

            return(0);
        }
예제 #14
0
 public void OnGameRecord(GameLogParser source, GameRecord gameRecord)
 {
     Games.Add(gameRecord);
 }
예제 #15
0
 static void logParser_OnGameRecord(GameLogParser source, GameRecord gameRecord)
 {
     _dealRecords.Add(new DealRecord(gameRecord, _deckDescr, _randomDealer));
 }
예제 #16
0
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                return(1);
            }

            if (_cmdLine.DebuggerLaunch)
            {
                Debugger.Launch();
            }

            _randomDealer = _cmdLine.RngSeed == 0 ? new SequenceRng() : new SequenceRng(_cmdLine.RngSeed);

            _deckDescr = XmlSerializerExt.Deserialize <DeckDescriptor>(Props.Global.Expand(_cmdLine.DeckDescriptorFile));

            GameLogParser logParser = new GameLogParser();

            logParser.OnGameRecord += new GameLogParser.OnGameRecordHandler(logParser_OnGameRecord);
            logParser.ParseFile(_cmdLine.ConfigFile);

            if (_cmdLine.EnumCount)
            {
                for (int r = 0; r < _dealRecords.Count; ++r)
                {
                    long[] counts = _dealRecords[r].EnumCombosCounts;
                    Console.Write("Rec #{0,2}: ", r);
                    if (counts.Length == 0)
                    {
                        Console.Write("N/A");
                    }
                    else
                    {
                        long total = 1;
                        for (int i = 0; i < counts.Length; ++i)
                        {
                            total *= counts[i];
                            Console.Write("{0}, ", counts[i]);
                        }
                        Console.Write("Total: {0}", total);
                    }
                    Console.WriteLine();
                }
                return(0);
            }

            int id = 0;

            for (int r = 0; r < _cmdLine.Repeat; ++r)
            {
                for (int g = 0; g < _dealRecords.Count; ++g)
                {
                    GameRecord completedDealRecord = _dealRecords[g].Generate(r);
                    completedDealRecord.Id = id.ToString();
                    ++id;
                    Console.Out.WriteLine(completedDealRecord);
                }
            }

            return(0);
        }
예제 #17
0
 void logParser_OnError(GameLogParser source, string error)
 {
     throw new ApplicationException(source.GetDefaultErrorText(error));
 }
예제 #18
0
 void parser_OnGameRecord(GameLogParser source, GameRecord gameRecord)
 {
     _report.Update(gameRecord);
 }
예제 #19
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);
        }
예제 #20
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);
                }
            }
        }
예제 #21
0
 void gameLogParser_OnGameRecord(GameLogParser source, GameRecord gameRecord)
 {
     _dealLog.Add(gameRecord);
 }