Пример #1
0
        public bool Parse(State.Game game, State.ReadOnlyEntity target)
        {
            bool ret = true;

            foreach (var entity in game.Entities.Items)
            {
                if (!entity.Value.HasTag(State.GameTag.CARDTYPE))
                {
                    continue;
                }
                var card_type = (State.TAG_CARDTYPE)entity.Value.GetTag(State.GameTag.CARDTYPE);

                if (card_type != State.TAG_CARDTYPE.ENCHANTMENT)
                {
                    continue;
                }

                if (entity.Value.GetTagOrDefault(State.GameTag.ATTACHED, target.Id - 1) != target.Id)
                {
                    continue;
                }

                var enchant = new Enchantment();
                ret = enchant.Parse(game, entity.Value) && ret;
                this.Add(enchant);
            }

            return(ret);
        }
Пример #2
0
 public LogReader(string hearthstone_path, State.Game game_state, Logger logger)
 {
     logger_ = logger;
     this.hearthstone_path = hearthstone_path;
     this.game_state_      = game_state;
     this.Reset();
 }
Пример #3
0
        public LogParser(State.Game game_state, Logger logger)
        {
            logger_     = logger;
            game_state_ = game_state;

            this.power_log_parser           = new SubParsers.PowerLogParser(game_state_, logger_);
            this.entity_choices_parser      = new SubParsers.EntityChoicesParser(game_state_, logger_);
            this.send_choices_parser        = new SubParsers.SendChoicesParser(game_state_, logger_);
            this.debug_print_power_parser   = new SubParsers.DebugPrintPowerParser(game_state_, logger_);
            this.debug_print_options_parser = new SubParsers.DebugPrintOptions(logger_);

            this.power_log_parser.BlockStart += (sender, e) =>
            {
                if (this.BlockStart != null)
                {
                    this.BlockStart(this, e);
                }
            };
            this.power_log_parser.BlockEnd         += (sender, e) => this.BlockEnd(sender, e);
            this.power_log_parser.EntityTagChanged += (sender, e) => this.EntityTagChanged(sender, e);
            this.power_log_parser.CreateGameEvent  += (sender, e) =>
            {
                if (this.CreateGameEvent != null)
                {
                    this.CreateGameEvent(this, e);
                }
            };
            this.debug_print_options_parser.StartWaitingMainAction += (sender, e) =>
            {
                if (this.StartWaitingMainActionEvent != null)
                {
                    this.StartWaitingMainActionEvent(sender, e);
                }
            };
        }
Пример #4
0
        public bool Parse(State.Game game, State.ReadOnlyEntity player)
        {
            bool ret = true;

            int controller = player.GetTagOrDefault(State.GameTag.CONTROLLER, -1);

            if (controller < 0)
            {
                return(false);
            }

            foreach (var entity in game.Entities.Items)
            {
                if (entity.Value.GetTagOrDefault(State.GameTag.CONTROLLER, controller - 1) != controller)
                {
                    continue;
                }

                if (!entity.Value.HasTag(State.GameTag.ZONE))
                {
                    continue;
                }
                if (entity.Value.GetTag(State.GameTag.ZONE) != (int)State.TAG_ZONE.SECRET)
                {
                    continue;
                }

                Secret secret = new Secret();
                ret = secret.Parse(game, entity.Value) && ret;
                this.Add(secret);
            }

            return(ret);
        }
Пример #5
0
        public bool Parse(State.Game game, State.ReadOnlyEntity entity)
        {
            bool ret = true;

            this.entity_id = entity.Id;
            this.card_id   = entity.CardId;

            this.max_hp = entity.GetTagOrDefault(State.GameTag.HEALTH, -1);
            this.damage = entity.GetTagOrDefault(State.GameTag.DAMAGE, 0);
            this.armor  = entity.GetTagOrDefault(State.GameTag.ARMOR, 0);

            this.attack            = entity.GetTagOrDefault(State.GameTag.ATK, 0);
            this.attacks_this_turn = entity.GetTagOrDefault(State.GameTag.NUM_ATTACKS_THIS_TURN, 0);

            ret = this.status.Parse(game, entity) && ret;

            State.ReadOnlyEntity hero_power;
            if (game.TryGetPlayerHeroPowerEntity(entity.Id, out hero_power))
            {
                this.hero_power.Parse(game, hero_power);
            }
            else
            {
                ret = false;
            }

            ret = this.enchantments.Parse(game, entity) && ret;

            return(ret);
        }
Пример #6
0
        public bool Parse(State.Game game, State.ReadOnlyEntity player)
        {
            bool ret = true;

            int controller = player.GetTagOrDefault(State.GameTag.CONTROLLER, -1);

            if (controller < 0)
            {
                return(false);
            }

            SortedDictionary <int, Minion> sorted_minions = new SortedDictionary <int, Minion>();

            foreach (var entity in game.Entities.Items)
            {
                if (entity.Value.GetTagOrDefault(State.GameTag.CONTROLLER, controller - 1) != controller)
                {
                    continue;
                }

                if (!entity.Value.HasTag(State.GameTag.ZONE))
                {
                    continue;
                }
                if (entity.Value.GetTag(State.GameTag.ZONE) != (int)State.TAG_ZONE.PLAY)
                {
                    continue;
                }

                if (!entity.Value.HasTag(State.GameTag.CARDTYPE))
                {
                    continue;
                }
                var card_type = (State.TAG_CARDTYPE)entity.Value.GetTag(State.GameTag.CARDTYPE);

                if (card_type != State.TAG_CARDTYPE.MINION)
                {
                    continue;
                }

                var zone_pos = entity.Value.GetTagOrDefault(State.GameTag.ZONE_POSITION, -1);
                if (zone_pos < 0)
                {
                    ret = false;
                }

                Minion minion = new Minion();
                ret = minion.Parse(game, entity.Value) && ret;

                sorted_minions.Add(zone_pos, minion);
            }

            foreach (var sorted_minion in sorted_minions)
            {
                this.Add(sorted_minion.Value);
            }

            return(true);
        }
Пример #7
0
        public bool Parse(State.Game game, State.ReadOnlyEntity entity)
        {
            this.entity_id = entity.Id;
            this.card_id   = entity.CardId;
            this.used      = (entity.GetTagOrDefault(State.GameTag.EXHAUSTED, 0) != 0);

            return(true);
        }
Пример #8
0
        public bool Parse(State.Game game, State.ReadOnlyEntity enchant)
        {
            this.entity_id         = enchant.Id;
            this.card_id           = enchant.CardId;
            this.creator_entity_id = enchant.GetTagOrDefault(State.GameTag.CREATOR, -1);

            return(true);
        }
Пример #9
0
        public bool Parse(State.Game game, State.ReadOnlyEntity player)
        {
            bool ret = true;

            this.equipped = false;

            int controller = player.GetTagOrDefault(State.GameTag.CONTROLLER, -1);

            if (controller < 0)
            {
                return(false);
            }

            foreach (var entity in game.Entities.Items)
            {
                if (entity.Value.GetTagOrDefault(State.GameTag.CONTROLLER, controller - 1) != controller)
                {
                    continue;
                }

                if (!entity.Value.HasTag(State.GameTag.ZONE))
                {
                    continue;
                }
                if (entity.Value.GetTag(State.GameTag.ZONE) != (int)State.TAG_ZONE.PLAY)
                {
                    continue;
                }

                if (!entity.Value.HasTag(State.GameTag.CARDTYPE))
                {
                    continue;
                }
                var card_type = (State.TAG_CARDTYPE)entity.Value.GetTag(State.GameTag.CARDTYPE);

                if (card_type != State.TAG_CARDTYPE.WEAPON)
                {
                    continue;
                }

                if (this.equipped)
                {
                    // equip two weapons!
                    return(false);
                }

                this.entity_id  = entity.Value.Id;
                this.card_id    = entity.Value.CardId;
                this.attack     = entity.Value.GetTagOrDefault(State.GameTag.ATK, 0);
                this.durability = entity.Value.GetTagOrDefault(State.GameTag.DURABILITY, 0);
                this.damage     = entity.Value.GetTagOrDefault(State.GameTag.DAMAGE, 0);
                ret             = this.enchantments.Parse(game, entity.Value) && ret;

                this.equipped = true;
            }

            return(ret);
        }
Пример #10
0
        public void Reset(string hearthstone_path)
        {
            game_state_ = new State.Game();

            this.stable_decider_ = new StableDecider(100); // 100 ms

            this.log_reader = new LogReader(hearthstone_path, game_state_, logger_);
            this.log_reader.StartWaitingMainActionEvent += StartWaitingMainAction;
            this.log_reader.BlockStart += (sender, e) =>
            {
                game_state_.NotifyBlockStarted(e.entity_id, e.block_type);

                if (this.BlockStart != null)
                {
                    this.BlockStart(this, new BlockStartEventArgs(e, game_state_));
                }
            };
            this.log_reader.BlockEnd += (sender, e) =>
            {
                game_state_.NotifyBlockEnded(e.entity_id, e.block_type, logger_);

                if (e.block_type == "PLAY")
                {
                    AnalyzePlayHandCardAction(e.entity_id);
                }

                if (this.BlockEnd != null)
                {
                    this.BlockEnd(this, new BlockEndEventArgs(e, game_state_));
                }
            };
            this.log_reader.CreateGameEvent += (sender, e) =>
            {
                // if game is auto-restarted, we don't want to reset the game info
                // because this loses the player/opponent's entity id
                game_state_.SoftReset();

                CreateGameEvent(sender, e);
            };
            this.log_reader.log_changed = () =>
            {
                stable_decider_.Changed();
            };
            this.log_reader.EntityTagChanged += (sender, e) =>
            {
                game_state_.NotifyEntityTagChanged(e.current.Id, e.prev, logger_);
            };

            game_state_.EndTurnEvent += (sender, e) =>
            {
                if (this.EndTurnEvent != null)
                {
                    this.EndTurnEvent(this, new EndTurnEventArgs(e, game_state_));
                }
            };
        }
Пример #11
0
        public bool Parse(State.Game game, State.ReadOnlyEntity entity)
        {
            this.total     = entity.GetTagOrDefault(State.GameTag.RESOURCES, 0);
            this.this_turn = entity.GetTagOrDefault(State.GameTag.TEMP_RESOURCES, 0);
            this.used      = entity.GetTagOrDefault(State.GameTag.RESOURCES_USED, 0);

            this.overload           = entity.GetTagOrDefault(State.GameTag.OVERLOAD_LOCKED, 0);
            this.overload_next_turn = entity.GetTagOrDefault(State.GameTag.OVERLOAD_OWED, 0);

            return(true);
        }
Пример #12
0
        static public int GetEntityIdFromRawString(State.Game game_state, string entity_raw, out string entity_str)
        {
            entity_raw = entity_raw.Replace("UNKNOWN ENTITY ", "");
            int entityId = -1;

            entity_str = "";

            // Get entity id - Method 1
            if (entity_raw.StartsWith("[") && EntityRegex.IsMatch(entity_raw))
            {
                entityId = int.Parse(EntityRegex.Match(entity_raw).Groups["id"].Value);
            }

            // Get entity id - Method 2
            if (entityId < 0)
            {
                if (!int.TryParse(entity_raw, out entityId))
                {
                    entityId = -1;
                }
            }

            // Get entity id - Method 3
            if (entityId < 0)
            {
                string entity_str_try = entity_raw;
                var    entity         = game_state.Entities.Items.FirstOrDefault(x => x.Value.Name == entity_str_try);
                if (entity.Value != null)
                {
                    entityId   = entity.Key;
                    entity_str = entity_str_try;
                }
                else
                {
                    entity_str_try = "UNKNOWN HUMAN PLAYER";
                    entity         = game_state.Entities.Items.FirstOrDefault(x => x.Value.Name == entity_str_try);
                    if (entity.Value != null)
                    {
                        entityId   = entity.Key;
                        entity_str = entity_str_try;
                        game_state.ChangeEntityName(entityId, entity_str_try);
                    }
                    else
                    {
                        entity_str = entity_raw;
                    }
                }
            }

            return(entityId);
        }
Пример #13
0
 public bool Parse(State.Game game)
 {
     foreach (var block in game.blocks_)
     {
         this.Add(new BlockInfo()
         {
             id        = block.Value.block_id,
             parent_id = block.Value.parent_block_id,
             type      = block.Value.block_type,
             entity_id = block.Value.entity_id
         });
     }
     return(true);
 }
Пример #14
0
        public bool Parse(State.Game game, State.ReadOnlyEntity entity)
        {
            bool ret = true;

            ret = this.ParseOneStatus(entity, State.GameTag.CHARGE, out this.charge) && ret;
            ret = this.ParseOneStatus(entity, State.GameTag.TAUNT, out this.taunt) && ret;
            ret = this.ParseOneStatus(entity, State.GameTag.DIVINE_SHIELD, out this.divine_shield) && ret;
            ret = this.ParseOneStatus(entity, State.GameTag.STEALTH, out this.stealth) && ret;
            ret = this.ParseOneStatus(entity, State.GameTag.FORGETFUL, out this.forgetful) && ret;
            ret = this.ParseOneStatus(entity, State.GameTag.FREEZE, out this.freeze) && ret;
            ret = this.ParseOneStatus(entity, State.GameTag.FROZEN, out this.frozen) && ret;
            ret = this.ParseOneStatus(entity, State.GameTag.POISONOUS, out this.poisonous) && ret;
            ret = this.ParseOneStatus(entity, State.GameTag.WINDFURY, out this.windfury) && ret;

            return(ret);
        }
Пример #15
0
        public bool Parse(State.Game game, State.ReadOnlyEntity entity)
        {
            bool ret = true;

            this.entity_id = entity.Id;
            this.card_id   = entity.CardId;
            if (entity.HasTag(State.GameTag.CLASS) == false)
            {
                this.@class = "";
            }
            else
            {
                this.@class = ((State.TAG_CLASS)entity.GetTag(State.GameTag.CLASS)).ToString();
            }

            return(ret);
        }
Пример #16
0
        public bool Parse(State.Game game)
        {
            foreach (var obj in game.Entities.Items)
            {
                while (obj.Key >= this.Count)
                {
                    this.Add(new Entity());
                }

                if (!this[obj.Key].Parse(game, obj.Value))
                {
                    return(false);
                }
            }

            return(true);
        }
Пример #17
0
        public bool Parse(State.Game game, State.ReadOnlyEntity player)
        {
            bool ret = true;

            int controller = player.GetTagOrDefault(State.GameTag.CONTROLLER, -1);

            if (controller < 0)
            {
                return(false);
            }

            SortedDictionary <int, int> sorted_cards = new SortedDictionary <int, int>();

            foreach (var entity in game.Entities.Items)
            {
                if (entity.Value.GetTagOrDefault(State.GameTag.CONTROLLER, controller - 1) != controller)
                {
                    continue;
                }

                if (!entity.Value.HasTag(State.GameTag.ZONE))
                {
                    continue;
                }
                if (entity.Value.GetTag(State.GameTag.ZONE) != (int)State.TAG_ZONE.HAND)
                {
                    continue;
                }

                var zone_pos = entity.Value.GetTagOrDefault(State.GameTag.ZONE_POSITION, -1);
                if (zone_pos < 0)
                {
                    ret = false;
                }

                sorted_cards.Add(zone_pos, entity.Value.Id);
            }

            foreach (var sorted_card in sorted_cards)
            {
                this.entities.Add(sorted_card.Value);
            }

            return(ret);
        }
Пример #18
0
        public bool Parse(State.Game game, State.ReadOnlyEntity entity)
        {
            bool ret = true;

            entity_id = entity.Id;

            ret = this.crystal.Parse(game, entity) && ret;

            this.fatigue = entity.GetTagOrDefault(State.GameTag.FATIGUE, 0);

            this.first_player = (entity.GetTagOrDefault(State.GameTag.FIRST_PLAYER, 0) != 0);

            ret = this.enchantments.Parse(game, entity) && ret;

            if (entity.HasTag(State.GameTag.HERO_ENTITY) == false)
            {
                ret = false;
            }
            else
            {
                int hero_entity_id = entity.GetTag(State.GameTag.HERO_ENTITY);
                if (game.Entities.Items.ContainsKey(hero_entity_id) == false)
                {
                    ret = false;
                }
                else
                {
                    ret = this.hero.Parse(game, game.Entities.Items[hero_entity_id]) && ret;
                }
            }

            ret = this.weapon.Parse(game, entity) && ret;

            ret = this.secrets.Parse(game, entity) && ret;

            ret = this.minions.Parse(game, entity) && ret;

            ret = this.hand.Parse(game, entity) && ret;

            ret = this.deck.Parse(game, entity) && ret;

            return(ret);
        }
Пример #19
0
        public bool Parse(State.Game game, State.ReadOnlyEntity entity)
        {
            this.entity_id = entity.Id;
            this.card_id   = entity.CardId;

            this.max_hp             = entity.GetTagOrDefault(State.GameTag.HEALTH, -1);
            this.damage             = entity.GetTagOrDefault(State.GameTag.DAMAGE, 0);
            this.attack             = entity.GetTagOrDefault(State.GameTag.ATK, 0);
            this.attacks_this_turn  = entity.GetTagOrDefault(State.GameTag.NUM_ATTACKS_THIS_TURN, 0);
            this.exhausted          = (entity.GetTagOrDefault(State.GameTag.EXHAUSTED, 0) != 0);
            this.silenced           = (entity.GetTagOrDefault(State.GameTag.SILENCED, 0) != 0);
            this.spellpower         = entity.GetTagOrDefault(State.GameTag.SPELLPOWER, 0);
            this.summoned_this_turn = entity.GetTagOrDefault(State.GameTag.JUST_PLAYED, 0) != 0;

            this.status.Parse(game, entity);
            this.enchantments.Parse(game, entity);

            return(true);
        }
Пример #20
0
        public bool Parse(State.Game game, State.ReadOnlyEntity entity)
        {
            this.id = entity.Id;

            this.card_id    = entity.CardId;
            this.controller = entity.GetTagOrDefault(State.GameTag.CONTROLLER, -1);

            this.generate_under_blocks = new EntityGenerationInfo();
            foreach (var obj in entity.generate_under_blocks_)
            {
                this.generate_under_blocks.Add(obj);
            }

            tags = new Dictionary <string, int>();
            foreach (var kv in entity.Tags)
            {
                tags[kv.Key.ToString()] = kv.Value;
            }

            return(true);
        }
Пример #21
0
        public bool Parse(State.Game game)
        {
            State.ReadOnlyEntity game_entity;
            if (!game.TryGetGameEntity(out game_entity))
            {
                return(false);
            }
            this.turn = game_entity.GetTagOrDefault(State.GameTag.TURN, 0);

            if (!blocks.Parse(game))
            {
                return(false);
            }
            if (!entities.Parse(game))
            {
                return(false);
            }

            State.ReadOnlyEntity player_entity;
            if (!game.TryGetPlayerEntity(out player_entity))
            {
                return(false);
            }
            if (!this.player.Parse(game, player_entity))
            {
                return(false);
            }

            State.ReadOnlyEntity opponent_entity;
            if (!game.TryGetOpponentEntity(out opponent_entity))
            {
                return(false);
            }
            if (!this.opponent.Parse(game, opponent_entity))
            {
                return(false);
            }

            return(true);
        }
Пример #22
0
 public EndTurnEventArgs(State.Game.EndTurnEventArgs e, State.Game game) : base(e)
 {
     this.game = game;
 }
Пример #23
0
 public BlockEndEventArgs(SubParsers.PowerLogParser.BlockEndEventArgs e, State.Game game) : base(e)
 {
     this.game = game;
 }
Пример #24
0
        public bool Parse(State.Game game, State.ReadOnlyEntity player)
        {
            bool ret = true;

            int controller = player.GetTagOrDefault(State.GameTag.CONTROLLER, -1);

            if (controller < 0)
            {
                return(false);
            }

            this.total_cards = 0;

            foreach (var entity in game.Entities.Items)
            {
                if (entity.Value.GetTagOrDefault(State.GameTag.CONTROLLER, controller - 1) != controller)
                {
                    continue;
                }

                if (!entity.Value.HasTag(State.GameTag.ZONE))
                {
                    continue;
                }
                if (entity.Value.GetTag(State.GameTag.ZONE) != (int)State.TAG_ZONE.DECK)
                {
                    continue;
                }

                this.total_cards++;
                this.entities.Add(entity.Value.Id);
                if (entity.Value.CardId != "")
                {
                    this.known_cards.Add(entity.Value.CardId);
                }
            }

            foreach (var joust_entity_id in game.joust_information.entities)
            {
                var joust_card = game.Entities.Items[joust_entity_id];
                if (joust_card.GetTagOrDefault(State.GameTag.CONTROLLER, controller - 1) != controller)
                {
                    continue;
                }
                this.joust_cards.Add(joust_card.CardId);
            }

            List <string> raw_played_cards;

            if (player.Id == game.PlayerEntityId)
            {
                raw_played_cards = game.player_played_hand_cards;
            }
            else if (player.Id == game.OpponentEntityId)
            {
                raw_played_cards = game.opponent_played_hand_cards;
            }
            else
            {
                raw_played_cards = new List <string>();
            }

            foreach (var played_card in raw_played_cards)
            {
                this.played_cards.Add(played_card);
            }

            return(ret);
        }
Пример #25
0
 public DebugPrintPowerParser(State.Game game_state, Logger logger)
     : base(logger)
 {
     this.game_state = game_state;
     this.enumerator = this.Process().GetEnumerator();
 }
Пример #26
0
 public EntityChoicesParser(State.Game game_state, Logger logger)
     : base(logger)
 {
     this.game_state = game_state;
     this.enumerator = this.Process().GetEnumerator();
 }
Пример #27
0
        static public int GetEntityIdFromRawString(State.Game game_state, string entity_raw)
        {
            string entity_str;

            return(GetEntityIdFromRawString(game_state, entity_raw, out entity_str));
        }