Skip to content

Commit

Permalink
Refactored Chess\Tutor\PiecePhrase
Browse files Browse the repository at this point in the history
  • Loading branch information
programarivm committed Dec 1, 2023
1 parent 6b2c024 commit 207c8f5
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/Tutor/PiecePhrase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ class PiecePhrase
*/
public static $phrase = [
[
'pgn' => "N",
'id' => "N",
'color' => "w",
'meanings' => [
"White's knight",
"white knight",
],
],
[
'pgn' => "n",
'id' => "N",
'color' => "b",
'meanings' => [
"Black's knight",
"black knight",
Expand All @@ -36,12 +38,11 @@ class PiecePhrase

public static function deterministic(AbstractPiece $piece): ?string
{
$pgn = $piece->getColor() === Color::W
? $piece->getId()
: mb_strtolower($piece->getId());

foreach (self::$phrase as $item) {
if ($item['pgn'] === $pgn) {
if (
$item['id'] === $piece->getId() &&
$item['color'] === $piece->getColor()
) {
return "{$item['meanings'][0]} on {$piece->getSq()}";
}
}
Expand Down

0 comments on commit 207c8f5

Please sign in to comment.