Skip to content

Commit 1e6c1bb

Browse files
feat(PLA-842): breakthroughtroyka pawn
1 parent 14ad88b commit 1e6c1bb

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

src/premove.ts

+16
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,17 @@ function amazonsQueen(pieces: cg.Pieces): Mobility {
528528
};
529529
}
530530

531+
const breakthroughPawn = (pieces: cg.Pieces, playerIndex: cg.PlayerIndex): Mobility => {
532+
return (x1, y1, x2, y2) => {
533+
if (!diff(x1, x2)) {
534+
// prevents a premove in front of us on a friendly pawn
535+
const pos = util.pos2key([x1, y1 + (playerIndex === 'p1' ? 1 : -1)]) as cg.Key;
536+
if (pieces.has(pos) && pieces.get(pos)?.playerIndex === playerIndex) return false;
537+
}
538+
return diff(x1, x2) < 2 && (playerIndex === 'p1' ? y2 === y1 + 1 : y2 === y1 - 1);
539+
};
540+
};
541+
531542
const noMovement: Mobility = (_, __, ___, ____) => {
532543
return false;
533544
};
@@ -1131,6 +1142,11 @@ export function premove(
11311142
}
11321143
break;
11331144

1145+
case 'breakthroughtroyka':
1146+
case 'minibreakthroughtroyka':
1147+
mobility = breakthroughPawn(pieces, playerIndex);
1148+
break;
1149+
11341150
// Variants using standard pieces and additional fairy pieces like S-chess, Capablanca, etc.
11351151
default:
11361152
switch (role) {

tests/premove.test.ts

+102
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,105 @@ describe('premove() test', () => {
214214
expect(premoves).to.have.members(expected);
215215
});
216216
});
217+
218+
describe('premove() test', () => {
219+
it('breakthroughTroyka pawns can premove forward diagonally and in front of them when there is no piece', () => {
220+
const state = defaults() as State;
221+
configure(state, {
222+
dimensions: { width: 8, height: 8 },
223+
variant: 'breakthroughtroyka',
224+
fen: 'pppppppp/pppppppp/8/8/8/8/PPPPPPPP/PPPPPPPP',
225+
});
226+
227+
const expected = ['e6', 'f6', 'g6'];
228+
const premoves = premove(
229+
state.pieces,
230+
'f7',
231+
state.premovable.castle,
232+
state.dimensions,
233+
state.variant,
234+
state.chess960
235+
);
236+
expect(premoves).to.have.members(expected);
237+
});
238+
239+
it('breakthroughTroyka pawns on the edge can not premove outside the board', () => {
240+
const state = defaults() as State;
241+
configure(state, {
242+
dimensions: { width: 8, height: 8 },
243+
variant: 'breakthroughtroyka',
244+
fen: 'pppppppp/pppppppp/8/8/8/8/PPPPPPPP/PPPPPPPP',
245+
});
246+
247+
const expected = ['g6', 'h6'];
248+
const premoves = premove(
249+
state.pieces,
250+
'h7',
251+
state.premovable.castle,
252+
state.dimensions,
253+
state.variant,
254+
state.chess960
255+
);
256+
expect(premoves).to.have.members(expected);
257+
});
258+
259+
it('breakthroughTroyka pawns can premove to opponent pawn in front of them', () => {
260+
const state = defaults() as State;
261+
configure(state, {
262+
dimensions: { width: 8, height: 8 },
263+
variant: 'breakthroughtroyka',
264+
fen: 'pppppppp/ppp1pppp/8/4p3/4P3/8/PPPP1PPP/PPPPPPPP',
265+
});
266+
267+
const expected = ['d4', 'e4', 'f4'];
268+
const premoves = premove(
269+
state.pieces,
270+
'e5',
271+
state.premovable.castle,
272+
state.dimensions,
273+
state.variant,
274+
state.chess960
275+
);
276+
expect(premoves).to.have.members(expected);
277+
});
278+
279+
it('breakthroughTroyka pawns can not premove to friendly pawn in front of them', () => {
280+
const state = defaults() as State;
281+
configure(state, {
282+
dimensions: { width: 8, height: 8 },
283+
variant: 'breakthroughtroyka',
284+
fen: 'pppppppp/ppp1p1pp/4p3/4p3/4P3/4P3/PPP2PPP/PPPPPPPP',
285+
});
286+
287+
const expected = ['d5', 'f5'];
288+
const premoves = premove(
289+
state.pieces,
290+
'e6',
291+
state.premovable.castle,
292+
state.dimensions,
293+
state.variant,
294+
state.chess960
295+
);
296+
expect(premoves).to.have.members(expected);
297+
});
298+
299+
it('breakthroughTroyka pawns can premove to friendly and opponent pawn in diagonal', () => {
300+
const state = defaults() as State;
301+
configure(state, {
302+
dimensions: { width: 8, height: 8 },
303+
variant: 'breakthroughtroyka',
304+
fen: 'pppppppp/ppp1p1pp/8/4p3/3pPP2/4P3/PPP3PP/PPPPPPPP',
305+
});
306+
307+
const expected = ['d4', 'e4', 'f4'];
308+
const premoves = premove(
309+
state.pieces,
310+
'e5',
311+
state.premovable.castle,
312+
state.dimensions,
313+
state.variant,
314+
state.chess960
315+
);
316+
expect(premoves).to.have.members(expected);
317+
});
318+
});

0 commit comments

Comments
 (0)