commit 59ecc0ee72a180692fcccab88db310d60021f2ab
parent ec87f96ffec31c430b6058663ae831c1b3a29ff9
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Sat, 13 Apr 2024 19:22:49 +0200
Fixed howto, added example
Diffstat:
6 files changed, 45 insertions(+), 2 deletions(-)
diff --git 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
Binary files differ.
diff --git a/example/a.out b/example/a.out
Binary files differ.
diff --git a/example/compile.sh b/example/compile.sh
@@ -0,0 +1 @@
+g++ example.cpp ../cube.o
diff --git a/example/example.cpp b/example/example.cpp
@@ -0,0 +1,34 @@
+#include <cinttypes>
+#include <iostream>
+#include <vector>
+
+extern "C" {
+#include "../cube.h"
+}
+
+cube_t apply_alg(cube_t cube, std::vector<move_t> *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<move_t> { 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
Binary files differ.