-
Notifications
You must be signed in to change notification settings - Fork 0
/
variant.ts
39 lines (35 loc) · 896 Bytes
/
variant.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// NOTE: This skips a bunch of stuff for now.
// This only implements enough for minimal functionality of `pgn.ts`.
import { iterAny } from './utils'
import { Board } from './index'
const VARIANTS: (typeof Board)[] = [
Board,
/* TODO: Add variant board support */
// SuicideBoard, GiveawayBoard, AntichessBoard,
// AtomicBoard,
// KingOfTheHillBoard,
// RacingKingsBoard,
// HordeBoard,
// ThreeCheckBoard,
// CrazyhouseBoard,
]
/**
* Looks for a variant board class by variant name. Supports many common
* aliases.
*/
export const findVariant = (name: string): typeof Board => {
for (const variant of VARIANTS) {
if (
iterAny(
variant.aliases,
alias => alias.toLowerCase() === name.toLowerCase(),
)
) {
return variant
}
}
throw new Error(`ValueError: unsupported variant: ${name}`)
}
export default {
findVariant,
}