Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the bad bishop evaluation #208

Closed
programarivm opened this issue May 9, 2022 · 7 comments
Closed

Implement the bad bishop evaluation #208

programarivm opened this issue May 9, 2022 · 7 comments
Assignees

Comments

@programarivm
Copy link
Member

programarivm commented May 9, 2022

A new evaluation feature needs to be implemented in order to keep track of bad bishops. A bad bishop is a bishop whose mobility is restricted by its own pawns. Sometimes it becomes such a bad piece that it's like playing with one less piece.

Thus, a new file named BadBishopEvaluation.php needs to be implemented in a similar way as other evaluation features, for example:

Also Chess\Evaluation\BadBishopEvaluation should be TDDed accordingly:

With the new feature implemented, we'll be able to display a nice bar chart pointing out whether or not a bad bishop is found on the chessboard.

For further information please visit:

Keep it up, and happy coding and learning!

@programarivm
Copy link
Member Author

programarivm commented Jul 20, 2022

Hi @MarcinGladkowski,

Let's try to define what a bad bishop is in terms of the pawns on its side only, this way it'll be differentiated from a blocked bishop I suppose.

Here are some hints:

  • If most of your pawns are on light squares, then the light-squared bishop can be restricted (the same is true for dark-squared bishops and pawns on dark squares)

  • If you have just one bishop, you should try to place your pawns on the squares of the opposite color of your bishop. If you do this, then you can control squares of both colors, and your bishop can move more freely

  • The rule of thumb claims that a bishop suffers if the pawns are blocked and stand on squares of the colour the bishop moves on. If the bishop is not hemmed in by his own pawns we speak of a "good bishop"

Thus, what about creating a bunch of tests with specific results for chess positions according to these hints?

For further information please visit:

Happy learning and coding!

@programarivm
Copy link
Member Author

This is a suggested result for the following sample position:

chessboard

White's bishop is being blocked by 0 pawns while Black's bishop is blocked by 5 pawns.

<?php

namespace Chess\Tests\Unit\Eval;

use Chess\Eval\BadBishopEval;
use Chess\FEN\StrToBoard;
use Chess\Tests\AbstractUnitTestCase;

class BadBishopEvalTest extends AbstractUnitTestCase
{
    /**
     * @test
     */
    public function position_01()
    {
        $fen = '8/5b2/p2k4/1p1p1p1p/1P1K1P1P/2P1PB2/8/8 w - - 0 1';

        $board = (new StrToBoard($fen))->create();

        $expected = [
            'w' => 0,
            'b' => 5,
        ];

        $badBishopEval = (new BadBishopEval($board))->eval();

        $this->assertSame($expected, $badBishopEval);
    }
}

@MarcinGladkowski
Copy link
Contributor

MarcinGladkowski commented Jul 21, 2022

Great! Thanks @programarivm for that example. I will prepare solution for it.

Happy learning and coding!

@programarivm
Copy link
Member Author

programarivm commented Jul 21, 2022

Thanks! Shall we do it test by test?

I just found this position with a bad bishop on c2 and was wondering which expected result would make sense.

2-1-300x300

Keep it up and happy learning and coding.

@programarivm
Copy link
Member Author

programarivm commented Jul 21, 2022

This is a position with a bad bishop on d7.

chess-position

Which result should be expected?

w = 2
b = 5

@programarivm
Copy link
Member Author

programarivm commented Jul 21, 2022

This is a bad bishop on c8.
chess-position

w = 1
b = 6

@programarivm
Copy link
Member Author

programarivm commented Aug 4, 2022

@MarcinGladkowski the samples have been updated with an expected result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants