unrenamed / knossos

A Rust library and CLI for generating mazes with some basic routines for rendering and saving mazes to files
https://crates.io/crates/knossos
Apache License 2.0
6 stars 1 forks source link

Define Start-Goal Points #2

Closed SSebigo closed 1 year ago

SSebigo commented 1 year ago

Is there a way to automatically or manually define start-goal points, where for example the start point would be represented by a "S" and the goal by a "G" on the ASCII map?

unrenamed commented 1 year ago

Hi @SSebigo. Thanks for your question.

So, the idea of yours is to randomly or manually set the coordinates of the entry and exit doors in the maze. The way I see it, this can be done by carving two walls on different sides of the maze field:

#########
..#...#.#
#.#.#.#.#
#.#.#...#
#.#.###.#
#...#...#
#####.###
#.......#
#######.#

What you're suggesting looks to me like this:

#########
S.#...#.#
#.#.#.#.#
#.#.#...#
#.#.###.#
#...#...#
#####.###
#.......#
#######G#

Is this what you're looking for? What do you think about the first approach?

I'm also curious what do you like to build such a map for if I may ask?

SSebigo commented 1 year ago

That's exactly what I'm suggesting, in my use case I need to parse a file (for a game), if the start-goal are just dots in walls it's requires a bit of work on my end to find them but if they're S-G, then I can just search for these letters.

So far, I've been generating mazes and placing the letters manually, it would be better if it could be generated directly with the maze, so the pipeline would be fully automated (generate -> solve -> test with bot).

unrenamed commented 1 year ago

@SSebigo I see. This sounds interesting 👍

I think I can get it done. Perhaps, it can be a part of the public API of the GameMap struct. Thus both the lib and CLI can provide the feature to generate the start-goal positions. By the way, from what you said I'd hazard a guess you're using the CLI for generating mazes, aren't you?

SSebigo commented 1 year ago

Yeah, I generate the maze into a file, then read the file inside Godot. But I was considering using Godot Rust plugin to use knossos directly into the engine.

unrenamed commented 1 year ago

@SSebigo That's great. I'll look into it this week

unrenamed commented 1 year ago

@SSebigo Hi. I've managed to implement an MVP version of the feature you requested. Before I move further to covering new logic with unit tests and documenting the API changes, I'd be happy if you take a look at the changes I've made so far. It'd make a lot of sense if you actually integrate the new feature of knossos with your game and test them together so that you can suggest any improvements or changes you need.

How to test? You have two options here: either using the CLI or the lib API as a plugin you mentioned.

CLI:

  1. Clone the new branch
  2. Build the binary via cargo build --release
  3. .target/release/knossos generate -W 4 -H 4 game-map --with-start-goal --output-path=maze.txt to run the CLI in your terminal

Lib:

  1. Add the following to your Cargo.toml
    [dependencies]
    knossos = { git = "https://github.com/unrenamed/knossos.git", branch = "2-define-start-goal-points" }
  2. Use GameMap::new().with_start_goal() to format a maze into a map with "S" and "G" points

If you encounter any issues or bugs, please let me know. If you've decided to use another repository or library for generating mazes, I'd be happy to know too.

SSebigo commented 1 year ago

I've tested the CLI and that's exactly what I had in mind. Haven't tested the lib yet, but if it used the same code as the CLI it should be good to go.

unrenamed commented 1 year ago

@SSebigo Hi, this is great that you were able to test it and verified the results. The CLI uses the library public API, hence you can try using it for your plugin as well.

I can see you've closed the issue, though the PR isn't merged yet and the new feature isn't covered with unit tests. I feel OK with finishing this feature and release a new minor version. I just need some time to do that. Simply put, we can reopen this and close once the PR is merged. WDYT?

SSebigo commented 1 year ago

@unrenamed my bad, I forgot this feature was not on the main branch. Take your time, I'll work with the feature branch for now np.

unrenamed commented 1 year ago

@SSebigo Great! I'll let you know when it's ready.

By the way, how's the progress with your game? Have you already tried using the Godot Rust plugin to make knossos generate mazes directly in the game engine?