diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 03cc6c0..472277c 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -3,7 +3,7 @@ return (new PhpCsFixer\Config()) ->setRules([ '@PSR12' => true, - 'array_syntax' => ['syntax' => 'short'], + '@PHP74Migration' => true, 'binary_operator_spaces' => ['operators' => ['=>' => 'single_space', '=' => 'single_space']], 'blank_line_before_statement' => ['statements' => ['return']], 'cast_spaces' => true, @@ -12,8 +12,6 @@ 'fully_qualified_strict_types' => true, 'phpdoc_separation' => true, 'native_function_invocation' => ['include' => ['@all']], - 'new_with_braces' => true, - 'no_blank_lines_after_class_opening' => true, 'no_extra_blank_lines' => true, 'no_spaces_around_offset' => ['positions' => ['inside', 'outside']], 'no_unneeded_control_parentheses' => true, diff --git a/README.md b/README.md index 696d920..494e724 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ detection - basically everything but the AI. NOTE: this started as a port of [chess.js](https://github.com/jhlywa/chess.js) for php, forked from [ryanhs/chess.php](https://github.com/ryanhs/chess.php) [![Latest Stable Version](https://poser.pugx.org/p-chess/chess/v/stable)](https://packagist.org/p-chess/chess) -[![buddy branch](https://app.buddy.works/akondas/chess/repository/branch/master/badge.svg?token=bfd952ec0cee0cb4db84dbd50ded487354ee6c9f37a7034f7c46425fed70dea7 "buddy branch")](https://app.buddy.works/akondas/chess/repository/branch/master) [![MIT License](https://poser.pugx.org/p-chess/chess/license)](https://packagist.org/packages/p-chess/chess) ## Installation @@ -116,13 +115,13 @@ There is still a lot to do in this topic. ### Chess::move() -| iteration | mean | comment | -|-----------|-------|---------| -| 1 | 548.819μs | initial | -| 2 | 447.973μs | replace fen with json_encode in history position (inThreefoldRepetition cache) | -| 3 | 340.375μs | replace fen with json_encode in generateMoves | -| 4 | 333.145μs | add boardHash calculation on make/undo move | -| 5 | 25.917μs | :fire: add cache for moveToSAN method | +| iteration | mean | comment | +|:---------:|:---------:|--------------------------------------------------------------------------------| +| 1 | 548.819μs | initial | +| 2 | 447.973μs | replace fen with json_encode in history position (inThreefoldRepetition cache) | +| 3 | 340.375μs | replace fen with json_encode in generateMoves | +| 4 | 333.145μs | add boardHash calculation on make/undo move | +| 5 | 25.917μs | :fire: add cache for moveToSAN method | ## Other documentation diff --git a/composer.json b/composer.json index 5d7a142..9cf8d00 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "ext-json": "*" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^3.37", + "friendsofphp/php-cs-fixer": "^3.48", "imagine/imagine": "^1.3", "johnkary/phpunit-speedtrap": "^4.0", "phpbench/phpbench": "^1.2", diff --git a/tests/ChessPublicator.php b/tests/ChessPublicator.php index b613c42..4b308fc 100644 --- a/tests/ChessPublicator.php +++ b/tests/ChessPublicator.php @@ -56,7 +56,7 @@ public function undoMovePublic(): ?Move return $this->undoMove(); } - public function moveToSANPublic(?Move $move): void + public function moveToSANPublic(Move $move): void { $this->moveToSAN($move); } @@ -81,17 +81,17 @@ public function perft(int $depth, bool $full = false) if (!$this->kingAttacked($color)) { if ($depth - 1 > 0) { - $childs = $this->perft($depth - 1, true); - if (!\is_array($childs)) { + $children = $this->perft($depth - 1, true); + if (!\is_array($children)) { continue; } - $nodes += $childs['nodes']; - $captures += $childs['captures']; - $enPassants += $childs['enPassants']; - $castles += $childs['castles']; - $promotions += $childs['promotions']; - $checks += $childs['checks']; - $checkmates += $childs['checkmates']; + $nodes += $children['nodes']; + $captures += $children['captures']; + $enPassants += $children['enPassants']; + $castles += $children['castles']; + $promotions += $children['promotions']; + $checks += $children['checks']; + $checkmates += $children['checkmates']; } else { ++$nodes; } diff --git a/tests/MoveTest.php b/tests/MoveTest.php index 5619158..cd142ce 100644 --- a/tests/MoveTest.php +++ b/tests/MoveTest.php @@ -237,6 +237,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('e4', $undo->san); self::assertEquals('e4', (string) $undo); @@ -251,6 +252,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('Nf6', $undo->san); // normal pawn capture @@ -264,6 +266,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('exd5', $undo->san); // en passant capture @@ -277,6 +280,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('dxe6', $undo->san); // normal knight capture @@ -290,6 +294,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('Nxd5', $undo->san); // promotion @@ -304,6 +309,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('d8=R', $undo->san); // check @@ -317,6 +323,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('Rf8+', $undo->san); // checkmate @@ -330,6 +337,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('Rb8#', $undo->san); // ambiguous moves: row @@ -343,6 +351,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('N4xd6', $undo->san); // ambiguous moves: rank > 0 & file > 0 @@ -356,6 +365,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('Qd5xd4', $undo->san); // ambiguous moves: col @@ -369,6 +379,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('Nexd6', $undo->san); // ambiguous moves: col @@ -382,6 +393,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('Ncxd6', $undo->san); // ambiguous moves: normal capture @@ -395,6 +407,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('Nxd6', $undo->san); // ambiguous moves: normal capture @@ -408,6 +421,7 @@ public function testMoveToSAN(): void )); $chess->makeMovePublic($move); $undo = $chess->undo(); + self::assertNotNull($undo); self::assertEquals('Rxd6', $undo->san); // generate moves test