From 19adee5552657cb8f5fe94e95e8042366e003990 Mon Sep 17 00:00:00 2001 From: xwashere Date: Wed, 3 May 2023 15:26:40 -0400 Subject: [PATCH] first thingy nya --- .gitattributes | 19 +++++++++++++++ .gitignore | 30 ++++++++++++++++++++++++ build/.gitignore | 4 ++++ build/bootstrap.build | 7 ++++++ build/root.build | 22 ++++++++++++++++++ buildfile | 1 + knights-tour/.gitignore | 5 ++++ knights-tour/board.cxx | 49 +++++++++++++++++++++++++++++++++++++++ knights-tour/board.mxx | 20 ++++++++++++++++ knights-tour/buildfile | 6 +++++ knights-tour/main.cxx | 51 +++++++++++++++++++++++++++++++++++++++++ knights-tour/out.svg | 11 +++++++++ knights-tour/testscript | 9 ++++++++ manifest | 5 ++++ repositories.manifest | 11 +++++++++ 15 files changed, 250 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 build/.gitignore create mode 100644 build/bootstrap.build create mode 100644 build/root.build create mode 100644 buildfile create mode 100644 knights-tour/.gitignore create mode 100644 knights-tour/board.cxx create mode 100644 knights-tour/board.mxx create mode 100644 knights-tour/buildfile create mode 100644 knights-tour/main.cxx create mode 100644 knights-tour/out.svg create mode 100644 knights-tour/testscript create mode 100644 manifest create mode 100644 repositories.manifest diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1631641 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,19 @@ +# This is a good default: files that are auto-detected by git to be text are +# converted to the platform-native line ending (LF on Unix, CRLF on Windows) +# in the working tree and to LF in the repository. +# +* text=auto + +# Use `eol=crlf` for files that should have the CRLF line ending both in the +# working tree (even on Unix) and in the repository. +# +#*.bat text eol=crlf + +# Use `eol=lf` for files that should have the LF line ending both in the +# working tree (even on Windows) and in the repository. +# +#*.sh text eol=lf + +# Use `binary` to make sure certain files are never auto-detected as text. +# +#*.png binary diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d01c0f1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +.bdep/ + +# Local default options files. +# +.build2/local/ + +# Compiler/linker output. +# +*.d +*.t +*.i +*.i.* +*.ii +*.ii.* +*.o +*.obj +*.gcm +*.pcm +*.ifc +*.so +*.dll +*.a +*.lib +*.exp +*.pdb +*.ilk +*.exe +*.exe.dlls/ +*.exe.manifest +*.pc diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..974e01d --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,4 @@ +/config.build +/root/ +/bootstrap/ +build/ diff --git a/build/bootstrap.build b/build/bootstrap.build new file mode 100644 index 0000000..333b97a --- /dev/null +++ b/build/bootstrap.build @@ -0,0 +1,7 @@ +project = knights-tour + +using version +using config +using test +using install +using dist diff --git a/build/root.build b/build/root.build new file mode 100644 index 0000000..c1d79d2 --- /dev/null +++ b/build/root.build @@ -0,0 +1,22 @@ +# Uncomment to suppress warnings coming from external libraries. +# +#cxx.internal.scope = current + +cxx.std = experimental +cxx.features.modules = true + +using cxx + +hxx{*}: extension = hxx +ixx{*}: extension = ixx +txx{*}: extension = txx +cxx{*}: extension = cxx +mxx{*}: extension = mxx + +# Assume headers are importable unless stated otherwise. +# +hxx{*}: cxx.importable = true + +# The test target for cross-testing (running tests under Wine, etc). +# +test.target = $cxx.target diff --git a/buildfile b/buildfile new file mode 100644 index 0000000..4bec3bc --- /dev/null +++ b/buildfile @@ -0,0 +1 @@ +./: {*/ -build/} doc{README.md} manifest diff --git a/knights-tour/.gitignore b/knights-tour/.gitignore new file mode 100644 index 0000000..a8367d6 --- /dev/null +++ b/knights-tour/.gitignore @@ -0,0 +1,5 @@ +knights-tour + +# Testscript output directory (can be symlink). +# +test-knights-tour diff --git a/knights-tour/board.cxx b/knights-tour/board.cxx new file mode 100644 index 0000000..0b08e66 --- /dev/null +++ b/knights-tour/board.cxx @@ -0,0 +1,49 @@ +module board; + +import ; +import ; +import ; +import ; + +board::board() { + this->cells[0][0] = 1; + this->x = 0; + this->y = 0; +} + +void board::move(uint8_t x, uint8_t y) { + this->x = x; + this->y = y; + this->cells[x][y] = 1; +} + +std::vector> board::cell_moves(uint8_t x, uint8_t y) { + std::vector> moves = {}; + + if (x >= 1 && y >= 2 && !this->cells[x-1][y-2]) moves.push_back({ x - 1, y - 2 }); + if (x >= 1 && y <= 5 && !this->cells[x-1][y+2]) moves.push_back({ x - 1, y + 2 }); + if (x >= 2 && y >= 1 && !this->cells[x-2][y-1]) moves.push_back({ x - 2, y - 1 }); + if (x >= 2 && y <= 6 && !this->cells[x-2][y+1]) moves.push_back({ x - 2, y + 1 }); + if (x <= 5 && y >= 1 && !this->cells[x+2][y-1]) moves.push_back({ x + 2, y - 1 }); + if (x <= 5 && y <= 6 && !this->cells[x+2][y+1]) moves.push_back({ x + 2, y + 1 }); + if (x <= 6 && y >= 2 && !this->cells[x+1][y-2]) moves.push_back({ x + 1, y - 2 }); + if (x <= 6 && y <= 5 && !this->cells[x+1][y+2]) moves.push_back({ x + 1, y + 2 }); + + return moves; +} + +void board::print_board() { + for (uint8_t i = 0; i < 8; i++) { + for (uint8_t j = 0; j < 8; j++) { + if (this->x == i && this->y == j) { + std::cout << 'o'; + } else if (this->cells[i][j]) { + std::cout << 'x'; + } else { + std::cout << ' '; + } + } + + std::cout << '\n'; + } +} diff --git a/knights-tour/board.mxx b/knights-tour/board.mxx new file mode 100644 index 0000000..99bf90d --- /dev/null +++ b/knights-tour/board.mxx @@ -0,0 +1,20 @@ +export module board; + +import ; +export import ; +export import ; + +export struct board { + bool cells[8][8] = {}; + + uint8_t x; + uint8_t y; + + board(); + + void move(uint8_t x, uint8_t y); + + std::vector> cell_moves(uint8_t x, uint8_t y); + + void print_board(); +}; diff --git a/knights-tour/buildfile b/knights-tour/buildfile new file mode 100644 index 0000000..e03f505 --- /dev/null +++ b/knights-tour/buildfile @@ -0,0 +1,6 @@ +libs = +#import libs += libhello%lib{hello} + +exe{knights-tour}: {mxx hxx ixx txx cxx}{**} $libs testscript + +cxx.poptions =+ "-I$out_root" "-I$src_root" diff --git a/knights-tour/main.cxx b/knights-tour/main.cxx new file mode 100644 index 0000000..a1fafd7 --- /dev/null +++ b/knights-tour/main.cxx @@ -0,0 +1,51 @@ +import ; +import ; +import ; + +import board; + +int main (int argc, char* argv[]) { + std::vector> history = {{ 0, 0 }}; + + board b; + + while (1) { + auto moves = b.cell_moves(b.x, b.y); + + if (moves.size() == 0) break; + + uint8_t tm = 255; + uint8_t tx = 0; + uint8_t ty = 0; + + for (auto [nx, ny] : moves) { + uint8_t nm = b.cell_moves(nx, ny).size(); + if (nm > tm) continue; + tm = nm; tx = nx; ty = ny; + } + + b.move(tx, ty); + history.push_back({ tx, ty }); + } + + std::cout << "\n"; + + std::cout << ""; + for (uint8_t i = 0; i < 8; i++) { + for (uint8_t j = 0; j < 8; j++) { + std::cout << ""; + } + } + uint8_t px = 0; + uint8_t py = 0; + for (auto [x, y] : history) { + std::cout << ""; + px = x; py = y; + } + + std::cout << ""; +} diff --git a/knights-tour/out.svg b/knights-tour/out.svg new file mode 100644 index 0000000..37150cc --- /dev/null +++ b/knights-tour/out.svg @@ -0,0 +1,11 @@ + + \ No newline at end of file diff --git a/knights-tour/testscript b/knights-tour/testscript new file mode 100644 index 0000000..cefda39 --- /dev/null +++ b/knights-tour/testscript @@ -0,0 +1,9 @@ +: basics +: +$* 'World' >'Hello, World!' + +: missing-name +: +$* 2>>EOE != 0 +error: missing name +EOE diff --git a/manifest b/manifest new file mode 100644 index 0000000..915c955 --- /dev/null +++ b/manifest @@ -0,0 +1,5 @@ +: 1 +name: knights-tour +version: 0.1.0 +depends: * build2 >= 0.15.0 +depends: * bpkg >= 0.15.0 diff --git a/repositories.manifest b/repositories.manifest new file mode 100644 index 0000000..f422ec7 --- /dev/null +++ b/repositories.manifest @@ -0,0 +1,11 @@ +: 1 +summary: knights-tour project repository + +#: +#role: prerequisite +#location: https://pkg.cppget.org/1/stable +#trust: ... + +#: +#role: prerequisite +#location: https://git.build2.org/hello/libhello.git