mirror of
https://github.com/sigmasternchen/php-chess
synced 2025-03-15 07:58:54 +00:00
refactor: Move square color logic to position class
This commit is contained in:
parent
51d01b0953
commit
64b29a881b
1 changed files with 3 additions and 3 deletions
|
@ -401,10 +401,10 @@ class Game {
|
||||||
$result .= ($rank + 1) . " ";
|
$result .= ($rank + 1) . " ";
|
||||||
|
|
||||||
for ($file = 0; $file < 8; $file++) {
|
for ($file = 0; $file < 8; $file++) {
|
||||||
$color = ($rank % 2) ^ ($file % 2);
|
$position = new Position($file, $rank);
|
||||||
$result .= "\033[" . ($color ? 47 : 100) . "m";
|
$result .= "\033[" . ($position->getSquareColor() == Side::WHITE ? 47 : 100) . "m";
|
||||||
|
|
||||||
$piece = current(array_filter($this->pieces, fn($p) => $p->getPosition()->equals(new Position($file, $rank))));
|
$piece = current(array_filter($this->pieces, fn($p) => $p->getPosition()->equals($position)));
|
||||||
if ($piece) {
|
if ($piece) {
|
||||||
if ($piece->getSide() == Side::WHITE) {
|
if ($piece->getSide() == Side::WHITE) {
|
||||||
$result .= "\033[97m";
|
$result .= "\033[97m";
|
||||||
|
|
Loading…
Reference in a new issue