From 59ecc0ee72a180692fcccab88db310d60021f2ab Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 13 Apr 2024 19:22:49 +0200 Subject: Fixed howto, added example --- README.md | 12 ++++++++++-- cube.o | Bin 22112 -> 23088 bytes example/a.out | Bin 0 -> 49752 bytes example/compile.sh | 1 + example/example.cpp | 34 ++++++++++++++++++++++++++++++++++ example/example.o | Bin 0 -> 33856 bytes 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100755 example/a.out create mode 100755 example/compile.sh create mode 100644 example/example.cpp create mode 100644 example/example.o diff --git a/README.md b/README.md index 131c7ed..a1b260a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A simple set of basic routines for working with a 3x3x3 Rubik's Cube. ## How to use CubeCore -(More details coming soon) +See the example in `example/` for details. 0. Requirements: a C99 compiler (e.g. GCC) @@ -15,12 +15,20 @@ $ make $ make test # optional ``` -2. Include in your C or C++ project +2. Include in your C project ``` #include "cube.h" ``` +or in your C++ project + +``` +extern "C" { +#include "cube.h" +} +``` + 3. Compile including the `cube.o` file ``` diff --git a/cube.o b/cube.o index 9f4fb3d..e61cb30 100644 Binary files a/cube.o and b/cube.o differ diff --git a/example/a.out b/example/a.out new file mode 100755 index 0000000..ef2babe Binary files /dev/null and b/example/a.out differ diff --git a/example/compile.sh b/example/compile.sh new file mode 100755 index 0000000..4ce3bd2 --- /dev/null +++ b/example/compile.sh @@ -0,0 +1 @@ +g++ example.cpp ../cube.o diff --git a/example/example.cpp b/example/example.cpp new file mode 100644 index 0000000..60c998f --- /dev/null +++ b/example/example.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +extern "C" { +#include "../cube.h" +} + +cube_t apply_alg(cube_t cube, std::vector *moves) { + auto ret = cube; + + for (auto m : *moves) + ret = cube_move(ret, m); + + return ret; +} + +int main() { + auto cube = cube_new(); + auto moves = new std::vector { R, U, R3, U3 }; + char cstr[500]; + + std::cout << "The solved cube looks like this in H48 notation:\n"; + cube_write((char *)"H48", cube, cstr); + std::string solvedstr(cstr); + std::cout << solvedstr << "\n"; + std::cout << "After a sexy move it looks like this:\n"; + cube = apply_alg(cube, moves); + cube_write((char *)"H48", cube, cstr); + std::string sexystr(cstr); + std::cout << sexystr << "\n"; + + return 0; +} diff --git a/example/example.o b/example/example.o new file mode 100644 index 0000000..af95a15 Binary files /dev/null and b/example/example.o differ -- cgit v1.3