mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibChess: Remove use of DeprecatedString in Move::from_algebraic()
This commit is contained in:
parent
a10cc37ef0
commit
20d517f1da
Notes:
sideshowbarker
2024-07-16 22:17:03 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/20d517f1da Pull-request: https://github.com/SerenityOS/serenity/pull/18487
1 changed files with 12 additions and 12 deletions
|
@ -118,7 +118,7 @@ ErrorOr<String> Move::to_long_algebraic() const
|
|||
|
||||
Move Move::from_algebraic(StringView algebraic, const Color turn, Board const& board)
|
||||
{
|
||||
DeprecatedString move_string = algebraic;
|
||||
auto move_string = algebraic;
|
||||
Move move({ 50, 50 }, { 50, 50 });
|
||||
|
||||
if (move_string.contains('-')) {
|
||||
|
@ -132,10 +132,10 @@ Move Move::from_algebraic(StringView algebraic, const Color turn, Board const& b
|
|||
|
||||
if (algebraic.contains('#')) {
|
||||
move.is_mate = true;
|
||||
move_string = move_string.substring(0, move_string.length() - 1);
|
||||
move_string = move_string.substring_view(0, move_string.length() - 1);
|
||||
} else if (algebraic.contains('+')) {
|
||||
move.is_check = true;
|
||||
move_string = move_string.substring(0, move_string.length() - 1);
|
||||
move_string = move_string.substring_view(0, move_string.length() - 1);
|
||||
}
|
||||
|
||||
if (algebraic.contains('=')) {
|
||||
|
@ -144,36 +144,36 @@ Move Move::from_algebraic(StringView algebraic, const Color turn, Board const& b
|
|||
move_string = parts[0];
|
||||
}
|
||||
|
||||
move.to = Square(move_string.substring(move_string.length() - 2, 2));
|
||||
move_string = move_string.substring(0, move_string.length() - 2);
|
||||
move.to = Square(move_string.substring_view(move_string.length() - 2, 2));
|
||||
move_string = move_string.substring_view(0, move_string.length() - 2);
|
||||
|
||||
if (move_string.contains('x')) {
|
||||
move.is_capture = true;
|
||||
move_string = move_string.substring(0, move_string.length() - 1);
|
||||
move_string = move_string.substring_view(0, move_string.length() - 1);
|
||||
}
|
||||
|
||||
if (move_string.is_empty() || move_string.characters()[0] >= 'a') {
|
||||
if (move_string.is_empty() || move_string[0] >= 'a') {
|
||||
move.piece = Piece(turn, Type::Pawn);
|
||||
} else {
|
||||
move.piece = Piece(turn, piece_from_char(move_string[0]));
|
||||
move_string = move_string.substring(1, move_string.length() - 1);
|
||||
move_string = move_string.substring_view(1, move_string.length() - 1);
|
||||
}
|
||||
|
||||
Square::for_each([&](Square const& square) {
|
||||
if (!move_string.is_empty()) {
|
||||
if (board.get_piece(square).type == move.piece.type && board.is_legal(Move(square, move.to), turn)) {
|
||||
if (move_string.length() >= 2) {
|
||||
if (square == Square(move_string.substring(0, 2))) {
|
||||
if (square == Square(move_string.substring_view(0, 2))) {
|
||||
move.from = square;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
} else if (move_string.characters()[0] <= 57) {
|
||||
if (square.rank == (move_string.characters()[0] - '0')) {
|
||||
} else if (move_string[0] <= 57) {
|
||||
if (square.rank == (move_string[0] - '0')) {
|
||||
move.from = square;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
} else {
|
||||
if (square.file == (move_string.characters()[0] - 'a')) {
|
||||
if (square.file == (move_string[0] - 'a')) {
|
||||
move.from = square;
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue