-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
An attempt to more correctly solve pinning.
- Loading branch information
Showing
5 changed files
with
192 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,147 @@ | ||
import { assert, describe, it } from "vitest"; | ||
import { BoardState } from "./board"; | ||
import { pins } from "./pins"; | ||
import { pins, TAllowedMoves } from "./pins"; | ||
import { TSquare } from "./types"; | ||
|
||
describe("pins", () => { | ||
it("initial state", () => { | ||
const board = new BoardState(); | ||
|
||
assert.deepEqual(pins(board, "e1"), []); | ||
assert.deepEqual(pins(board, "e1"), new Map<TSquare, TAllowedMoves>([])); | ||
}); | ||
|
||
it("adjacent rooks", () => { | ||
const board = new BoardState("8/3r4/3R4/3K4/3R4/3r4/8/8 w KQkq - 0 1"); | ||
|
||
assert.deepEqual(pins(board, "d5"), ["d4", "d6"]); | ||
assert.deepEqual( | ||
pins(board, "d5"), | ||
new Map<TSquare, TAllowedMoves>([ | ||
["d4", []], | ||
["d6", []], | ||
]) | ||
); | ||
}); | ||
|
||
it("far rooks", () => { | ||
it("far enemy rooks", () => { | ||
const board = new BoardState("3r4/8/3R4/3K4/3R4/8/8/3r4 w KQkq - 0 1"); | ||
|
||
assert.deepEqual(pins(board, "d5"), ["d4", "d6"]); | ||
assert.deepEqual( | ||
pins(board, "d5"), | ||
new Map<TSquare, TAllowedMoves>([ | ||
["d4", []], | ||
["d6", []], | ||
]) | ||
); | ||
}); | ||
|
||
it("far friendly rooks", () => { | ||
const board = new BoardState("3r4/3R4/8/3K4/8/8/3R4/3r4 w KQkq - 0 1"); | ||
|
||
assert.deepEqual( | ||
pins(board, "d5"), | ||
new Map<TSquare, TAllowedMoves>([ | ||
["d2", ["d4", "d3"]], | ||
["d7", ["d6"]], | ||
]) | ||
); | ||
}); | ||
|
||
it("adjacent bishops", () => { | ||
const board = new BoardState("8/1b6/2R5/3K4/4R3/5b2/8/8 w KQkq - 0 1"); | ||
|
||
assert.deepEqual(pins(board, "d5"), ["e4", "c6"]); | ||
assert.deepEqual( | ||
pins(board, "d5"), | ||
new Map<TSquare, TAllowedMoves>([ | ||
["e4", []], | ||
["c6", []], | ||
]) | ||
); | ||
}); | ||
|
||
it("far bishops", () => { | ||
it("far enemy bishop", () => { | ||
const board = new BoardState("K7/1R6/8/8/8/8/8/7b w KQkq - 0 1"); | ||
|
||
assert.deepEqual(pins(board, "a8"), ["b7"]); | ||
assert.deepEqual( | ||
pins(board, "a8"), | ||
new Map<TSquare, TAllowedMoves>([["b7", []]]) | ||
); | ||
}); | ||
|
||
it("far friendly bishop with bishop pin", () => { | ||
const board = new BoardState("K7/8/8/8/8/8/6B1/7b w KQkq - 0 1"); | ||
|
||
assert.deepEqual( | ||
pins(board, "a8"), | ||
new Map<TSquare, TAllowedMoves>([["g2", ["b7", "c6", "d5", "e4", "f3"]]]) | ||
); | ||
}); | ||
|
||
it("far friendly rook with bishop pin", () => { | ||
const board = new BoardState("K7/8/8/8/8/8/6R1/7b w KQkq - 0 1"); | ||
|
||
assert.deepEqual( | ||
pins(board, "a8"), | ||
new Map<TSquare, TAllowedMoves>([["g2", []]]) | ||
); | ||
}); | ||
|
||
it("adjacent queens", () => { | ||
const board = new BoardState("8/3q4/3R4/3K4/3R4/3q4/8/8 w KQkq - 0 1"); | ||
|
||
assert.deepEqual(pins(board, "d5"), ["d4", "d6"]); | ||
assert.deepEqual( | ||
pins(board, "d5"), | ||
new Map<TSquare, TAllowedMoves>([ | ||
["d4", []], | ||
["d6", []], | ||
]) | ||
); | ||
}); | ||
|
||
it("far queen", () => { | ||
it("far enemy queen with rook pin", () => { | ||
const board = new BoardState("K7/1R6/8/8/8/8/8/7q w KQkq - 0 1"); | ||
|
||
assert.deepEqual(pins(board, "a8"), ["b7"]); | ||
assert.deepEqual( | ||
pins(board, "a8"), | ||
new Map<TSquare, TAllowedMoves>([["b7", []]]) | ||
); | ||
}); | ||
|
||
it("far enemy queen with bishop pin", () => { | ||
const board = new BoardState("K7/8/8/8/8/8/6B1/7q w KQkq - 0 1"); | ||
|
||
assert.deepEqual( | ||
pins(board, "a8"), | ||
new Map<TSquare, TAllowedMoves>([["g2", ["b7", "c6", "d5", "e4", "f3"]]]) | ||
); | ||
}); | ||
|
||
it("far enemy queen with rook pin", () => { | ||
const board = new BoardState("K7/8/8/8/8/8/6R1/7q w KQkq - 0 1"); | ||
|
||
assert.deepEqual( | ||
pins(board, "a8"), | ||
new Map<TSquare, TAllowedMoves>([["g2", []]]) | ||
); | ||
}); | ||
|
||
it("far enemy queen with queen pin", () => { | ||
const board = new BoardState("K7/8/8/8/8/5Q2/8/7q w KQkq - 0 1"); | ||
|
||
assert.deepEqual( | ||
pins(board, "a8"), | ||
new Map<TSquare, TAllowedMoves>([["f3", ["b7", "c6", "d5", "e4"]]]) | ||
); | ||
}); | ||
|
||
it("multiple defenders", () => { | ||
const board = new BoardState("3r4/3P4/3R4/3K4/3R4/3P4/8/3r4 w KQkq - 0 1"); | ||
|
||
assert.deepEqual(pins(board, "d5"), ["d4", "d6"]); | ||
assert.deepEqual( | ||
pins(board, "d5"), | ||
new Map<TSquare, TAllowedMoves>([ | ||
["d4", []], | ||
["d6", []], | ||
]) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters