From 81f06cb209d9d3f092e3ed0ef2e2dbc6b288f1de Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 19 Jan 2023 15:51:12 +0100 Subject: [PATCH] Integrate Chess Move Interface --- .gitlab-ci.yml | 2 +- .gitmodules | 3 +++ CMakeLists.txt | 13 ++++++++++--- libs/chess-move-interface | 1 + src/HalfMove.cpp | 16 ++++++++++++++++ src/HalfMove.hpp | 4 ++++ tests/CMakeLists.txt | 8 ++++---- 7 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 .gitmodules create mode 160000 libs/chess-move-interface diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 014eeb4..709f835 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,4 +3,4 @@ archlinux: before_script: - pacman -Sy cmake --noconfirm --needed script: - - mkdir build && cd build && cmake ../ && make && ctest + - mkdir build && cd build && cmake ../ -DCOMPILE_TESTS:BOOL:ON && make && ctest diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..704f939 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "libs/chess-move-interface"] + path = libs/chess-move-interface + url = git@gitlab.com:manzerbredes/chess-move-interface.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 64447e9..fd5cddf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,9 +12,16 @@ configure_file(src/PGN.hpp ${PGNP_INCLUDE_DIR}/pgnp.hpp COPYONLY) configure_file(src/HalfMove.hpp ${PGNP_INCLUDE_DIR} COPYONLY) configure_file(src/LargeFileStream.hpp ${PGNP_INCLUDE_DIR} COPYONLY) configure_file(src/Types.hpp ${PGNP_INCLUDE_DIR} COPYONLY) - include_directories(${PGNP_INCLUDE_DIR}) +# ChessMoveInterface +add_subdirectory(libs/chess-move-interface) +include_directories(${CMI_INCLUDE_DIR}) + # Unit tests -enable_testing() -add_subdirectory(./tests) +set(COMPILE_TESTS OFF CACHE BOOL "Should unit tests be compiled") +if(COMPILE_TESTS) + enable_testing() + add_subdirectory(./tests) +endif() + diff --git a/libs/chess-move-interface b/libs/chess-move-interface new file mode 160000 index 0000000..3a4af94 --- /dev/null +++ b/libs/chess-move-interface @@ -0,0 +1 @@ +Subproject commit 3a4af94254d21e51ae260ad71fcc605ebb7e734e diff --git a/src/HalfMove.cpp b/src/HalfMove.cpp index 81d9a67..c1e4667 100644 --- a/src/HalfMove.cpp +++ b/src/HalfMove.cpp @@ -78,4 +78,20 @@ HalfMove *HalfMove::GetHalfMoveAt(int distance) { return (tmp); } +CMI::HalfMove *HalfMove::GetAsCMI(){ + CMI::HalfMove *m=new CMI::HalfMove(); + m->SetSAN(move); + m->SetNumber(count); + m->SetIsBlack(isBlack); + m->SetComment(comment); + m->SetNAG(NAG); + if(MainLine!=NULL){ + m->SetMainline(MainLine->GetAsCMI()); + } + for (HalfMove *var : variations) { + m->AddVariation(var->GetAsCMI()); + } + return m; +} + } // namespace pgnp \ No newline at end of file diff --git a/src/HalfMove.hpp b/src/HalfMove.hpp index 45eb96c..c836a3e 100644 --- a/src/HalfMove.hpp +++ b/src/HalfMove.hpp @@ -5,6 +5,8 @@ #include #include +#include "CMI.hpp" + namespace pgnp { /** @@ -40,6 +42,8 @@ public: void Copy(HalfMove *copy); /// @brief Get HalfMove located x down the MainLine HalfMove *GetHalfMoveAt(int); + /// @brief Get CMI version of HalfMove + CMI::HalfMove *GetAsCMI(); }; struct HalfMoveOutOfRange : public std::exception { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4b0d167..c31bdf9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -8,17 +8,17 @@ add_library(pgnp_catch3 SHARED ./catch3/catch_amalgamated.cpp) # Add tests add_executable(pgnp_valid valid.cpp) -target_link_libraries(pgnp_valid pgnp pgnp_catch3) +target_link_libraries(pgnp_valid pgnp pgnp_catch3 ChessMoveInterface) add_test(PGNP_Valid_PGN_Set pgnp_valid) add_executable(pgnp_str str.cpp) -target_link_libraries(pgnp_str pgnp pgnp_catch3) +target_link_libraries(pgnp_str pgnp pgnp_catch3 ChessMoveInterface) add_test(PGNP_STR_Compliant_Set pgnp_str) add_executable(pgnp_combined combined.cpp) -target_link_libraries(pgnp_combined pgnp pgnp_catch3) +target_link_libraries(pgnp_combined pgnp pgnp_catch3 ChessMoveInterface) add_test(PGNP_Combined_Set pgnp_combined) add_executable(from_string from_string.cpp) -target_link_libraries(from_string pgnp pgnp_catch3) +target_link_libraries(from_string pgnp pgnp_catch3 ChessMoveInterface) add_test(PGNP_FromString_Set from_string)