Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/apps/chess/__tests__/rules.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest'
import {
glyph,
describeResult,
formatClock,
lastMoveSquares,
Expand Down Expand Up @@ -88,6 +89,19 @@ describe('formatClock', () => {
})
})

describe('glyph', () => {
// U+265F is an emoji: without the text selector, phones draw the pawn
// as a black emoji whatever its side's color.
it('asks for text presentation, so CSS colors every piece', () => {
for (const piece of 'KQRBNPkqrbnp') expect(glyph(piece).endsWith('\uFE0E')).toBe(true)
})

it('draws both sides with the filled glyph', () => {
expect(glyph('P')).toBe(glyph('p'))
expect(glyph('K')).toBe('♚\uFE0E')
})
})

describe('pieceName', () => {
it('names a piece by its color and kind', () => {
expect(pieceName('K')).toBe('white king')
Expand Down
3 changes: 2 additions & 1 deletion src/apps/chess/components/ChessTable.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@

.whitePiece {
color: #fff;
text-shadow: 0 0 2px #000, 0 0 1px #000;
-webkit-text-stroke: 0.04em #000;
paint-order: stroke fill;
}

.blackPiece {
Expand Down
6 changes: 4 additions & 2 deletions src/apps/chess/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ export function pieceName(piece: string): string {
}

// Filled glyphs for both sides, told apart by color, so neither side's
// pieces read as outlines.
// pieces read as outlines. U+FE0E asks for text presentation: ♟ is also
// an emoji, which phones draw black whatever the CSS color says.
const GLYPHS: Record<string, string> = { k: '♚', q: '♛', r: '♜', b: '♝', n: '♞', p: '♟' }

export function glyph(piece: string): string {
return GLYPHS[piece.toLowerCase()] ?? ''
const shape = GLYPHS[piece.toLowerCase()]
return shape === undefined ? '' : `${shape}\uFE0E`
}

const WON_BY: Record<ChessEnding, string> = {
Expand Down
Loading