Skip to content

Commit

Permalink
Documented IsolatedPawnEval (chesslablab#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm authored Oct 22, 2024
1 parent b336e34 commit 5882b81
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Eval/IsolatedPawnEval.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
use Chess\Variant\Classical\PGN\AN\Piece;
use Chess\Variant\Classical\Piece\P;

/**
* Isolated Pawn Evaluation
*
* An isolated pawn has no friendly pawns on the adjacent files. Since it cannot
* be defended by other pawns it is considered a weakness.
*/
class IsolatedPawnEval extends AbstractEval implements
ElaborateEvalInterface,
ExplainEvalInterface,
Expand All @@ -15,8 +21,16 @@ class IsolatedPawnEval extends AbstractEval implements
use ElaborateEvalTrait;
use ExplainEvalTrait;

/**
* The name of the heuristic.
*
* @var string
*/
const NAME = 'Isolated pawn';

/**
* @param \Chess\Variant\AbstractBoard $board
*/
public function __construct(AbstractBoard $board)
{
$this->board = $board;
Expand Down Expand Up @@ -55,6 +69,12 @@ public function __construct(AbstractBoard $board)
$this->elaborate($this->result);
}

/**
* Returns true if the given pawn is isolated.
*
* @param \Chess\Variant\Classical\Piece\P $pawn
* @return bool
*/
private function isIsolated(P $pawn): bool
{
$left = chr(ord($pawn->sq) - 1);
Expand All @@ -75,6 +95,11 @@ private function isIsolated(P $pawn): bool
return true;
}

/**
* Elaborate on the evaluation.
*
* @param array $result
*/
private function elaborate(array $result): void
{
$singular = mb_strtolower('an ' . self::NAME);
Expand Down

0 comments on commit 5882b81

Please sign in to comment.