-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement figurine algebraic notation #578
feat: implement figurine algebraic notation #578
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@programarivm Would like to know your thoughts, will complete the development for this PR based on the knowledge. Regards.
|
||
use Chess\Variant\Classical\PGN\Move; | ||
|
||
class FanMovetext extends SanMovetext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some thought, I concluded it would be better to extend from SanMovetext
as most of the logic could be reused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KartikWatts, Chess\Movetext\FanMovetext
can definitely be extended from Chess\Movetext\SanMovetext
.
<?php
namespace Chess\Movetext;
class FanMovetext extends SanMovetext
{
public function validate(): string
{
$validated = parent::validate();
return $this->toFan($validated);
}
public function filtered($comments = true, $nags = true): string
{
$filtered = parent::filtered($comments, $nags);
return $this->toFan($filtered);
}
protected function toFan(string $movetext)
{
// TODO
}
}
Keep it up,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, after some thought, I realized that both $validated
and $movetext
are strings, so for cases where comments and nags are also included, simple conversion as in Js-utils won't work, but rather we have to traverse through the string with explode(' ', ...
to convert only the pieces and not the whole string in toFan
. I didn't find it optimum to traverse two times separately, for validate and filtered methods.
So, conversely, I found it better to have the implementation to convert the properties in proper format straight-way during insert, so that we won't be required to convert them separately later.
Instead, I maintained $sanMoves
differently which can be utilized for validation purposes.
Though If we decide it better to call toFan two times rather, let me know, in that case we can traverse through the array: foreach (explode(' ', $this->validated) as $key => $val) {
in toFan
method, instead of insert
as currently done.
$movetext = '1.d4 Nf6 2.Nf3 e6 3.c4 Bb4+ 4.Nbd2 O-O 5.a3 Be7 6.e4 d6 7.Bd3 c5'; | ||
|
||
$expected = [ 'd4', '♘f6', '♘f3', 'e6', 'c4', '♗b4+', '♘bd2', 'O-O', 'a3', '♗e7', 'e4', 'd6', '♗d3', 'c5' ]; | ||
|
||
$this->assertEquals($expected, (new FanMovetext(self::$move, $movetext))->moves); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My most important question as discussed in the issue discussion as well was to understand, if this is the correct test case that satisfies the requirement, i.e. for standard notation provided the moves would be in FAN, if this is true I'll extend on to it to write more test cases based on the understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably the best thing to do is to extend from SanMovetext
as described above.
Replaced R, N and B with miniature piece icons.
@KartikWatts I hope this helps. Keep it up, |
Revert the changes back
Also the changes in Let's recap, this the way to proceed now:
Keep it up and happy learning! |
public function get_san_movetext() | ||
{ | ||
$movetext = '1.d4 Nf6 2.Nf3 e6 3.c4 Bb4+ 4.Nbd2 O-O 5.a3 Be7 6.e4 d6 7.Bd3 c5'; | ||
|
||
$expected = [ 'd4', '♘f6', '♘f3', 'e6', 'c4', '♗b4+', '♘bd2', 'O-O', 'a3', '♗e7', 'e4', 'd6', '♗d3', 'c5' ]; | ||
|
||
$this->assertEquals($expected, (new FanMovetext(self::$move, $movetext))->moves); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function get_san_moves() | ||
{ | ||
$movetext = '1.d4 ♘f6 2.♘f3 e6 3.c4 ♗b4+ 4.♘bd2 O-O 5.a3 ♗e7 6.e4 d6 7.♗d3 c5'; | ||
|
||
$expected = [ 'd4', 'Nf6', 'Nf3', 'e6', 'c4', 'Bb4+', 'Nbd2', 'O-O', 'a3', 'Be7', 'e4', 'd6', 'Bd3', 'c5' ]; | ||
|
||
$this->assertEquals($expected, (new FanMovetext(self::$move, $movetext))->sanMoves); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that we have toFan
method in our FanMoveText class, it only make more sense if the class has ability to receive SAN text as well in the constructor itself.
Likewise, having the ability to get SAN moves is nice.
So, I have implemented 2 tests for the scenarios, let me know your thoughts on this. If approved I can write more tests for other possible cases. Else I can remove the tests.
closes #487
This PR implements FAN notation.