-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17dffc9
commit 96dd2c3
Showing
7 changed files
with
280 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { parseCard } from '../action-parser'; | ||
import { RootAction, RootActionMove, RootActionType, RootCardName, RootFaction, RootFactionBoard, RootThing } from '../interfaces'; | ||
import { splitAction } from '../utils/action-splitter'; | ||
import { formRegex } from '../utils/regex-former'; | ||
|
||
const FLIP_RELIC_REGEX = formRegex('t<Clearing|||relicClearing>^<Piece|||relicFlipped>'); | ||
const ADD_TO_RETINUE_REGEX = formRegex('[Number|||countAdded]<Card|||cardAdded>K->$_<Retinue|||columnAdded>') | ||
const DISCARD_FROM_RETINUE_REGEX = formRegex('<Card|||cardDiscarded>$_<Retinue|||columnDiscarded>->') | ||
|
||
export function parseAddToRetinue(actions: string[]): RootActionMove { | ||
|
||
const movingComponents = []; | ||
|
||
for (let action of actions) { | ||
const result = action.match(ADD_TO_RETINUE_REGEX); | ||
const component = { | ||
number: +(result.groups.countAdded || 1), | ||
thing: parseCard(result.groups.cardAdded), | ||
start: RootFaction.Keepers, | ||
destination: { | ||
faction: RootFaction.Keepers, | ||
sublocation: +result.groups.columnAdded, | ||
} | ||
}; | ||
|
||
movingComponents.push(component); | ||
} | ||
|
||
return { | ||
things: movingComponents | ||
}; | ||
|
||
} | ||
|
||
export function parseKeepersAction(action: string): RootAction { | ||
|
||
if (FLIP_RELIC_REGEX.test(action)) { | ||
const result = action.match(FLIP_RELIC_REGEX); | ||
|
||
return { | ||
type: RootActionType.FlipRelic, | ||
relic: result.groups.relicFlipped, | ||
clearing: +result.groups.relicClearing | ||
}; | ||
} | ||
|
||
if (DISCARD_FROM_RETINUE_REGEX.test(action)) { | ||
const result = action.match(DISCARD_FROM_RETINUE_REGEX); | ||
const card = parseCard(result.groups.cardDiscarded); | ||
|
||
return { | ||
things: [{ | ||
number: 1, | ||
thing: card, | ||
start: { | ||
faction: RootFaction.Keepers, | ||
sublocation: +result.groups.columnDiscarded | ||
}, | ||
destination: (card.cardName === RootCardName.FaithfulRetainer) ? null : 'Discard pile' | ||
}] | ||
} | ||
} | ||
|
||
const simpleActions = splitAction(action); | ||
|
||
if (simpleActions.every(act => ADD_TO_RETINUE_REGEX.test(act))) { | ||
return parseAddToRetinue(simpleActions); | ||
} | ||
|
||
return null; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import test from 'ava-ts'; | ||
import { parseAction } from '../src/action-parser'; | ||
|
||
import { RootActionMove, RootActionType, RootFaction, RootFactionBoard, RootSuit } from '../src/interfaces'; | ||
|
||
test('Correctly parses placing a Keepers waystation', t => { | ||
|
||
const result = parseAction('b_t_j->3', RootFaction.Keepers); | ||
|
||
t.deepEqual(result.things, [{ | ||
number: 1, | ||
thing: { | ||
faction: RootFaction.Keepers, | ||
piece: 'b_t_j', | ||
pieceType: 'b' | ||
}, | ||
start: null, | ||
destination: 3 | ||
}]); | ||
}); | ||
|
||
test('Correctly parses delving a relic', t => { | ||
|
||
const result = parseAction('t_j1_2_5_10->10', RootFaction.Keepers); | ||
|
||
t.deepEqual(result.things, [{ | ||
number: 1, | ||
thing: { | ||
faction: RootFaction.Keepers, | ||
piece: 't_j', | ||
pieceType: 't' | ||
}, | ||
start: { | ||
clearings: [1, 2, 5, 10], | ||
}, | ||
destination: 10 | ||
}]); | ||
}); | ||
|
||
test('Correctly parses flipping a relic', t => { | ||
|
||
const result = parseAction('t3^t_2_j', RootFaction.Keepers); | ||
|
||
t.deepEqual(result, { | ||
type: RootActionType.FlipRelic, | ||
clearing: 3, | ||
relic: 't_2_j' | ||
}); | ||
}); | ||
|
||
test('Correctly parses recovering a relic', t => { | ||
|
||
const result = parseAction('t_2_j2->$', RootFaction.Keepers); | ||
|
||
t.deepEqual(result.things, [{ | ||
number: 1, | ||
thing: { | ||
faction: RootFaction.Keepers, | ||
piece: 't_2_j', | ||
pieceType: 't' | ||
}, | ||
start: 2, | ||
destination: { | ||
faction: RootFaction.Keepers | ||
} | ||
}]); | ||
}); | ||
|
||
test('Correctly parses adding a card to the retinue', t => { | ||
|
||
const result = parseAction('M#K->$_1', RootFaction.Keepers); | ||
|
||
t.deepEqual(result.things, [{ | ||
number: 1, | ||
thing: { | ||
suit: RootSuit.Mouse, | ||
cardName: null, | ||
}, | ||
start: RootFaction.Keepers, | ||
destination: { | ||
faction: RootFaction.Keepers, | ||
sublocation: 1 | ||
} | ||
}]); | ||
}); | ||
|
||
test('Correctly parses discarding a Faithful Retainer from the retinue', t => { | ||
|
||
const result = parseAction('#faith$_1->', RootFaction.Keepers); | ||
|
||
t.deepEqual(result.things, [{ | ||
number: 1, | ||
thing: { | ||
suit: null, | ||
cardName: 'faith', | ||
}, | ||
start: { | ||
faction: RootFaction.Keepers, | ||
sublocation: 1, | ||
}, | ||
destination: null | ||
}]); | ||
}); | ||
|
||
test('Correctly parses discarding a deck card from the retinue', t => { | ||
|
||
const result = parseAction('B#$_2->', RootFaction.Keepers); | ||
|
||
t.deepEqual(result.things, [{ | ||
number: 1, | ||
thing: { | ||
suit: RootSuit.Bird, | ||
cardName: null, | ||
}, | ||
start: { | ||
faction: RootFaction.Keepers, | ||
sublocation: 2, | ||
}, | ||
destination: 'Discard pile' | ||
}]); | ||
}); | ||
|
||
test('Correctly parses removing relic after battle', t => { | ||
|
||
const result = parseAction('Kt_2_j3->', RootFaction.Eyrie); | ||
|
||
t.deepEqual(result.things, [{ | ||
number: 1, | ||
thing: { | ||
faction: RootFaction.Keepers, | ||
piece: 't_2_j', | ||
pieceType: 't', | ||
}, | ||
start: 3, | ||
destination: null | ||
}]); | ||
}); | ||
|
||
test('Correctly parses placing relic in forest during setup', t => { | ||
|
||
const result = parseAction('t_j->1_2_5_10', RootFaction.Keepers); | ||
|
||
t.deepEqual(result.things, [{ | ||
number: 1, | ||
thing: { | ||
faction: RootFaction.Keepers, | ||
piece: 't_j', | ||
pieceType: 't', | ||
}, | ||
start: null, | ||
destination: { | ||
clearings: [1, 2, 5, 10] | ||
} | ||
}]); | ||
}); | ||
|
||
test('Correctly parses placing relic in forest after removal', t => { | ||
|
||
const result = parseAction('Kt_2_j->1_2_5_10', RootFaction.Eyrie); | ||
|
||
t.deepEqual(result.things, [{ | ||
number: 1, | ||
thing: { | ||
faction: RootFaction.Keepers, | ||
piece: 't_2_j', | ||
pieceType: 't', | ||
}, | ||
start: null, | ||
destination: { | ||
clearings: [1, 2, 5, 10] | ||
} | ||
}]); | ||
}); |