Skip to content

Commit

Permalink
setup checkmate
Browse files Browse the repository at this point in the history
  • Loading branch information
fitztrev committed Jan 20, 2024
1 parent 9e1b97b commit 75db6fa
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions js/goals/setup-checkmate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Game } from 'chess-fetcher'
import { TrophyCheckResult } from '../types/types'
import { fenToPosition } from '../utils/fen-to-position'

export function originalSetupCheckmate(game: Game, fen: string): TrophyCheckResult {
if (game.result.via !== 'checkmate') {
return []
}

let position = fenToPosition(fen)

if (position.startsWith('rnbqkbnr..K') || position.endsWith('k.....RNBQKBNR')) {
return [
{
color: game.result.winner === 'white' ? 'w' : 'b',
},
]
}

return []
}
22 changes: 22 additions & 0 deletions tests/setup-checkmate.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Game } from 'chess-fetcher'
import { describe, expect, test } from 'vitest'
import { originalSetupCheckmate } from '../js/goals/setup-checkmate'

describe('original setup checkmate', () => {
test.each([
['white', { color: 'w' }, '8/8/8/8/8/8/2k5/RNBQKBNR b KQ - 0 1'],
['black', { color: 'b' }, 'rnbqkbnr/2K5/8/8/8/8/8/8 w kq - 0 1'],
])('test FEN: %p %p', (winner, expected, fen) => {
expect(
originalSetupCheckmate(
{
result: {
via: 'checkmate',
winner: winner,
},
} as Game,
fen
)
).toStrictEqual([expected])
})
})

0 comments on commit 75db6fa

Please sign in to comment.