Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MazeGenerator exercise and related tests #2355

Merged
merged 35 commits into from
Nov 1, 2023

Conversation

rabestro
Copy link
Member

Introduction

Meet Mickey and Minerva, two clever mice who love to navigate their way through a maze to find cheese. They enjoy a good challenge, but with only their tiny mouse brains, they prefer if there's only one correct path to the cheese.

Instructions

Your task is to generate the perfect mazes for Mickey and Minerva — those with only one solution and no isolated sections. Here's what you need to know:

  • The maze is rectangular, with the outer borders roughly forming a rectangle.
  • The maze has square cells and orthogonal passages intersecting at right angles.
  • The program should accept two parameters: rows and columns. The maze should be between 5 and 100 cells in size.
  • Consider the maze walls by using the formula 2x+1 for the actual width and height, where x is rows or columns.
  • If no seed is provided, generate a random maze. If a seed is provided, get the same labyrinth every time.
  • Use box-drawing characters to draw walls, and an arrow symbol (⇨) for the entrance on the left and exit on the right.

It's time to create some perfect mazes for these adventurous mice!

Examples

  1. The smallest square maze 5x5 cells (or 11x11 characters)
	┌───────┬─┐
	│       │ │
	│ ┌─┬── │ │
	│ │ │   │ ⇨
	│ │ │ ──┤ │
	⇨ │ │   │ │
	┌─┤ └── │ │
	│ │     │ │
	│ │ ────┘ │
	│         │
	└─────────┘
  1. The rectangular maze 6x18 cells
	┌───────────┬─────────┬───────────┬─┐
	│           │         │           │ │
	│ ┌───────┐ │ ┌─┐ ──┐ └───┐ ┌───┐ │ │
	│ │       │ │ │ │   │     │ │   │   ⇨
	│ └─┐ ┌─┐ │ │ │ ├── ├───┐ │ │ ──┼── │
	│   │ │ │   │   │   │   │ │ │   │   │
	└── │ │ ├───┴───┤ ┌─┘ ┌─┘ │ ├── │ ──┤
	⇨   │   │       │ │   │   │ │   │   │
	┌─┬─┴─┐ └─┐ ┌─┐ │ └─┐ │ ┌─┘ │ ──┴─┐ │
	│ │   │   │ │ │ │   │   │   │     │ │
	│ │ │ └── │ │ │ └── │ ──┘ ┌─┘ ──┐ │ │
	│   │       │       │     │     │   │
	└───┴───────┴───────┴─────┴─────┴───┘

Hints

General

Maze generation

You can use any algorithm to generate a perfect maze. The recursive backtracker is a good choice.

Box drawing characters

Character Name Unicode
box drawings light down and right U+250C
box drawings light horizontal U+2500
box drawings light down and horizontal U+252C
box drawings light down and left U+2510
box drawings light vertical U+2502
box drawings light up and right U+2514
box drawings light up and horizontal U+2534
box drawings light up and left U+2518
box drawings light vertical and right U+2520
rightwards white arrow U+21E8

This commit introduces a new MazeGenerator class along with related Units Tests. It also adds the `Dimensions` record to represent the size of the maze. Both MazeGenerator and Dimensions classes are incorporated into the build.gradle file. For testing purposes, MazeGeneratorTest along with its configuration file and a test reference were incorporated.

This change allows generating perfect mazes of a specified size with a single correct path, ideal for maze navigation tasks. Can produce random mazes or reproducible ones when provided with a seed. The mazes are represented using box-drawing characters and the entrances/exits are denoted by an arrow symbol(⇨).
@rabestro
Copy link
Member Author

I just realized that the latest pull request contains a new version of the JUnit library. Should I use JUnit 5 for the new exercise?

Copy link
Contributor

@sanderploegsma sanderploegsma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution! This sounds like a fun and challenging exercise.

I left some inline comments for you to look at. Apart from those, these points should be addressed before this can be merged:

exercises/practice/mazy-mice/src/main/java/Dimensions.java Outdated Show resolved Hide resolved
exercises/practice/mazy-mice/.docs/hints.md Outdated Show resolved Hide resolved
@sanderploegsma
Copy link
Contributor

I just realized that the latest pull request contains a new version of the JUnit library. Should I use JUnit 5 for the new exercise?

Support for JUnit 5 is being added in exercism/java-test-runner#61. It will support both JUnit 4 and 5 so for now I would suggest to keep using JUnit 4 like the other practice exercises.

Jegors Čemisovs added 8 commits September 19, 2023 11:02
The config.json file for the mazy-mice exercise has been improved to include the new 'invalidator' field. This field references the build.gradle file which is used for the construction and testing of the 'MazeGenerator' example. With this addition, users are now able to work with the MazeGenerator class and its related unit tests in their local environment with ease.
Minor grammatical correction has been made in the mazy-mice exercise documentation. Prior sentences were changed from "The small square maze" and "The rectangular maze" to "A small square maze" and "A rectangular maze" respectively, to improve sentence flow and clarity for users.
The placeholder comment in the 'hints.md' file for the mazy-mice exercise has been replaced with the 'Hints' header. This change is essential for creating a more meaningful start to the document and improving the clarity for users trying to understand maze generation.
The test method name 'the_dimensions_are_correct' in MazeGeneratorTest has been refactored to 'theDimensionsAreCorrect'. This is in line with Java's camelCase naming convention, improving readability and maintaining a consistent code style.
Updated the name of the test method in MazeGeneratorTest from 'twoMazesShouldNotBeEqual' to 'aMazeIsDifferentEachTimeItIsGenerated'. The new name better indicates the purpose of the test, which is to check that every maze generated is unique.
Included 'practice:mazy-mice' in the settings.gradle to extend the diversity of exercises. This step is necessary for building and running the 'mazy-mice' exercise.
@rabestro
Copy link
Member Author

* [X]  The exercise's Gradle project should be added to `exercises/settings.gradle`. This will include it in the CI build as well.

done

@rabestro rabestro changed the title Add MazeGenerator exercise and related tests [WIP] Add MazeGenerator exercise and related tests Oct 5, 2023
@sanderploegsma sanderploegsma marked this pull request as draft October 5, 2023 18:37
Jegors Čemisovs added 2 commits October 7, 2023 17:33
A new exercise named "mazy-mice" has been added to config.json. This exercise, which involves character arrays and string handling with for-loops, is intended to diversify the exercise list and give users more exercise choices. The difficulty of this exercise has been set to 8.
@rabestro
Copy link
Member Author

rabestro commented Oct 7, 2023

  • The exercise should be added to the config.json at the root of this repository. This is where the exercises are sourced from on exercism.org, so it won't be available to anyone unless it's in there.

done

@sanderploegsma
Copy link
Contributor

@rabestro are you still actively working on this?

@rabestro
Copy link
Member Author

@rabestro are you still actively working on this?

Yes. I'm on vocation now and I will continue in November.

Jegors Čemisovs added 3 commits October 28, 2023 12:18
The methods for maze generation have been refactored to directly accept individual parameters for 'rows' and 'columns' instead of a 'Dimensions' object. This change simplifies the method calls and enhances code readability. Also, updated the corresponding test cases to adhere to the new method signature. Additionally, added enumeration for directions at the end of the test class to improve code organization and readability.
An auto-generated 'tests.toml' file is introduced. The descriptions added provide information for each test key about the attributes and functionality that is being tested. These include correct dimensions, valid characters, proper locations of entrances and exits, and generation of mazes with or without a seed parameter. These descriptions help developers understand the purpose of the tests and correct functioning of the maze.

Also, change method names and orders to make the test easier to follow. This allows the clearer reading of the tests, thus increasing productivity. It helps maintainers to spot and understand the new changes faster and easier. Minor changes, such as capitalisation corrections, are also made for improved readability.
This commit changes the access modifier of all test methods in the `MazeGeneratorTest` class from default to public.

This necessary change, switching to public, allows JUnit to access the test methods. Previously, due to default access level it could cause issues with the test runner and result in no tests being executed. Access modifiers were also applied to the `setup` method to ensure it properly annotated before each test run. Making these methods public improves test functionality and ensures they are recognized as legitimate JUnit tests.
@rabestro rabestro changed the title [WIP] Add MazeGenerator exercise and related tests Add MazeGenerator exercise and related tests Oct 28, 2023
Jegors Čemisovs added 3 commits October 29, 2023 13:49
This commit adds important hints in the hints.md file for the 'mazy-mice' exercise. It introduces useful general information regarding the generation of random numbers in Java 17 including links to valuable resources. This could help participants to understand better how to deal with random numbers and thus can improve the exercise's learning objectives.
This commit added a new test case to the MazeGeneratorTest file. The added test, "theMazeIsPerfectWithSeed", simulates a perfect maze generation with a predefined seed. This test aims to help to ensure that the maze generator can correctly use seed to produce the expected unique maze structure. This also enhances the test coverage and further ensures the robustness of the maze generating code.
In this commit, 4 new tests have been added to the MazeGeneratorTest in order to check the validity of size parameters passed to the 'generatePerfectMaze' function. These tests ensure that both rows and columns parameters are within acceptable range (5-100) by throwing an IllegalArgumentException if they are not.
@rabestro rabestro marked this pull request as ready for review October 29, 2023 17:18
Dimension validation methods have been included in the maze generation methods of the MazeGenerator class. This is to ensure that the rows and columns of the maze are within an acceptable range (5-100). If these values fall out of the given range, an IllegalArgumentException is thrown. This was introduced to prevent the generation of mazes that would be too small or too big, which could lead to performance issues or unplayable mazes.
@sanderploegsma
Copy link
Contributor

Thanks for taking care of everything! I will need a moment to review it, I hope to get to it in the coming week. Just know that it’s on my to-do list! 🙂

Copy link
Contributor

@sanderploegsma sanderploegsma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for processing the comments! I have found some more things to address though, could you have a look at them?

config.json Outdated Show resolved Hide resolved
exercises/practice/mazy-mice/.docs/instructions.md Outdated Show resolved Hide resolved
exercises/practice/mazy-mice/.meta/tests.toml Outdated Show resolved Hide resolved
exercises/practice/mazy-mice/.meta/version Outdated Show resolved Hide resolved
exercises/practice/mazy-mice/src/main/java/Dimensions.java Outdated Show resolved Hide resolved
Jegors Čemisovs and others added 13 commits October 31, 2023 11:03
The heading formatting in the instructions.md document within the mazy-mice exercise directory has been revised. The markdown format was adjusted from using "##" to make it a sub-heading, to "#" to make it a top level heading. This change has been implemented for clarity and readability, making it easier for users to understand the structure of the document.
The file Dimensions.java was deleted because its purpose - to represent the dimensions of a maze - is already covered by another class in our program. Its functionality including width and height calculations, which were previously done in cells, are now handled elsewhere, making this file unnecessary.
Added "strings" and "for-loops" to the "practices" array in the config.json file. This change is necessary to ensure all necessary learning concepts are being covered within the curriculum.
# Conflicts:
#	config.json
The new game "Mazy Mice" with corresponding uuid, practices, prerequisites, and difficulty level was added to the config.json. This is essential for including a new game in the curriculum that emphasizes the application of "strings" and "for-loops" practices.
Included "Dimensions.java" in the example files array for the "Mazy Mice" problem in config.json, as it is needed for the correct generation of the maze. Not including this could lead to errors or incomplete solutions.
The mazeIsNotNull test in MazeGeneratorTest class was removed as it was deemed unnecessary and redundant. The null check is already implicitly covered in the subsequent dimensions and valid characters tests.
Moved `Direction` enum to the top of the MazeGeneratorTest class to improve code organization and readability. Adjusted dimensions test to use Arrays.stream for enhanced test flow and comprehension. Removed redundant mazeNotNull test.
Copy link
Contributor

@sanderploegsma sanderploegsma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! I think this would make a great addition to the Java track.

Can I ask you to add one more thing before we merge? Since this exercise is new on Exercism, I'd like to mark it as beta so that students on the website are asked to provide feedback on it. You can do this by adding the property "status": "beta" to the exercise object in the config.json at the root of this repo.

@rabestro
Copy link
Member Author

rabestro commented Nov 1, 2023

Since this exercise is new on Exercism, I'd like to mark it as beta so that students on the website are asked to provide feedback on it. You can do this by adding the property "status": "beta" to the exercise object in the config.json at the root of this repo.

done

@sanderploegsma sanderploegsma added the x:size/large Large amount of work label Nov 1, 2023
@sanderploegsma sanderploegsma merged commit c5660c7 into exercism:main Nov 1, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:size/large Large amount of work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants