mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00:00
LibChess: Add UCIEndpoint for writing UCI chess engines
This commit is contained in:
parent
e80d0abb2c
commit
7331b2b2f6
Notes:
sideshowbarker
2024-07-19 03:22:12 +09:00
Author: https://github.com/petelliott
Commit: 7331b2b2f6
Pull-request: https://github.com/SerenityOS/serenity/pull/3214
Issue: https://github.com/SerenityOS/serenity/issues/3171
Issue: https://github.com/SerenityOS/serenity/issues/3187
Reviewed-by: https://github.com/Dexesttp
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/awesomekling
7 changed files with 867 additions and 2 deletions
|
@ -53,6 +53,25 @@ String char_for_piece(Chess::Type type)
|
|||
}
|
||||
}
|
||||
|
||||
Chess::Type piece_for_char_promotion(const StringView& str)
|
||||
{
|
||||
String string = String(str).to_lowercase();
|
||||
if (string == "")
|
||||
return Type::None;
|
||||
if (string == "n")
|
||||
return Type::Knight;
|
||||
if (string == "b")
|
||||
return Type::Bishop;
|
||||
if (string == "r")
|
||||
return Type::Rook;
|
||||
if (string == "q")
|
||||
return Type::Queen;
|
||||
if (string == "k")
|
||||
return Type::King;
|
||||
|
||||
return Type::None;
|
||||
}
|
||||
|
||||
Colour opposing_colour(Colour colour)
|
||||
{
|
||||
return (colour == Colour::White) ? Colour::Black : Colour::White;
|
||||
|
@ -82,11 +101,18 @@ Square::Square(const StringView& name)
|
|||
String Square::to_algebraic() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append(file - 'a');
|
||||
builder.append(rank - '1');
|
||||
builder.append(file + 'a');
|
||||
builder.append(rank + '1');
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
Move::Move(const StringView& algebraic)
|
||||
: from(algebraic.substring_view(0, 2))
|
||||
, to(algebraic.substring_view(2, 2))
|
||||
, promote_to(piece_for_char_promotion((algebraic.length() >= 5) ? algebraic.substring_view(4, 1) : ""))
|
||||
{
|
||||
}
|
||||
|
||||
String Move::to_long_algebraic() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue