示例#1
0
        private PowerHistoryEntry ProcessShowEntity(PowerGame currentPowerGame, string contentLine)
        {
            string str = contentLine
                         .Replace("SHOW_ENTITY - Updating Entity=", "")
                         .Replace(" [cardType=INVALID]", "");

            Match match1 = showEntityRgx1.Match(str);
            Match match2 = showEntityRgx2.Match(str);

            if (match1.Success)
            {
                return(new PowerShowEntity()
                {
                    Id = Int32.Parse(match1.Groups[1].Value),
                    CardId = match1.Groups[2].Value
                });
            }

            if (match2.Success)
            {
                return(new PowerShowEntity()
                {
                    Name = match1.Groups[2].Value,
                    Id = Int32.Parse(match1.Groups[3].Value),
                    Zone = match1.Groups[4].Value,
                    ZonePos = match1.Groups[5].Value,
                    PlayerId = match1.Groups[6].Value,
                    CardId = match1.Groups[7].Value
                });
            }

            Console.WriteLine("entityRgx unmatched: '" + str + "'");
            return(null);
        }
示例#2
0
        private PowerBlockStart ProcessBlockStart(PowerGame powerGame, string str)
        {
            Match match1 = blockStartRgx.Match(str);

            if (!match1.Success)
            {
                Console.WriteLine("blockStartRgx unmatched: '" + str + "'");
                return(null);
            }

            string blockType    = match1.Groups[1].Value;
            string entity       = match1.Groups[2].Value;
            string effectCardId = match1.Groups[3].Value;
            string effectIndex  = match1.Groups[4].Value;
            string target       = match1.Groups[5].Value;

            int entityId = GetIdFromEntity(entity, powerGame);

            int targetId = GetIdFromEntity(target, powerGame);

            return(new PowerBlockStart()
            {
                BlockType = blockType,
            });
        }
示例#3
0
        static void Main(string[] args)
        {
            var interpreter        = new Interpreter(@"C:\Users\admin\Source\Repos\SabberStone\core-extensions\SabberStonePowerLog\resources\", "initialmulli.log");
            List <PowerGame> games = interpreter.Parse(true, true);

            Console.WriteLine($"Done parsing! Found {games.Count} game(s) in log.");
            Console.ReadKey();

            if (games.Any())
            {
                PowerGame game = games.Last();


                Console.WriteLine($"Starting a syncronized PowerGame!");

                while (game.PowerHistory.Count > 0)
                {
                    PowerHistoryEntry entry = game.PowerHistory.Dequeue();
                    Console.WriteLine($"Dequeue {entry.ToString()}.");
                    Console.ReadKey();
                    //entry.Process(game);
                }
                //var realGame = new SyncedGame(game);
                //realGame.Sync();
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            var interpreter        = new Interpreter(@"D:\Hearthstone\Logs\", "Power.log");
            List <PowerGame> games = interpreter.Parse(true, true);

            Console.WriteLine($"Done parsing! Found {games.Count} game(s) in log.");
            Console.ReadKey();

            if (games.Any())
            {
                PowerGame game = games.Last();


                Console.WriteLine($"Starting a syncronized PowerGame!");

                while (game.PowerHistory.Count > 0)
                {
                    PowerHistoryEntry entry = game.PowerHistory.Dequeue();
                    Console.WriteLine($"Dequeue {entry.ToString()}.");
                    Console.ReadKey();
                    //entry.Process(game);
                }
                //var realGame = new SyncedGame(game);
                //realGame.Sync();
            }
        }
示例#5
0
        private PowerHistoryEntry ProcessShowEntity(PowerGame currentPowerGame, string contentLine)
        {
            var str = contentLine
                      .Replace("SHOW_ENTITY - Updating Entity=", "")
                      .Replace(" [cardType=INVALID]", "");
            var match1 = showEntityRgx.Match(str);

            if (!match1.Success)
            {
                Console.WriteLine("entityRgx unmatched: '" + str + "'");
                return(null);
            }

            var id = 0;

            if (!int.TryParse(match1.Groups[1].Value, out id))
            {
                id = int.Parse(match1.Groups[3].Value);
            }

            return(new PowerShowEntity()
            {
                Name = match1.Groups[2].Value,
                Id = id,
                Zone = match1.Groups[4].Value,
                ZonePos = match1.Groups[5].Value,
                PlayerId = match1.Groups[6].Value,
                CardId = match1.Groups[7].Value
            });
        }
示例#6
0
        public override object VisitCompileUnit(HSGrammarParser.CompileUnitContext context)
        {
            PowerGame PowerGame = new PowerGame();

            foreach (HSGrammarParser.HsPowerLineContext hsPowerLine in context.hsPowerLine())
            {
                PowerGame.Entries.Enqueue(VisitHsPowerLine(hsPowerLine) as PowerLogEntry);
            }

            return(PowerGame);
        }
示例#7
0
        private PowerTagChange ProcessTagChange(PowerGame powerGame, string str)
        {
            Match match1 = tagValueRgx.Match(str);
            Match match2 = idRgx.Match(str);

            if (!match1.Success || !match2.Success)
            {
                Console.WriteLine("tagValueRgx or idRgx unmatched: '" + str + "'");
                return(null);
            }

            string tag    = match1.Groups[1].Value;
            string value  = match1.Groups[2].Value;
            string entity = match2.Groups[2].Value;
            int    id;

            if (!int.TryParse(entity, out id))
            {
                if (powerGame.Game.Name == null)
                {
                    id = 1;
                    powerGame.Game.Name = entity;
                    Console.WriteLine("Game " + entity);
                }
                else if (powerGame.Player1.Name == null)
                {
                    id = 2;
                    powerGame.Player1.Name = entity;
                    Console.WriteLine("Player1: " + entity);
                }
                else if (powerGame.Player2.Name == null)
                {
                    id = 3;
                    powerGame.Player2.Name = entity;
                    Console.WriteLine("Player2: " + entity);
                }
                else
                {
                    id = powerGame.GetIdByName(entity);
                }
            }

            return(new PowerTagChange()
            {
                Id = id,
                Tag = tag,
                Value = value
            });
        }
示例#8
0
        private int GetIdFromEntity(string str, PowerGame powerGame)
        {
            int result;

            if (!int.TryParse(str, out result))
            {
                Match match = idRgx.Match(str);
                if (match.Success)
                {
                    result = int.Parse(match.Groups[2].Value);
                }
                else
                {
                    result = powerGame.GetIdByName(str);
                }
            }
            return(result);
        }
示例#9
0
        private PowerFullEntity ProcessFullEntity(PowerGame powerGame, string str)
        {
            Match match = fullEntityRgx.Match(str);

            if (!match.Success)
            {
                Console.WriteLine("fullEntityRgx unmatched: '" + str + "'");
                return(null);
            }
            int    id     = int.Parse(match.Groups[1].Value);
            string cardId = match.Groups[2].Value;

            return(new PowerFullEntity()
            {
                Id = id,
                CardId = cardId
            });
        }
示例#10
0
        private PowerHistoryEntry ProcessHideEntity(PowerGame currentPowerGame, string contentLine)
        {
            string str = contentLine
                         .Replace("HIDE_ENTITY - Entity=", "");
            Match match1 = hideEntityRgx.Match(str);

            if (!match1.Success)
            {
                Console.WriteLine("hideEntityRgx unmatched: '" + str + "'");
                return(null);
            }

            return(new PowerHideEntity()
            {
                Name = match1.Groups[1].Value,
                Id = int.Parse(match1.Groups[2].Value),
                Zone = match1.Groups[3].Value,
                ZonePos = match1.Groups[4].Value,
                CardId = match1.Groups[5].Value,
                PlayerId = match1.Groups[6].Value,
                Tag = match1.Groups[7].Value,
                Value = match1.Groups[8].Value
            });
        }
示例#11
0
        static void Main(string[] args)
        {
            var interpreter = new Interpreter(@"C:\Users\admin\Source\Repos\SabberStone\SabberStonePowerLog\Files\", "Power.log");
            var games       = interpreter.Parse(true, true);

            Console.WriteLine($"Done parsing! Found {games.Count} game(s) in log.");
            Console.ReadKey();

            if (games.Any())
            {
                PowerGame game = games.Last();

                Console.WriteLine($"Starting a syncronized PowerGame!");

                while (game.PowerHistory.Count > 0)
                {
                    var entry = game.PowerHistory.Dequeue();

                    Console.WriteLine($"Dequeue {entry}.");

                    Console.ReadKey();
                }
            }
        }
示例#12
0
        public List <PowerGame> Parse(bool createJsonFile, bool createCleanLog)
        {
            List <PowerGame>         powerGames        = new List <PowerGame>();
            PowerState               currentPowerState = PowerState.Start;
            PowerGame                currentPowerGame  = null;
            PowerType                currentPowerType  = 0;
            Dictionary <string, int> currentNameToIdDict;
            PowerHistoryEntry        currentPowerHistoryEntry = null;
            StringBuilder            cleanLog = new StringBuilder();

            string line;

            while ((line = file.ReadLine()) != null)
            {
                Match matchLogRgx = logRgx.Match(line);
                if (matchLogRgx.Success)
                {
                    string entryType = matchLogRgx.Groups[1].Value;
                    string timestamp = matchLogRgx.Groups[2].Value;
                    string classType = matchLogRgx.Groups[3].Value;
                    string debugType = matchLogRgx.Groups[4].Value;
                    string content   = matchLogRgx.Groups[5].Value;

                    if (!classType.Equals("GameState") || debugType.Equals("DebugPrintOptions"))
                    {
                        continue;
                    }

                    string contentLine = content.Trim();

                    cleanLog.AppendLine($"{("[" + debugType.ToString() + "] ").PadLeft(27)}{content}");

                    PowerType nextPowerType;
                    if (Enum.TryParse <PowerType>(contentLine.Split(' ')[0], out nextPowerType))
                    {
                        currentPowerType = nextPowerType;
                    }
                    ;

                    switch (currentPowerType)
                    {
                    case PowerType.CREATE_GAME:
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("matchLogRgx: '" + line + "'");
                }
            }

            if (createJsonFile)
            {
                string jsonStr = JsonConvert.SerializeObject(powerGames, Formatting.Indented,
                                                             new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.All
                });
                File.WriteAllText(filePath + "powerLog.json", jsonStr);
            }

            if (createCleanLog)
            {
                File.WriteAllText(filePath + "cleanLog.log", cleanLog.ToString());
            }

            //while (powerGame.PowerHistory.Count > 0)
            //{
            //    var powerHistoryEntry = powerGame.PowerHistory.Dequeue();
            //    powerHistoryEntry.Process(powerGame);
            //}
            //File.WriteAllText(filePath + "powerLogProc.json", JsonConvert.SerializeObject(powerGame, Formatting.Indented));

            return(powerGames);
        }
示例#13
0
 private PowerBlockEnd ProcessBlockEnd(PowerGame powerGame, string str)
 {
     return(new PowerBlockEnd());
 }
示例#14
0
        public List <PowerGame> Parse(bool createJsonFile, bool createCleanLog)
        {
            List <PowerGame>         powerGames        = new List <PowerGame>();
            PowerState               currentPowerState = PowerState.Start;
            PowerGame                currentPowerGame  = null;
            PowerType                currentPowerType  = 0;
            Dictionary <string, int> currentNameToIdDict;
            PowerHistoryEntry        currentPowerHistoryEntry = null;
            StringBuilder            cleanLog = new StringBuilder();

            string line;

            while ((line = file.ReadLine()) != null)
            {
                Match matchLogRgx = logRgx.Match(line);
                if (matchLogRgx.Success)
                {
                    string entryType = matchLogRgx.Groups[1].Value;
                    string timestamp = matchLogRgx.Groups[2].Value;
                    string classType = matchLogRgx.Groups[3].Value;
                    string debugType = matchLogRgx.Groups[4].Value;
                    string content   = matchLogRgx.Groups[5].Value;

                    if (!classType.Equals("GameState"))                     //|| !debugType.Equals("DebugPrintPower"))
                    {
                        continue;
                    }

                    string contentLine = content.Trim();

                    cleanLog.AppendLine($"{("[" + debugType.ToString() + "] ").PadLeft(27)}{content}");

                    PowerType nextPowerType;
                    if (Enum.TryParse <PowerType>(contentLine.Split(' ')[0], out nextPowerType))
                    {
                        currentPowerType = nextPowerType;
                    }
                    ;

                    switch (currentPowerType)
                    {
                    case PowerType.CREATE_GAME:
                        break;
                    }

                    if (contentLine.StartsWith("CREATE_GAME"))
                    {
                        currentPowerState        = PowerState.CreateGame;
                        currentPowerGame         = new PowerGame();
                        currentNameToIdDict      = new Dictionary <string, int>();
                        currentPowerHistoryEntry = new PowerCreateGame();
                        currentPowerGame.PowerHistory.Enqueue(currentPowerHistoryEntry);
                        powerGames.Add(currentPowerGame);
                    }
                    else if (contentLine.StartsWith("Player"))
                    {
                        currentPowerState = PowerState.CreateGamePlayer;
                        var    createGame = currentPowerHistoryEntry as PowerCreateGame;
                        Player player     = new Player();
                        createGame.Players.Add(player);
                        if (createGame.Players.Count == 1)
                        {
                            currentPowerGame.Player1 = player;
                        }
                        else if (createGame.Players.Count == 2)
                        {
                            currentPowerGame.Player2 = player;
                        }
                    }
                    else if (contentLine.StartsWith("GameEntity"))
                    {
                        currentPowerState = PowerState.CreateGameGameEntity;
                        GameEntity game = new GameEntity();
                        currentPowerGame.Game = game;
                        (currentPowerHistoryEntry as PowerCreateGame).Game = game;
                    }
                    else if (contentLine.StartsWith("FULL_ENTITY"))
                    {
                        currentPowerState        = PowerState.FullEntity;
                        currentPowerHistoryEntry = ProcessFullEntity(currentPowerGame, contentLine);
                        if (currentPowerHistoryEntry != null)
                        {
                            currentPowerGame.PowerHistory.Enqueue(currentPowerHistoryEntry);
                        }
                    }
                    else if (contentLine.StartsWith("TAG_CHANGE"))
                    {
                        currentPowerState        = PowerState.TagChange;
                        currentPowerHistoryEntry = ProcessTagChange(currentPowerGame, contentLine);
                        if (currentPowerHistoryEntry != null)
                        {
                            currentPowerGame.PowerHistory.Enqueue(currentPowerHistoryEntry);
                        }
                    }
                    else if (contentLine.StartsWith("BLOCK_START"))
                    {
                        currentPowerState        = PowerState.BlockStart;
                        currentPowerHistoryEntry = ProcessBlockStart(currentPowerGame, contentLine);
                        if (currentPowerHistoryEntry != null)
                        {
                            currentPowerGame.PowerHistory.Enqueue(currentPowerHistoryEntry);
                        }
                    }
                    else if (contentLine.StartsWith("BLOCK_END"))
                    {
                        currentPowerState        = PowerState.BlockEnd;
                        currentPowerHistoryEntry = ProcessBlockEnd(currentPowerGame, contentLine);
                        if (currentPowerHistoryEntry != null)
                        {
                            currentPowerGame.PowerHistory.Enqueue(currentPowerHistoryEntry);
                        }
                    }
                    else if (contentLine.StartsWith("HIDE_ENTITY"))
                    {
                        currentPowerState        = PowerState.HideEntity;
                        currentPowerHistoryEntry = ProcessHideEntity(currentPowerGame, contentLine);
                        if (currentPowerHistoryEntry != null)
                        {
                            currentPowerGame.PowerHistory.Enqueue(currentPowerHistoryEntry);
                        }
                    }
                    else if (contentLine.StartsWith("SHOW_ENTITY"))
                    {
                        currentPowerState        = PowerState.ShowEntity;
                        currentPowerHistoryEntry = ProcessShowEntity(currentPowerGame, contentLine);
                        if (currentPowerHistoryEntry != null)
                        {
                            currentPowerGame.PowerHistory.Enqueue(currentPowerHistoryEntry);
                        }
                    }
                    else if (contentLine.StartsWith("META_DATA"))
                    {
                        currentPowerState = PowerState.MetaData;
                    }
                    else if (contentLine.StartsWith("Info["))
                    {
                    }
                    else if (contentLine.StartsWith("tag="))
                    {
                        Match matchTagValueRgx = tagValueRgx.Match(contentLine);
                        if (matchTagValueRgx.Success)
                        {
                            string tag   = matchTagValueRgx.Groups[1].Value;
                            string value = matchTagValueRgx.Groups[2].Value;

                            switch (currentPowerState)
                            {
                            case PowerState.CreateGameGameEntity:
                                (currentPowerHistoryEntry as PowerCreateGame).Game.Add(tag, value);
                                break;

                            case PowerState.CreateGamePlayer:
                                (currentPowerHistoryEntry as PowerCreateGame).Players.Last().Add(tag, value);
                                break;

                            case PowerState.FullEntity:
                                (currentPowerHistoryEntry as PowerFullEntity).PowerEntity.Add(tag, value);
                                break;

                            default:
                                //Console.WriteLine("Found unimplemented currentPowerState case: '" + currentPowerState + "'");
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Found uninterpreted contentLine: '" + contentLine + "'");
                        }
                    }
                    else
                    {
                        Console.WriteLine($"[{debugType}] unhandled line: '{contentLine}'");
                    }
                }
                else
                {
                    Console.WriteLine("matchLogRgx: '" + line + "'");
                }
            }

            if (createJsonFile)
            {
                string jsonStr = JsonConvert.SerializeObject(powerGames, Formatting.Indented,
                                                             new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.All
                });
                File.WriteAllText(filePath + "powerLog.json", jsonStr);
            }

            if (createCleanLog)
            {
                File.WriteAllText(filePath + "cleanLog.log", cleanLog.ToString());
            }

            //while (powerGame.PowerHistory.Count > 0)
            //{
            //    var powerHistoryEntry = powerGame.PowerHistory.Dequeue();
            //    powerHistoryEntry.Process(powerGame);
            //}
            //File.WriteAllText(filePath + "powerLogProc.json", JsonConvert.SerializeObject(powerGame, Formatting.Indented));

            return(powerGames);
        }
示例#15
0
 public override void Process(PowerGame powerGame)
 {
     powerGame.Entities[Id].Change("CARD_ID", CardId);
 }
示例#16
0
        static void Main(string[] args)
        {
            string path       = @"C:\Users\admin\Source\Repos\SabberStone\core-extensions\HSGrammar\File\";
            Regex  logPattern = new Regex(@"[D][ ][0-9]{2}[:][0-9]{2}[:][0-9]{2}[.][0-9]{7}[ ](GameState|PowerTaskList|PowerProcessor)[.](DebugDump|DebugPrintPower|DebugPrintPowerList|PrepareHistoryForCurrentTaskList|DebugPrintEntityChoices|EndCurrentTaskList|DebugPrintEntitiesChosen|SendChoices|SendOption|DebugPrintOptions|DoTaskListForCard)[\(][\)][ ][-][ ]*(.*)");
            var    listLines  = File.ReadAllLines(path + "Power.log").ToList();

            var gameStrs = new List <StringBuilder>();
            int index    = 0;

            listLines.ForEach(p =>
            {
                Match logMatch = logPattern.Match(p);
                if (logMatch.Success)
                {
                    string logType1 = logMatch.Groups[1].Value;
                    string logType2 = logMatch.Groups[2].Value;
                    string logEntry = logMatch.Groups[3].Value;

                    if (logType1 == "GameState" && (logType2 == "DebugPrintPower" || logType2 == "DebugPrintEntityChoices" || logType2 == "SendChoices" || logType2 == "SendOption" || logType2 == "DebugPrintOptions"))
                    {
                        if (logEntry.StartsWith("CREATE_GAME"))
                        {
                            gameStrs.Add(new StringBuilder());
                        }

                        gameStrs.Last()?.AppendLine(logEntry);
                    }
                    else
                    {
                        // ignore
                    }
                }
                else
                {
                    Console.WriteLine("unsuccessful logMatch: " + p);
                    Console.ReadKey();
                }
            });

            // writing files
            gameStrs.ForEach(p => WriteFile(path + $"GameLog{gameStrs.IndexOf(p)}.log", p.ToString()));

            Console.WriteLine("Starting parsing process now! (Press key)");
            Console.ReadKey();

            gameStrs.ForEach(p => {
                try
                {
                    AntlrInputStream inputStream        = new AntlrInputStream(p.ToString());
                    HSGrammarLexer hsLexer              = new HSGrammarLexer(inputStream);
                    CommonTokenStream commonTokenStream = new CommonTokenStream(hsLexer);
                    HSGrammarParser hsParser            = new HSGrammarParser(commonTokenStream);

                    HSGrammarParser.CompileUnitContext compileUnit = hsParser.compileUnit();
                    HsGrammarVisitor visitor = new HsGrammarVisitor();
                    PowerGame powerGame      = visitor.Visit(compileUnit) as PowerGame;
                    WriteFile(path + $"GameLog{gameStrs.IndexOf(p)}.json", JsonConvert.SerializeObject(powerGame, Formatting.Indented));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: " + ex);
                    Console.ReadKey();
                }
            });


            Console.WriteLine("Finished! (Press key)");
            Console.ReadKey();
        }
示例#17
0
 public SyncedGame(PowerGame powerGame) : base(new GameConfig())
 {
     _powerGame = powerGame;
 }