Skip to content

Latest commit

 

History

History
220 lines (141 loc) · 6.31 KB

modules.md

File metadata and controls

220 lines (141 loc) · 6.31 KB

js-curling-scoreboard / Exports

js-curling-scoreboard

js-curling-scoreboard is a standalone, dependency-free JavaScript module that renders DOM to show a curling scoreboard.

Table of contents

Interfaces

Functions

Functions

gameStateReducer

gameStateReducer<T>(state, action): GameState

Given a GameState an an action, compute the resulting GameState. The input state is unmodified - this function returns a new object.

Type parameters

Name Type
T T: keyof ActionTypeMap

Parameters

Name Type
state GameState
action Action<T>

Returns

GameState

GameState

Defined in

scoreboard.ts:588


getClubStyleCardIndexes

getClubStyleCardIndexes(ends): ClubStyleCards

Given a list of ends played, return a data structure indicating the positions to hang cards for a club-style scoreboard.

Parameters

Name Type
ends End[]

Returns

ClubStyleCards

ClubStyleCards

Defined in

scoreboard.ts:283


getEndsFromClubStyle

getEndsFromClubStyle(lines, mode?): End[]

Generates end-by-end scores from data formatted as you would see on a club-style scoreboard.

Each line (team1Line, team2Line) should contain an array of string arrays. Each item in the outer array should be an array of length 0 or 1. An array of length 0 represents no card in the spot labeled with + 1 points. An array of length 1 represents a card hanging in that spot, the value of which is the string in that length-1 array.

The last element of the outer array represents blank ends. The string array in the last element may have multiple elements, representing multiple ends that were blanked.

Mode

When mode is strict, any of the following conditions result in an Error being thrown:

  • A end card is represented multiple times.
  • The end cards are out of order
  • An end card is missing (incomplete games are fine, but skipped ends are not).
  • An end of more than 8 points is represented.

When mode is lenient, the following actions are taken for the same conditions:

  • A end card is represented multiple times. First, we will check if any ends are missing. If so, the second instance of a card takes the place of the missing end. Otherwise, treat the duplicated end card as the next in-order end.
  • The end cards are out of order The out-of-order card is treated as though it has wrapped around. For instance, if the maximum point value represented by a scoreboard is 12, and an out-of-order end card is found above a 3, that card is treated as though it represents 15 points.
  • An end card is missing (i.e. a skipped end). The end that is missing a card is considered blank. This can happen if there are no blank spaces on the scoreboard, or if they are full.
  • An end of more than 8 points is represented. The end that is represented with a score of more than 8 is considered blank. This can happen if there are no blank spaces on the scoreboard, or if they are full.

Parameters

Name Type Default value
lines ClubStyleCards undefined
mode "strict" | "lenient" "lenient"

Returns

End[]

Defined in

scoreboard.ts:348


getHammerTeam

getHammerTeam(ends, LSFE?, doubles?): 0 | 1 | undefined

Returns the team (0 or 1) which has hammer after the given ends. If no ends have been played, or only blanks have been scored, use LSFE to deduce the hammer team.

If doubles is true, blank ends cause hammer to go to the other team.

Parameters

Name Type Default value
ends End[] undefined
LSFE? 0 | 1 undefined
doubles boolean false

Returns

0 | 1 | undefined

0 if the top team, 1 if the bottom team, or undefined if LSFE is needed but unknown.

Defined in

scoreboard.ts:253


getScore

getScore(ends): Object

Given a list of ends played, return the total score of each team.

Parameters

Name Type
ends End[]

Returns

Object

Name Type
team1 number
team2 number

Defined in

scoreboard.ts:234


render

render(elem, state, options?): void

Render DOM into the given elem to produce a visualization of a curling scoreboard.

Parameters

Name Type Description
elem HTMLElement Host element. Must be empty or contain a previously-rendered scoreboard.
state GameState
options ScoreboardOptions

Returns

void

Defined in

scoreboard.ts:607