chevcast/hearthstone-log-watcher

Accounting for action queueing

Opened this issue · 3 comments

As I was working on implementing turns I noticed that zone changes would sometimes happen out of order with turn changes. It is not a problem if you always let the game execute all actions before you instruct it to perform the next action, but it doesn't work when you queue up multiple actions.

Here is an example you can try with the current implementation using the game-over event:

  1. Have a minion on the board
  2. Buff the minion with several spells and then make it attack the opposing hero so the hero dies from the attack, do it very quickly so the game has only applied the first spell when you're done queueing everything
  3. The log parser will now detect and emit the game-over event before the zone-change events

I use two regexps for detecting turn changes, and they work very well:

  • Detect next turn number: /GameEntity tag=TURN value=(\d+)$/
  • Detect next turn start: /Entity=(.+) tag=TURN_START/

The main issue is that the parser does not keep track of queuing like the game does. This is very noticeable when parsing games against the computer, which always queues all actions very fast.

If this parser should grow and implement more events, like turn changes, it must handle queueing, and it should do so right away so it's easier to extend it without having to refactor the detection all the time.

Unfortunately I don't have the time to work on this right now, but I thought I'd share these findings so others can benefit from them and continue the detective work.

My work on turn-start and mulligan-start events can be found here: https://github.com/EvilOatmeal/hearthstone-log-watcher/tree/turn-events

It is incomplete since it doesn't fix the issues mentioned in this issue, but it does work well if action queueing is avoided.

I don't even know how to fix this because it's not that the watcher doesn't account for queuing, it's that Hearthstone makes no effort to write to the log in the right order. If it writes the game over entry to the log before the zone change entries, there's not really a way for my app to predict that there are still zone change events we are waiting on. The game detects that the game is over and writes that to the log, but it seems to wait for the async animations to begin before writing zone change events.

I do think this problem is going to be much harder to solve than it seems at first blush. I will definitely be looking into it though.

The watcher reads the log in the order it is written. If HS would just write to the log in the queue order then it would make things so much simpler :/