From 26c44a0ff4e56b6f298d4f5a894a0db43e458597 Mon Sep 17 00:00:00 2001 From: overflowerror Date: Sun, 7 Jan 2024 13:21:42 +0100 Subject: [PATCH] feat: Add castles notation --- src/Game/Move.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Game/Move.php b/src/Game/Move.php index 2b4d39f..fd4d384 100644 --- a/src/Game/Move.php +++ b/src/Game/Move.php @@ -37,9 +37,21 @@ class Move { ); } + public function getLong(): string { + if ($this->castleWith) { + if (abs($this->piece->getPosition()->file - $this->castleWith->getPosition()->file) > 3) { + return "O-O-O"; + } else { + return "O-O"; + } + } else { + return $this->piece . " " . + $this->piece->getType()->getShort() . ($this->captures ? "x" : "") . $this->target . + ($this->promoteTo ? $this->promoteTo->getShort() : ""); + } + } + public function __toString(): string { - return $this->piece . " " . - $this->piece->getType()->getShort() . ($this->captures ? "x" : "") . $this->target . - ($this->promoteTo ? $this->promoteTo->getShort() : ""); + return $this->getLong(); } } \ No newline at end of file