MCPcopy Create free account
hub / github.com/code100x/chess / isPromoting

Function isPromoting

apps/ws/src/Game.ts:16–39  ·  view source on GitHub ↗
(chess: Chess, from: Square, to: Square)

Source from the content-addressed store, hash-verified

14const GAME_TIME_MS = 10 * 60 * 60 * 1000;
15
16export function isPromoting(chess: Chess, from: Square, to: Square) {
17 if (!from) {
18 return false;
19 }
20
21 const piece = chess.get(from);
22
23 if (piece?.type !== 'p') {
24 return false;
25 }
26
27 if (piece.color !== chess.turn()) {
28 return false;
29 }
30
31 if (!['1', '8'].some((it) => to.endsWith(it))) {
32 return false;
33 }
34
35 return chess
36 .moves({ square: from, verbose: true })
37 .map((it) => it.to)
38 .includes(to);
39}
40
41export class Game {
42 public gameId: string;

Callers 3

seedMovesMethod · 0.70
makeMoveMethod · 0.70
index.tsxFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected