js-curling-scoreboard / Exports
js-curling-scoreboard is a standalone, dependency-free JavaScript module that renders DOM to show a curling scoreboard.
▸ 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.
Name | Type |
---|---|
T |
T : keyof ActionTypeMap |
Name | Type |
---|---|
state |
GameState |
action |
Action<T> |
GameState
▸ getClubStyleCardIndexes(ends
): ClubStyleCards
Given a list of ends played, return a data structure indicating the positions to hang cards for a club-style scoreboard.
Name | Type |
---|---|
ends |
End[] |
ClubStyleCards
▸ 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.
Name | Type | Default value |
---|---|---|
lines |
ClubStyleCards | undefined |
mode |
"strict" | "lenient" |
"lenient" |
End[]
▸ 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.
Name | Type | Default value |
---|---|---|
ends |
End[] | undefined |
LSFE? |
0 | 1 |
undefined |
doubles |
boolean |
false |
0
| 1
| undefined
0 if the top team, 1 if the bottom team, or undefined if LSFE is needed but unknown.
▸ getScore(ends
): Object
Given a list of ends played, return the total score of each team.
Name | Type |
---|---|
ends |
End[] |
Object
Name | Type |
---|---|
team1 |
number |
team2 |
number |
▸ render(elem
, state
, options?
): void
Render DOM into the given elem
to produce a visualization of a curling scoreboard.
Name | Type | Description |
---|---|---|
elem |
HTMLElement |
Host element. Must be empty or contain a previously-rendered scoreboard. |
state |
GameState | |
options |
ScoreboardOptions |
void