Files
kadi_game/src/static/rulesets.ts
Daniel Ledda 652092f741 Big update
2020-08-13 15:11:18 +02:00

205 lines
4.4 KiB
TypeScript
Executable File

export enum FieldType {
number = "numberField",
bool = "boolField",
bonus = "bonusField",
subtotal = "subtotalField",
globalTotal = "globalTotalField",
total = "totalField",
superkadi = "superkadiField",
multiplier = "multiplierField",
}
export const defaultCellValues = {
[FieldType.number]: 0,
[FieldType.bool]: false,
[FieldType.subtotal]: 0,
[FieldType.total]: 0,
[FieldType.bonus]: 0,
[FieldType.superkadi]: 0,
[FieldType.multiplier]: 0,
};
export interface Ruleset {
id: string;
label: string;
blocks: Record<string, BlockDef>;
}
export type BlockDef = BonusBlockDef | NoBonusBlockDef;
export interface NoBonusBlockDef extends DefaultBlockDef {
hasBonus: false;
}
export interface BonusBlockDef extends DefaultBlockDef {
hasBonus: true;
bonusScore: number;
bonusFor: number;
}
interface DefaultBlockDef {
label: string;
cells: Record<string, CellDef>;
}
export type CellDef =
| BoolCellDef
| MultiplierCellDef
| NumberCellDef
| SuperkadiCellDef;
export interface BoolCellDef extends DefaultCellDef {
fieldType: FieldType.bool;
score: number;
}
export interface MultiplierCellDef extends DefaultCellDef {
fieldType: FieldType.multiplier;
multiplier: number;
maxMultiples: number;
}
export interface SuperkadiCellDef extends DefaultCellDef {
fieldType: FieldType.superkadi;
score: number;
maxSuperkadis: number;
}
export interface NumberCellDef extends DefaultCellDef {
fieldType: FieldType.number;
max: number,
}
interface DefaultCellDef {
label: string;
}
// ----- Predefined sets
const defaultDiceCount = 5;
const DEFAULT_RULESET = "DEFAULT_RULESET";
const gameSchemas: Ruleset[] = [
{
id: DEFAULT_RULESET,
label: "Standard Kadi Rules (en)",
blocks: {
top: {
label: "Upper",
hasBonus: true,
bonusScore: 35,
bonusFor: 63,
cells: {
aces: {
fieldType: FieldType.multiplier,
label: "Aces",
multiplier: 1,
maxMultiples: defaultDiceCount,
},
twos: {
fieldType: FieldType.multiplier,
label: "Twos",
multiplier: 2,
maxMultiples: defaultDiceCount,
},
threes: {
fieldType: FieldType.multiplier,
label: "Threes",
multiplier: 3,
maxMultiples: defaultDiceCount,
},
fours: {
fieldType: FieldType.multiplier,
label: "Fours",
multiplier: 4,
maxMultiples: defaultDiceCount,
},
fives: {
fieldType: FieldType.multiplier,
label: "Fives",
multiplier: 5,
maxMultiples: defaultDiceCount,
},
sixes: {
fieldType: FieldType.multiplier,
label: "Sixes",
multiplier: 6,
maxMultiples: defaultDiceCount,
},
},
},
bottom: {
label: "Lower",
hasBonus: false,
cells: {
threeKind: {
fieldType: FieldType.number,
label: "Three of a Kind",
max: defaultDiceCount * 6,
},
fourKind: {
fieldType: FieldType.number,
label: "Four of a Kind",
max: defaultDiceCount * 6,
},
fullHouse: {
fieldType: FieldType.bool,
label: "Full House",
score: 25,
},
smlStraight: {
fieldType: FieldType.bool,
label: "Small Straight",
score: 30,
},
lgSraight: {
fieldType: FieldType.bool,
label: "Large Straight",
score: 40,
},
superkadi: {
fieldType: FieldType.superkadi,
label: "Super Kadis",
score: 50,
maxSuperkadis: 5,
},
chance: {
fieldType: FieldType.number,
label: "Chance",
max: defaultDiceCount * 6,
},
},
},
},
},
];
export function getGameSchemaById(schemaId: string): Ruleset {
for (const schema of gameSchemas) {
if (schema.id === schemaId) {
return schema;
}
}
throw new RangeError("No such GameSchema with id '" + schemaId + "'!");
}
export interface SchemaListing {
id: string;
label: string;
}
export function getSchemaListings(): SchemaListing[] {
return gameSchemas.map((s) => ({ id: s.id, label: s.label }));
}