Skip to content

Commit

Permalink
add new variant hyper backgammon
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHeppell committed Nov 8, 2024
1 parent 985bc1c commit e502b35
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 445 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stratops",
"version": "0.8.1-pstrat5.2",
"version": "0.8.1-pstrat5.3",
"description": "Strategy game rules and operations",
"keywords": [
"chess",
Expand Down
843 changes: 402 additions & 441 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function playstrategyRules(
| 'go13x13'
| 'go19x19'
| 'backgammon'
| 'hyper'
| 'nackgammon'
| 'breakthroughtroyka'
| 'minibreakthroughtroyka',
Expand Down Expand Up @@ -146,6 +147,7 @@ export function playstrategyVariants(
| 'go13x13'
| 'go19x19'
| 'backgammon'
| 'hyper'
| 'nackgammon'
| 'breakthrough'
| 'minibreakthrough'
Expand Down
6 changes: 3 additions & 3 deletions src/fen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const INITIAL_FEN = INITIAL_EPD + ' 0 1';
export const EMPTY_BOARD_FEN = '8/8/8/8/8/8/8/8';
export const EMPTY_EPD = EMPTY_BOARD_FEN + ' w - -';
export const EMPTY_FEN = EMPTY_EPD + ' 0 1';
export const COMMA_FEN_RULES = ['oware', 'togyzkumalak', 'bestemshe', 'backgammon', 'nackgammon'];
export const COMMA_FEN_RULES = ['oware', 'togyzkumalak', 'bestemshe', 'backgammon', 'hyper', 'nackgammon'];
export const MANCALA_FEN_VARIANT = ['oware', 'togyzkumalak', 'bestemshe'];

export enum InvalidFen {
Expand Down Expand Up @@ -533,7 +533,7 @@ export const parseFen = (rules: Rules) => (fen: string): Result<Setup, FenError>
if (rules === 'go9x9' || rules === 'go13x13' || rules === 'go19x19') {
return parseGoFen(rules)(fen);
}
if (rules === 'backgammon' || rules === 'nackgammon') {
if (rules === 'backgammon' || rules === 'hyper' || rules === 'nackgammon') {
return parseBackgammonFen(rules)(fen);
}

Expand Down Expand Up @@ -705,7 +705,7 @@ export const makeFen = (rules: Rules) => (setup: Setup, opts?: FenOpts): string
makeBoardFen(rules)(setup.board, opts) + (setup.pockets ? `[${makePockets(rules)(setup.pockets)}]` : ''),
...(MANCALA_FEN_VARIANT.includes(rules)
? owareMancalaFenParts(setup)
: rules === 'backgammon' || rules === 'nackgammon'
: rules === 'backgammon' || rules === 'hyper' || rules === 'nackgammon'
? backgammonFenParts(setup)
: chessVariantFenParts(rules)(setup, opts)),
...(rules === 'amazons' && setup.lastMove ? [makeLastMove(rules)(setup.lastMove)] : []),
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export const RULES = [
'go13x13',
'go19x19',
'backgammon',
'hyper',
'nackgammon',
'breakthrough',
'minibreakthrough',
Expand Down
1 change: 1 addition & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export const dimensionsForRules = (rules: Rules): BoardDimensions => {
case 'go19x19':
return { ranks: 19, files: 19 };
case 'nackgammon':
case 'hyper':
case 'backgammon':
return { ranks: 2, files: 12 };
default:
Expand Down
27 changes: 27 additions & 0 deletions src/variant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,29 @@ export class Backgammon extends Chess {
}
}

export class Hyper extends Chess {
// TODO - move into own class and have variant family
protected constructor() {
super('hyper');
}

static default(): Hyper {
return super.default();
}

static fromSetup(setup: Setup): Result<Hyper, PositionError> {
return super.fromSetup(setup);
}

clone(): Hyper {
return super.clone() as Hyper;
}

hasInsufficientMaterial(_playerIndex: PlayerIndex): boolean {
return false;
}
}

export class Nackgammon extends Chess {
// TODO - move into own class and have variant family
protected constructor() {
Expand Down Expand Up @@ -1227,6 +1250,8 @@ export function defaultPosition(rules: Rules): Position {
return Go19x19.default();
case 'backgammon':
return Backgammon.default();
case 'hyper':
return Hyper.default();
case 'nackgammon':
return Nackgammon.default();
case 'breakthrough':
Expand Down Expand Up @@ -1292,6 +1317,8 @@ export function setupPosition(rules: Rules, setup: Setup): Result<Position, Posi
return Go19x19.fromSetup(setup);
case 'backgammon':
return Backgammon.fromSetup(setup);
case 'hyper':
return Hyper.fromSetup(setup);
case 'nackgammon':
return Nackgammon.fromSetup(setup);
case 'breakthrough':
Expand Down

0 comments on commit e502b35

Please sign in to comment.