From 7004f571fbff9d779caa7af72c51769b14f4f31e Mon Sep 17 00:00:00 2001 From: ryan597 Date: Fri, 22 Dec 2023 22:16:53 +0000 Subject: [PATCH 1/4] check cmake host --- CMakeLists.txt | 4 ++-- src/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0d68ac..f0f8451 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,9 @@ set(CMAKE_CXX_STANDARD 20) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") if(CMAKE_BUILD_TYPE MATCHES Debug) - if(MSVC) + if(CMAKE_HOST_WIN32) #/WX - add_compile_options(/W4) + add_compile_options(-Wno-unused-parameter) else() # Flags to be added once refactor is done #-Werror diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25664e0..1b157ec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,7 @@ add_library(nginlib STATIC add_executable(NGin ${SOURCES}) -if(MSVC) +if(CMAKE_HOST_WIN32) set(ENABLED_WARNINGS /Wall) else() set(ENABLED_WARNING -Wall -Wextra -Wshadow -Wnon-virtual-dtor -pedantic -Wold-style-cast -Wcast-align diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0a0fa37..24e7760 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,7 +26,7 @@ include(CTest) include(Catch) catch_discover_tests(tests) -if( NOT MSVC AND CMAKE_BUILD_TYPE MATCHES Debug) +if( NOT CMAKE_HOST_WIN32 AND CMAKE_BUILD_TYPE MATCHES Debug) setup_target_for_coverage_lcov(NAME coverage EXECUTABLE tests EXCLUDE "/usr/*" "cmake/catch2/*" From aa5615ae8aae21f577e3c79fda9684c8709ba6b1 Mon Sep 17 00:00:00 2001 From: ryan597 Date: Fri, 22 Dec 2023 22:17:21 +0000 Subject: [PATCH 2/4] warning for int conversion --- src/board.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/board.cpp b/src/board.cpp index 35f38cd..c4649e0 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -1,6 +1,6 @@ #include "board.hpp" -auto make_type_ptr(int i, char col, char file, char rank) +auto make_type_ptr(size_t i, char col, char file, char rank) -> std::unique_ptr { switch (i) { case 0: @@ -34,7 +34,7 @@ Board::Board() { const std::vector back_rank{'R', 'N', 'B', 'K', 'Q', 'B', 'N', 'R'}; m_pieces.reserve(32); - for (std::size_t i = 0; i < back_rank.size(); i++) { + for (size_t i = 0; i < back_rank.size(); i++) { char file = char('a' + i); m_pieces.emplace_back(std::make_unique('w', Square{file, '2'})); m_pieces.emplace_back(make_type_ptr(i, 'w', file, '1')); @@ -105,7 +105,7 @@ auto Board::print_position(std::string &fen) -> void { if (std::find(pieces.begin(), pieces.end(), i) != std::end(pieces)) { asci_position += i; } else if (isdigit(i)) { - asci_position += std::string(i - '0', '.'); + asci_position += std::string(size_t(i - '0'), '.'); } else if (i == '/') { asci_position += '\n'; } else if (i == ' ') { @@ -125,14 +125,14 @@ auto Board::print() -> void { auto rank = piece->get_rank(); // when printing we start at the top left of the board (a8), so rank=7 (0 // index for the array) and file=0 (0 indexed for the array) - int current_square = 64 - rank * 8 + file - 8; + size_t current_square = 64 - rank * 8 + file - 8; board_position.at(current_square) = piece->get_type(); if (piece->get_colour() == 'b') { board_position.at(current_square) += 32; // convert to lowercase } } - for (int i = 0; i < 64; i++) { + for (size_t i = 0; i < 64; i++) { std::cout << board_position.at(i); if ((i + 1) % 8 == 0) { std::cout << '\n'; @@ -167,7 +167,7 @@ auto Board::move(const std::string ¬ation) -> bool { auto Board::parse_move(const std::string &move) -> void { // Square src; Square dst; - int pad{}; + size_t pad{}; if (move.at(move.size() - 1) == '+' || move.at(move.size() - 1) == '#') { pad++; } From e4e3997343691293588dafeac97adfd2a8426ff4 Mon Sep 17 00:00:00 2001 From: ryan597 Date: Fri, 22 Dec 2023 22:17:39 +0000 Subject: [PATCH 3/4] warning for int conversion --- src/main.cpp | 2 +- src/piece.hpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 25d6f9a..23653e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include "board.cpp" #include "player.cpp" -auto main(int argc, char **argv) -> int { +auto main() -> int { Player player1{"White", 1500.0, 'w'}; Player player2{"Black", 1600.0, 'b'}; diff --git a/src/piece.hpp b/src/piece.hpp index 3f11115..759a2bd 100644 --- a/src/piece.hpp +++ b/src/piece.hpp @@ -19,9 +19,9 @@ struct Square { Square(char file, char rank); Square(std::string position); struct HashFunction { - auto operator()(const Square &position) const -> int { - int rowHash = std::hash()(position.file); - int colHash = std::hash()(position.rank) << 1; + auto operator()(const Square &position) const -> size_t { + size_t rowHash = std::hash()(position.file); + size_t colHash = std::hash()(position.rank) << 1; return rowHash ^ colHash; } }; @@ -44,8 +44,8 @@ class Piece { Piece(char type, char colour, Square position); auto get_type() const -> char; auto get_colour() const -> char; - auto get_file() const -> int; - auto get_rank() const -> int; + auto get_file() const -> size_t; + auto get_rank() const -> size_t; auto get_square() const -> Square; auto move(Square dest) -> void; auto virtual generate_legal_moves(Board &board) From 69960d546e3a514db6aad331f26129f412b8ba60 Mon Sep 17 00:00:00 2001 From: ryan597 Date: Fri, 22 Dec 2023 22:18:30 +0000 Subject: [PATCH 4/4] int conversion warning --- src/piece.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/piece.cpp b/src/piece.cpp index cca01ff..b45ec13 100644 --- a/src/piece.cpp +++ b/src/piece.cpp @@ -50,9 +50,9 @@ auto Piece::get_type() const -> char { return m_type; } auto Piece::get_colour() const -> char { return m_colour; } -auto Piece::get_file() const -> int { return int(m_position.file - 'a'); } +auto Piece::get_file() const -> size_t { return size_t(m_position.file - 'a'); } -auto Piece::get_rank() const -> int { return int(m_position.rank - '1'); } +auto Piece::get_rank() const -> size_t { return size_t(m_position.rank - '1'); } auto Piece::get_square() const -> Square { return m_position; }