Skip to content

Commit

Permalink
Documented BackwardPawnEval (chesslablab#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm authored Oct 21, 2024
1 parent 32196e8 commit dcdf323
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Eval/BackwardPawnEval.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
use Chess\Variant\Classical\PGN\AN\Color;
use Chess\Variant\Classical\PGN\AN\Piece;

/**
* Backward Pawn Evaluation
*
* A backward pawn is the last pawn protecting other pawns in its chain. It is
* considered a weakness because it cannot advance safely.
*/
class BackwardPawnEval extends AbstractEval implements
ElaborateEvalInterface,
ExplainEvalInterface,
Expand All @@ -16,10 +22,23 @@ class BackwardPawnEval extends AbstractEval implements
use ElaborateEvalTrait;
use ExplainEvalTrait;

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

/**
* Isolated pawn evaluation.
*
* @var array
*/
private array $isolatedPawnEval;

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

/**
* Returns true if the given pawn can be defended by other pawns in its chain.
*
* @param \Chess\Variant\AbstractPiece $pawn
* @param string $file
* @return bool
*/
private function isDefensible(AbstractPiece $pawn, string $file): bool
{
if ($pawn->rank() == 2 || $pawn->rank() == $this->board->square::SIZE['ranks'] - 1) {
Expand Down Expand Up @@ -98,6 +124,11 @@ private function isDefensible(AbstractPiece $pawn, string $file): bool
return false;
}

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

0 comments on commit dcdf323

Please sign in to comment.