UNPKG

tsgammon-core

Version:

A Backgammon library for Typescript, formerly developed as a part of tsgammon-ui

34 lines (30 loc) 1.01 kB
import { EOGStatus } from '../EOGStatus' import { defaultNames } from '../records/utils/defaultNames' import { Score } from '../Score' /** * 得点及び終局状態を文字列に変換する。 * * @param stake 得点:0の側が敗者、そうでない側が勝者となる * @param eog 終局状態 * @param redPlayer Red側のプレイヤー名 * @param whitePlayer White側のプレイヤー名 * @returns 変換後の文字列 */ export function formatStake( stake: Score, eog: EOGStatus, redPlayer = defaultNames.red, whitePlayer = defaultNames.white ) { const gammon = eog.isBackgammon ? ' by Backgammon' : eog.isGammon ? ' by Gammon' : '' const red = format(redPlayer, stake.redScore, gammon) const white = format(whitePlayer, stake.whiteScore, gammon) return red + white function format(player: string, score: number, gammon: string) { return score === 0 ? '' : `${player} wins ${score} pt.${gammon}` } }