|
1 | 1 | import { describe, it, expect } from "vitest"; |
2 | 2 | import { GameState, initialState, parseFEN, parseSquare, positionKey, sqEq } from "../board"; |
3 | | -import { allLegalMoves, legalMovesFrom, makeMove, teleportTargets } from "../rules"; |
| 3 | +import { allLegalMoves, inCheck, legalMovesFrom, makeMove, teleportTargets } from "../rules"; |
4 | 4 |
|
5 | 5 | /** Wrap a state into Portal Chess mode with given creator type. */ |
6 | 6 | function asPortal(s: GameState, creator: "Q" | "R" | "B" | "N" | "K" = "Q"): GameState { |
@@ -136,6 +136,18 @@ describe("Portal Chess: teleport entry", () => { |
136 | 136 | expect(moves.length).toBe(1); |
137 | 137 | }); |
138 | 138 |
|
| 139 | + it("Teleport move can immediately give check", () => { |
| 140 | + const s = asPortal(parseFEN("4k3/4p3/8/8/8/8/8/K7 w - - 0 1")); |
| 141 | + s.board[3][6] = { type: "N", color: "w" }; // Ng4 on its own portal |
| 142 | + s.portals = { w: [parseSquare("g4")], b: [], max: 1 }; |
| 143 | + const move = legalMovesFrom(s, parseSquare("g4")) |
| 144 | + .find((m) => m.isPortalEntry && sqEq(m.to, parseSquare("f6"))); |
| 145 | + expect(move).toBeDefined(); |
| 146 | + |
| 147 | + const ns = makeMove(s, move!); |
| 148 | + expect(inCheck(ns, "b")).toBe(true); |
| 149 | + }); |
| 150 | + |
139 | 151 | it("With adjacency rule OFF (default), targets next to other pieces are allowed", () => { |
140 | 152 | const s = asPortal(parseFEN("8/8/8/8/8/1P6/8/8 w - - 0 1")); |
141 | 153 | s.board[2][5] = { type: "N", color: "w" }; // Nf3 on its own portal |
|
0 commit comments