Skip to content
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

Use consteval and constexpr in more places #128

Merged
merged 14 commits into from
Sep 12, 2024
Merged
2 changes: 1 addition & 1 deletion engine/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_library(wisdom-chess-core STATIC
board.cpp board.hpp
board_builder.cpp board_builder.hpp
board_builder.hpp
board_code.cpp board_code.hpp
check.cpp check.hpp
coord.cpp coord.hpp
Expand Down
12 changes: 6 additions & 6 deletions engine/src/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace wisdom
static constexpr int Board_Length_In_Chars = 31;

Board::Board()
: Board { BoardBuilder::fromDefaultPosition() }
: Board { default_board_builder }
{
}

Expand Down Expand Up @@ -136,7 +136,7 @@ namespace wisdom
auto convert = [color](char ch) -> char
{
return color == Color::Black
? gsl::narrow_cast<char> (tolower (ch))
? narrow_cast<char> (tolower (ch))
: ch;
};

Expand Down Expand Up @@ -175,9 +175,9 @@ namespace wisdom
row_string += std::to_string (none_count);

none_count = 0;
char ch = gsl::narrow_cast<char> (toupper (pieceChar (piece)));
char ch = narrow_cast<char> (toupper (pieceChar (piece)));
if (pieceColor (piece) == Color::Black)
ch = gsl::narrow_cast<char> (tolower (ch));
ch = narrow_cast<char> (tolower (ch));

row_string.append (1, ch);
}
Expand Down Expand Up @@ -268,7 +268,7 @@ namespace wisdom
for (int8_t source_col = 0; source_col < Num_Columns; source_col++)
{
int8_t first_source_row = 0;
auto last_source_row = gsl::narrow<int8_t> (Num_Rows - 1);
auto last_source_row = narrow<int8_t> (Num_Rows - 1);

removeInvalidPawns (result, first_source_row, source_col, result.my_squares);
removeInvalidPawns (result, last_source_row, source_col, result.my_squares);
Expand Down Expand Up @@ -304,7 +304,7 @@ namespace wisdom
coord_end,
finder
);
auto diff = gsl::narrow<int> (result - coord_begin);
auto diff = narrow<int> (result - coord_begin);

return (result != coord_end)
? std::make_optional<Coord> (Coord::fromIndex (diff))
Expand Down
4 changes: 2 additions & 2 deletions engine/src/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ namespace wisdom
constexpr auto coordColor (Coord coord) -> Color
{
int parity = (coord.row() % 2 + coord.column() % 2) % 2;
return colorFromColorIndex (gsl::narrow_cast<int8_t> (parity));
return colorFromColorIndex (narrow_cast<int8_t> (parity));
}

// white moves up (-)
Expand All @@ -262,6 +262,6 @@ namespace wisdom
static_assert (std::is_integral_v<IntegerType>);
assert (color == Color::Black || color == Color::White);
int8_t color_as_int = toInt8 (color);
return gsl::narrow_cast<IntegerType> (-1 + 2 * (color_as_int - 1));
return narrow_cast<IntegerType> (-1 + 2 * (color_as_int - 1));
}
}
143 changes: 0 additions & 143 deletions engine/src/board_builder.cpp

This file was deleted.

Loading
Loading