Skip to content
This repository has been archived by the owner on Oct 24, 2021. It is now read-only.

Commit

Permalink
feat: end of mulligan event (#23)
Browse files Browse the repository at this point in the history
It turns out as the functionality of mulligan-change that initialized
the number of cards in each deck was extraneous, as that was already
handled by the zone-change line parser. This did not affect our tests
for 2 reasons.

For the test that uses dummy.log, we were using an old format of the
hearthstone log, where the line for mulligan-start came after all the
cards were added to the deck and thus triggered the zone-change line
parser, which resulted in the mulligan-start setting the deck count from
30 to 30.

For the test that uses the newer togwaggle_deck_swap.log, where the cards were
added to the deck after the mulligan, there was a single space at the
end of the line for the mulligan start in the log, which made our parser
ignore it, but the cards were still added through our zone-change line
parser.

Thus, it would make sense to remove the deck count setting of the
MulliganStart parser, keep track of the mulligan start in the
GameTagChange parser, and then use that to set the state of
mulliganActive.
  • Loading branch information
rikumiyao authored and Alex Van Camp committed May 2, 2019
1 parent 46392bd commit dfc56c5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/GameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class GameState {

players: Player[];

mulliganActive: boolean;

constructor() {
this.reset();
}
Expand Down
42 changes: 42 additions & 0 deletions src/line-parsers/game-tag-change.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {AbstractLineParser} from './AbstractLineParser';
import {GameState} from '../GameState';

interface Parts {
tag: string;
value: string;
}

function formatParts(parts: string[]): Parts {
return {
tag: parts[1],
value: parts[2].trim()
};
}

// Check for gamestate tag changes.
export class GameTagChangeLineParser extends AbstractLineParser {
regex = /^\[Power\] GameState.DebugPrintPower\(\) -\s+TAG_CHANGE Entity=GameEntity tag=(.*) value=(.*)/;

eventName = 'game-tag-change' as const;

lineMatched(parts: string[], gameState: GameState): void {
const data = formatParts(parts);

if (data.tag === 'STEP' && data.value === 'MAIN_READY') {
gameState.mulliganActive = false;
}

if (data.tag === 'STEP' && data.value === 'BEGIN_MULLIGAN') {
gameState.mulliganActive = true;
}
}

formatLogMessage(parts: string[]): string {
const data = formatParts(parts);
return `Tag ${data.tag} of GameEntity set to ${data.value}`;
}

shouldEmit(): boolean {
return true;
}
}
6 changes: 3 additions & 3 deletions src/line-parsers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {GameOverLineParser} from './game-over';
import {GameStartLineParser} from './game-start';
import {MulliganStartLineParser} from './mulligan-start';
import {GameTagChangeLineParser} from './game-tag-change';
import {NewPlayerLineParser} from './new-player';
import {TurnLineParser} from './turn';
import {ZoneChangeLineParser} from './zone-change';
Expand All @@ -10,7 +10,7 @@ import {GameState} from '../GameState';
export const lineParsers = [
new GameOverLineParser(),
new GameStartLineParser(),
new MulliganStartLineParser(),
new GameTagChangeLineParser(),
new NewPlayerLineParser(),
new TurnLineParser(),
new ZoneChangeLineParser(),
Expand All @@ -21,7 +21,7 @@ export interface Events {
'gamestate-changed': GameState;
'game-over': void;
'game-start': void;
'mulligan-start': void;
'game-tag-change': void;
'player-joined': void;
'turn-change': void;
'tag-change': void;
Expand Down
22 changes: 0 additions & 22 deletions src/line-parsers/mulligan-start.ts

This file was deleted.

7 changes: 5 additions & 2 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ describe('hearthstone-log-watcher', () => {
],
gameOverCount: 2,
friendlyCount: 11,
opposingCount: 11
opposingCount: 11,
mulliganActive: false
});
});

Expand All @@ -91,6 +92,7 @@ describe('hearthstone-log-watcher', () => {
'gamestate-changed': 1,
'game-over': 2,
'game-start': 2,
'game-tag-change': 496,
'player-joined': 4,
'zone-change': 237,
'turn-change': 36,
Expand All @@ -114,7 +116,8 @@ describe('hearthstone-log-watcher', () => {
],
gameOverCount: 0,
friendlyCount: 10,
opposingCount: 16
opposingCount: 16,
mulliganActive: false
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/types/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ logWatcher.on('gamestate-changed', (gameState) => {
});
logWatcher.on('game-over', () => {});
logWatcher.on('game-start', () => {});
logWatcher.on('mulligan-start', () => {});
logWatcher.on('game-tag-change', () => {});
logWatcher.on('player-joined', () => {});
logWatcher.on('turn-change', () => {});
logWatcher.on('tag-change', () => {});
Expand Down

0 comments on commit dfc56c5

Please sign in to comment.