-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/castling ability in chess960 (#749)
* Implemented Chess\Variant\Chess960\FEN\Str * Optionally skip the shuffle array * Updated CastlingRule * Implemented the validation of the castling ability * Added tests * Implemented Chess\Variant\Chess960\FenToBoardFactory * Refactored Chess\Variant\Chess960\FenToBoardFactory * Refactored Chess\Variant\Chess960\FenToBoardFactory
- Loading branch information
1 parent
a015be5
commit b39a6de
Showing
6 changed files
with
1,328 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Chess\Variant\Chess960\FEN; | ||
|
||
use Chess\Exception\UnknownNotationException; | ||
use Chess\Variant\Chess960\CastlingRule; | ||
use Chess\Variant\Classical\FEN\PiecePlacement; | ||
use Chess\Variant\Classical\FEN\Str as ClassicalStr; | ||
use Chess\Variant\Classical\PGN\Color; | ||
use Chess\Variant\Classical\PGN\Square; | ||
|
||
class Str extends ClassicalStr | ||
{ | ||
public function validate(string $string): string | ||
{ | ||
$fields = explode(' ', $string); | ||
|
||
if (!isset($fields[0]) || | ||
!isset($fields[1]) || | ||
!isset($fields[2]) || | ||
!isset($fields[3]) | ||
) { | ||
throw new UnknownNotationException(); | ||
} | ||
|
||
(new PiecePlacement())->validate($fields[0]); | ||
|
||
(new Color())->validate($fields[1]); | ||
|
||
(new CastlingRule())->validate($fields[2]); | ||
|
||
if ('-' !== $fields[3]) { | ||
(new Square())->validate($fields[3]); | ||
} | ||
|
||
return $string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.