bhlangonijr / chesslib

chess library for legal move generation, FEN/PGN parsing and more
Apache License 2.0
223 stars 78 forks source link

KBvKB with bishops on different color squares treated as insufficient material #33

Closed dlbbld closed 3 years ago

dlbbld commented 3 years ago

KBvKB positions with bishops on different color squares are not insufficient material positions as well known, as a mate is still possible.

But when I tried, I found this to be treated as insufficient material. Can you please check?

final Board board = new Board();
board.loadFromFen("8/8/8/4k3/5b2/3K4/8/2B5 w - - 0 1");
System.out.println("isInsufficientMaterial: Expected=false, Actual=" + board.isInsufficientMaterial());

The output is as below, with latest version 1.1.22, which is not as expected

isInsufficientMaterial: Expected=false, Actual=true
bhlangonijr commented 3 years ago

Hello @dlbbld , The FEN you have provided is indeed a dead draw: You have ONE bishop left on each side. You need these two bishops on same side not to be insufficient material.

I've added this test:

@Test
    public void testInsufficientMaterial() {

        final Board board = new Board();
        board.loadFromFen("8/8/8/4k3/8/3K4/8/2BB4 w - - 0 1");

        assertFalse(board.isInsufficientMaterial());

        board.loadFromFen("8/8/8/4k3/5b2/3K4/8/2B5 w - - 0 1");

        assertTrue(board.isInsufficientMaterial());
    }
dlbbld commented 3 years ago

Hi Carlos

KBvKB falls under the insufficient material rule for bishops on same colour squares, but not for bishops on different colour squares. In this case, a mate is still possible (with the dear support of the opponent). One side can move his king to a corner with the same colour square as the opponent bishop, let his bishop block on own side, the opponent king on the other side so that the opponent bishop can mate. This mate does not work with bishops on the same colour square, for here the bishop cannot block.

I choose a FEN with bishops on the same colour squares by accident. Here the code is correct and flags the position as insufficient material. But for bishops on different colour squares, the code also flags the position as insufficient material, which is incorrect.

final Board board = new Board();

final String bishopOnSameColorSquares = "8/8/8/4k3/5b2/3K4/8/2B5 w - - 0 1";
board.loadFromFen(bishopOnSameColorSquares);
System.out.println("isInsufficientMaterial: Expected=true, Actual=" + board.isInsufficientMaterial());

final String bishopOnDifferentColorSquares = "8/8/8/4k3/5b2/3K4/2B5/8 w - - 0 1";
board.loadFromFen(bishopOnDifferentColorSquares);
System.out.println("isInsufficientMaterial: Expected=false, Actual=" + board.isInsufficientMaterial());

The output is as below, with latest version 1.1.23, which is not as expected for bishops on different colour squares:

isInsufficientMaterial: Expected=true, Actual=true
isInsufficientMaterial: Expected=false, Actual=true
bhlangonijr commented 3 years ago

Oh well that's true: https://syzygy-tables.info/?fen=8/8/8/8/8/8/b7/k1K1B3_w_-_-_0_1. There's a rule in place which flags insufficient material if both sides has <= 1 minor piece. I will fix that in next release. Thank you.