diff options
| -rw-r--r-- | .github/workflows/cmake-single-platform.yml | 5 | ||||
| -rw-r--r-- | CMakeLists.txt | 19 | ||||
| -rw-r--r-- | src/board.cpp | 11 | ||||
| -rw-r--r-- | src/board.hpp | 2 | ||||
| -rw-r--r-- | src/fen.cpp | 2 | ||||
| -rw-r--r-- | src/main.cpp | 2 | ||||
| -rw-r--r-- | src/moves.cpp | 5 |
7 files changed, 34 insertions, 12 deletions
diff --git a/.github/workflows/cmake-single-platform.yml b/.github/workflows/cmake-single-platform.yml index c02bed4..844556e 100644 --- a/.github/workflows/cmake-single-platform.yml +++ b/.github/workflows/cmake-single-platform.yml @@ -31,10 +31,13 @@ jobs: env: CC: gcc-14 CXX: g++-14 - run: cmake -B build -S . + run: cmake -B build -S . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - name: Build env: CC: gcc-14 CXX: g++-14 run: cmake --build build + + - name: Run clang-tidy + run: clang-tidy src/*.cpp -p build diff --git a/CMakeLists.txt b/CMakeLists.txt index 3782845..3f5a42f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,3 +14,22 @@ file(GLOB_RECURSE SOURCE_FILES src/*.c src/*.cpp src/*.h src/*.hpp) add_executable(${PROJECT_NAME} ${SOURCE_FILES}) target_include_directories(${PROJECT_NAME} PRIVATE src) + +if (MSVC) + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +else() + target_compile_options(${PROJECT_NAME} PRIVATE + -Wall + -Wextra + -Wpedantic + -Werror + ) +endif() + +target_compile_options(${PROJECT_NAME} PRIVATE + -fsanitize=address,undefined +) + +target_link_options(${PROJECT_NAME} PRIVATE + -fsanitize=address,undefined +) diff --git a/src/board.cpp b/src/board.cpp index 081cc7d..172a9be 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -5,13 +5,11 @@ #include <iostream> #include <print> #include <string> -#include <utility> - -const char toChar(pieceType type) { +char toChar(pieceType type) { switch (type) { case NONE: - return '.'; + return '.'; case PAWN: return 'P'; case KNIGHT: @@ -25,7 +23,8 @@ const char toChar(pieceType type) { case KING: return 'K'; default: - assert(false && "Unknown piece"); + std::cout << "\n" << type << "\n"; + assert(false && "Unknown piece" && type); return '?'; } } @@ -90,4 +89,4 @@ void printBoard(board *b) { std::println("Castling: {}", b->castle); } -void PlayMove(Move move, board *b) { return; } +// void PlayMove(Move move, board *b) { return; } diff --git a/src/board.hpp b/src/board.hpp index 23f89ad..afdb938 100644 --- a/src/board.hpp +++ b/src/board.hpp @@ -13,7 +13,7 @@ enum pieceType { KING, }; -const char toChar(pieceType type); +char toChar(pieceType type); struct Piece { bool color; diff --git a/src/fen.cpp b/src/fen.cpp index a6773c2..9c3154c 100644 --- a/src/fen.cpp +++ b/src/fen.cpp @@ -25,7 +25,7 @@ void setBoardFen(std::string fen, board *b) { }; parserState state = POSITION; - for (int i = 0; i < fen.length(); i++) { + for (uint i = 0; i < fen.length(); i++) { std::printf("state: %d\n", state); std::printf("doing: %c\n", fen[i]); if (fen[i] == ' ') { diff --git a/src/main.cpp b/src/main.cpp index 7a6e7f4..261c19d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -127,7 +127,7 @@ int main(int argc, char **argv) { continue; } std::println(); - PlayMove(move, &b); + // PlayMove(move, &b); // todo implement b.MoveClock++; b.turn = !b.turn; printBoard(&b); diff --git a/src/moves.cpp b/src/moves.cpp index 2ff8ed6..f02dfbe 100644 --- a/src/moves.cpp +++ b/src/moves.cpp @@ -1,5 +1,6 @@ #include <array> #include <cstdint> +#include <sys/types.h> #include "board.hpp" #include "moves.hpp" @@ -11,7 +12,7 @@ std::vector<Move> GetLegalMoves(board *b) { constexpr std::array<int, 4> rook_Moves{-1, 1, 8, -8}; constexpr std::array<int, 4> bishop_Moves{-9, 9, -7, 7}; - for (int i = 0; i < sizeof(b->pieces) / sizeof(b->pieces[0]); i++) { + for (uint i = 0; i < sizeof(b->pieces) / sizeof(b->pieces[0]); i++) { Piece piece = b->pieces[i]; if (piece.type == NONE) { continue; @@ -42,7 +43,7 @@ Position IndexToPosition(int i) { void GenerateSlidingMoves(board *b, int from, const std::array<int, 4> &directions, std::vector<Move> &moves) { - for (int i = 0; i < directions.size(); i++) { + for (uint i = 0; i < directions.size(); i++) { int direction = directions[i]; int i2 = from; |
