Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/samualtnorman/binmat. binmat simulator for game hackmud
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122import { assert, AssertError } from "@samual/lib/assert"import type { CardString, CardStringFace, Lane } from "./common"import { AttackerDeck, AttackerDiscardPile, CardStringFaces, MoveTag } from "./common"import { isCard } from "./isCard"
export type BinlogMoveDraw = { tag: MoveTag.Draw, deck: Lane | AttackerDeck }export type BinlogMovePlay = { tag: MoveTag.Play, lane: Lane }export type BinlogMovePlayFaceUp = { tag: MoveTag.PlayFaceUp, card: CardString | CardStringFace, lane: Lane }export type BinlogMoveCombat = { tag: MoveTag.Combat, lane: Lane }
export type BinlogMoveDiscard = { tag: MoveTag.Discard card: CardString | CardStringFace discardPile: Lane | AttackerDiscardPile}
export type BinlogMovePass = { tag: MoveTag.Pass }
export type BinlogMove = BinlogMoveDraw | BinlogMovePlay | BinlogMovePlayFaceUp | BinlogMoveCombat | BinlogMoveDiscard | BinlogMovePass
export function parseMove(move: string): BinlogMove { assert(move.length > 1, HERE)
if (move == `\`n--\``) return { tag: MoveTag.Pass }
switch (move[0]) { case `d`: { assert(move.length == 2, `${HERE} "${move}"`)
if (move[1] == `a`) return { tag: MoveTag.Draw, deck: AttackerDeck }
const lane = Number(move[1])
assert(lane >= 0 && lane < 6, HERE)
return { tag: MoveTag.Draw, deck: lane as Lane } }
case `c`: { assert(move.length == 2, HERE)
const lane = Number(move[1])
assert(lane >= 0 && lane < 6, HERE)
return { tag: MoveTag.Combat, lane: lane as Lane } }
case `p`: { assert(move.length == 3, HERE) assert(move[1] == `X`, HERE)
const lane = Number(move[2])
assert(lane >= 0 && lane < 6, HERE)
return { tag: MoveTag.Play, lane: lane as Lane } }
case `u`: { if (move.length == 3) { assert(CardStringFaces.includes(move[1]!), HERE)
const lane = Number(move[2])
assert(lane >= 0 && lane < 6, HERE)
return { tag: MoveTag.PlayFaceUp, card: move[1] as CardStringFace, lane: lane as Lane } }
if (move.length == 4) { const card = move.slice(1, 3)
assert(isCard(card), HERE)
const lane = Number(move[3])
assert(lane >= 0 && lane < 6, HERE)
return { tag: MoveTag.PlayFaceUp, card, lane: lane as Lane } }
break }
case `x`: { if (move.length == 3) { assert(CardStringFaces.includes(move[1]!), HERE)
if (move[2] == `a`) return { tag: MoveTag.Discard, card: move[1] as CardStringFace, discardPile: AttackerDiscardPile }
const lane = Number(move[2])
assert(lane >= 0 && lane < 6, HERE)
return { tag: MoveTag.Discard, card: move[1] as CardStringFace, discardPile: lane as Lane } }
if (move.length == 4) { const card = move.slice(1, 3)
assert(isCard(card), HERE)
if (move[3] == `a`) return { tag: MoveTag.Discard, card, discardPile: AttackerDiscardPile }
const lane = Number(move[3])
assert(lane >= 0 && lane < 6, HERE)
return { tag: MoveTag.Discard, card, discardPile: lane as Lane } } } }
throw new AssertError(`${HERE} "${move}"`)}