Skip to content

Commit

Permalink
Renamed captureSqs as xSqs
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Jan 23, 2024
1 parent 92bdda5 commit 4dcc279
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/Eval/PressureEval.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(AbstractBoard $board)
$this->result[$piece->color] = [
...$this->result[$piece->color],
...array_intersect(
$piece->captureSqs,
$piece->xSqs,
$this->board->sqCount['used'][$piece->oppColor()]
)
];
Expand Down
2 changes: 1 addition & 1 deletion src/Eval/SpaceEval.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(AbstractBoard $board)
} elseif ($piece->id === Piece::P) {
$this->result[$piece->color] = [
...$this->result[$piece->color],
...$piece->captureSqs,
...$piece->xSqs,
];
} else {
$this->result[$piece->color] = [
Expand Down
30 changes: 15 additions & 15 deletions src/Eval/SqOutpostEval.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@ public function __construct(AbstractBoard $board)

foreach ($this->board->pieces() as $piece) {
if ($piece->id === Piece::P) {
$captureSqs = $piece->captureSqs;
if ($piece->promoRank($this->board->square) !== (int) substr($captureSqs[0], 1)) {
$left = chr(ord($captureSqs[0]) - 1);
$right = chr(ord($captureSqs[0]) + 1);
$xSqs = $piece->xSqs;
if ($piece->promoRank($this->board->square) !== (int) substr($xSqs[0], 1)) {
$left = chr(ord($xSqs[0]) - 1);
$right = chr(ord($xSqs[0]) + 1);
if (
!$this->isFileAttacked($piece->color, $captureSqs[0], $left) &&
!$this->isFileAttacked($piece->color, $captureSqs[0], $right)
!$this->isFileAttacked($piece->color, $xSqs[0], $left) &&
!$this->isFileAttacked($piece->color, $xSqs[0], $right)
) {
$this->result[$piece->color][] = $captureSqs[0];
$this->toElaborate[] = $captureSqs[0];
$this->result[$piece->color][] = $xSqs[0];
$this->toElaborate[] = $xSqs[0];
}
if (isset($captureSqs[1])) {
$left = chr(ord($captureSqs[1]) - 1);
$right = chr(ord($captureSqs[1]) + 1);
if (isset($xSqs[1])) {
$left = chr(ord($xSqs[1]) - 1);
$right = chr(ord($xSqs[1]) + 1);
if (
!$this->isFileAttacked($piece->color, $captureSqs[1], $left) &&
!$this->isFileAttacked($piece->color, $captureSqs[1], $right)
!$this->isFileAttacked($piece->color, $xSqs[1], $left) &&
!$this->isFileAttacked($piece->color, $xSqs[1], $right)
) {
$this->result[$piece->color][] = $captureSqs[1];
$this->toElaborate[] = $captureSqs[1];
$this->result[$piece->color][] = $xSqs[1];
$this->toElaborate[] = $xSqs[1];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Variant/Classical/FEN/StrToBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function enPassant(AbstractBoard $board): AbstractBoard
if ($this->fields[3] !== '-') {
foreach ($board->pieces($this->fields[1]) as $piece) {
if ($piece->id === Piece::P) {
if (in_array($this->fields[3], $piece->captureSqs)) {
if (in_array($this->fields[3], $piece->xSqs)) {
$piece->enPassant = $this->fields[3];
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Variant/Classical/P.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

class P extends AbstractPiece
{
public array $captureSqs;
public array $xSqs;

public string $enPassant = '';

public function __construct(string $color, string $sq, Square $square)
{
parent::__construct($color, $sq, Piece::P);

$this->captureSqs = [];
$this->xSqs = [];

$this->flow = [];

Expand All @@ -38,15 +38,15 @@ public function __construct(string $color, string $sq, Square $square)
// capture square
$file = ord($this->file()) - 1;
if ($file >= 97 && $this->nextRank() <= $square::SIZE['ranks']) {
$this->captureSqs[] = chr($file) . $this->nextRank();
$this->xSqs[] = chr($file) . $this->nextRank();
}

// capture square
$file = ord($this->file()) + 1;
if ($file <= 97 + $square::SIZE['files'] - 1 &&
$this->nextRank() <= $square::SIZE['ranks']
) {
$this->captureSqs[] = chr($file) . $this->nextRank();
$this->xSqs[] = chr($file) . $this->nextRank();
}
}

Expand Down Expand Up @@ -96,7 +96,7 @@ public function moveSqs(): array
}

// capture squares
foreach ($this->captureSqs as $sq) {
foreach ($this->xSqs as $sq) {
if (in_array($sq, $this->board->sqCount['used'][$this->oppColor()])) {
$sqs[] = $sq;
}
Expand All @@ -106,7 +106,7 @@ public function moveSqs(): array
$end = end($this->board->history);
if ($end && $end['color'] === $this->oppColor()) {
$enPassant = explode(' ', $end['fen'])[3];
if (in_array($enPassant, $this->captureSqs)) {
if (in_array($enPassant, $this->xSqs)) {
$this->enPassant = $enPassant;
$sqs[] = $enPassant;
}
Expand All @@ -120,7 +120,7 @@ public function moveSqs(): array
public function defendedSqs(): array
{
$sqs = [];
foreach ($this->captureSqs as $sq) {
foreach ($this->xSqs as $sq) {
if (in_array($sq, $this->board->sqCount['used'][$this->color])) {
$sqs[] = $sq;
}
Expand Down
18 changes: 9 additions & 9 deletions src/Variant/Losing/Board.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,25 @@ public function isCheck(): bool
return false;
}

protected function captureSqs(): array
protected function xSqs(): array
{
$captureSqs = [];
$xSqs = [];
foreach ($this->pieces($this->turn) as $piece) {
foreach ($piece->attacked() as $attacked) {
$captureSqs[] = $attacked->sq;
$xSqs[] = $attacked->sq;
}
}

return $captureSqs;
return $xSqs;
}

public function legal(string $sq): array
{
$moveSqs = $this->pieceBySq($sq)->moveSqs();
$captureSqs = $this->captureSqs();
if ($intersect = array_intersect($moveSqs, $captureSqs)) {
$xSqs = $this->xSqs();
if ($intersect = array_intersect($moveSqs, $xSqs)) {
return array_values($intersect);
} elseif (!$captureSqs) {
} elseif (!$xSqs) {
return $moveSqs;
}

Expand All @@ -100,9 +100,9 @@ public function legal(string $sq): array

public function play(string $color, string $pgn): bool
{
if ($captureSqs = $this->captureSqs()) {
if ($xSqs = $this->xSqs()) {
$move = $this->move->toArray($color, $pgn, $this->castlingRule);
if (in_array($move['to'], $captureSqs)) {
if (in_array($move['to'], $xSqs)) {
return parent::play($color, $pgn);
}
} else {
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/Variant/Classical/PTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function white_a2()

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($captureSquares, $pawn->xSqs);
}

/**
Expand All @@ -44,7 +44,7 @@ public function white_d5()

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($captureSquares, $pawn->xSqs);
}

/**
Expand All @@ -60,7 +60,7 @@ public function white_f7()

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($captureSquares, $pawn->xSqs);
}

/**
Expand All @@ -76,7 +76,7 @@ public function white_f8()

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($captureSquares, $pawn->xSqs);
}

/**
Expand All @@ -92,7 +92,7 @@ public function black_a2()

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($captureSquares, $pawn->xSqs);
}

/**
Expand All @@ -108,6 +108,6 @@ public function black_d5()

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($captureSquares, $pawn->xSqs);
}
}
24 changes: 12 additions & 12 deletions tests/unit/Variant/Dunsany/PTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public function white_a2()

$position = 'a2';
$flow = ['a3'];
$captureSquares = ['b3'];
$xSqs = ['b3'];

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($xSqs, $pawn->xSqs);
}

/**
Expand All @@ -40,11 +40,11 @@ public function white_d5()

$position = 'd5';
$flow = ['d6'];
$captureSquares = ['c6', 'e6'];
$xSqs = ['c6', 'e6'];

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($xSqs, $pawn->xSqs);
}

/**
Expand All @@ -56,11 +56,11 @@ public function white_f7()

$position = 'f7';
$flow = ['f8'];
$captureSquares = ['e8', 'g8'];
$xSqs = ['e8', 'g8'];

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($xSqs, $pawn->xSqs);
}

/**
Expand All @@ -72,11 +72,11 @@ public function white_f8()

$position = 'f8';
$flow = [];
$captureSquares = [];
$xSqs = [];

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($xSqs, $pawn->xSqs);
}

/**
Expand All @@ -88,11 +88,11 @@ public function black_a2()

$position = 'a2';
$flow = ['a1'];
$captureSquares = ['b1'];
$xSqs = ['b1'];

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($xSqs, $pawn->xSqs);
}

/**
Expand All @@ -104,10 +104,10 @@ public function black_d5()

$position = 'd5';
$flow = ['d4'];
$captureSquares = ['c4', 'e4'];
$xSqs = ['c4', 'e4'];

$this->assertSame($position, $pawn->sq);
$this->assertEquals($flow, $pawn->flow);
$this->assertSame($captureSquares, $pawn->captureSqs);
$this->assertSame($xSqs, $pawn->xSqs);
}
}

0 comments on commit 4dcc279

Please sign in to comment.