tsgammon-core
Version:
A Backgammon library for Typescript, formerly developed as a part of tsgammon-ui
55 lines (52 loc) • 1.52 kB
text/typescript
import { MoveFormatDirection } from '../../utils/formatAbsMove'
import { formatPlyAbbr } from '../../utils/formatPly'
import { PlyRecord } from '../PlyRecord'
import { SGResult } from '../SGResult'
/**
* 一手番でのプレイ(チェッカープレイ・キューブアクション)を文字列に変換する
*
* @param plyRecord
* @param direction
* @param fmtDoublet
* @param labelNoMove
* @returns
*/
export function formatPlyRecord(
plyRecord: PlyRecord,
direction: MoveFormatDirection = MoveFormatDirection.RELATIVE_DEC,
fmtDoublet = true,
labelNoMove = ''
) {
switch (plyRecord.tag) {
case 'Commit': {
return formatPlyAbbr(
plyRecord.ply,
direction,
fmtDoublet,
labelNoMove
)
}
case 'Double': {
return ' Doubles => ' + plyRecord.cubeValue
}
case 'Pass': {
return 'Drops'
}
case 'Take': {
return ' Takes'
}
case 'EOG': {
const stake = plyRecord.stake
return plyRecord.sgResult === SGResult.NOGAME
? 'No game'
: formatStake(
plyRecord.sgResult === SGResult.REDWON
? stake.redScore
: stake.whiteScore
)
}
}
function formatStake(score: number): string {
return score === 0 ? '' : `Wins ${score} point`
}
}