Skip to content

Mazy Mice #2312

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions exercises/mazy-mice/canonican-data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
{
"exercise": "mazy-mice",
"comments": [
"The following checks should be considered: ",
" ",
"The dimensions of the maze are correct: ",
" - the number of lines is equal to rows * 2 + 1 ",
" - the width of each line in characters is equal to columns * 2 + 1",
"The maze contains only valid characters. ",
"The maze has a single entrance on the left side. ",
"The maze has a single exit on the right side. ",
"The maze is perfect: ",
" - there is a single path from the entrance to the exit ",
" - there are no loops in the maze ",
" - there are no inaccessible sections in the maze ",
"The maze is random: ",
" - the maze is different each time it is generated ",
" - the maze is the same if the same seed is used ",
" - two mazes with different seeds should not be equal ",
"The rows and cols must be between 5 and 100 "
],
"cases": [
{
"uuid": "e01f6db6-613c-4b55-9c09-e87edc0b04dd",
"description": "The dimensions of the maze are correct",
"property": "generateMaze",
"input": {
"rows": 6,
"cols": 18
},
"expected": {
"width": 37,
"height": 13
}
},
{
"uuid": "4782cea6-a1e3-48b2-b825-a805890b5118",
"description": "The maze contains only valid characters",
"property": "generateMaze",
"input": {
"rows": 6,
"cols": 18
},
"expected": true
},
{
"uuid": "1433a6ff-d18e-4ade-b37c-40b286218f07",
"description": "The maze has a single entrance on the left side",
"property": "generateMaze",
"input": {
"rows": 6,
"cols": 18
},
"expected": true
},
{
"uuid": "a0be2a1c-4ec1-412a-8a30-36d6b1d96df2",
"description": "The maze has a single exit on the right side",
"property": "generateMaze",
"input": {
"rows": 6,
"cols": 18
},
"expected": true
},
{
"uuid": "1f7f50f5-4a3a-4e96-8c5e-92b284fd8b3b",
"description": "the smallest square maze is perfect",
"property": "generateMaze",
"input": {
"rows": 5,
"cols": 5
},
"expected": true
},
{
"uuid": "2a8e8f63-7e89-4c9a-8d1f-1439a7d9a3e9",
"description": "the small rectangular maze is perfect",
"property": "generateMaze",
"input": {
"rows": 5,
"cols": 10
},
"expected": true
},
{
"uuid": "3b6e8d5c-2a8d-4f03-9e7a-6c8f2a4e4f88",
"description": "the square maze is perfect",
"property": "generateMaze",
"input": {
"rows": 10,
"cols": 10
},
"expected": true
},
{
"uuid": "4c7f6e5b-5e45-4a8d-8e8a-7f3e3e4e5f99",
"description": "the large rectangular maze is perfect",
"property": "generateMaze",
"input": {
"rows": 10,
"cols": 20
},
"expected": true
},
{
"uuid": "5d8f7f6c-6e46-4a9d-8e8b-8f3f3f4e6f00",
"description": "the rectangular maze with aspect 2:1 is perfect",
"property": "generateMaze",
"input": {
"rows": 20,
"cols": 10
},
"expected": true
},
{
"uuid": "6e9f8f7d-7e47-4a9e-8e8c-9f3f3f4e7f01",
"description": "the huge rectangular maze is perfect",
"property": "generateMaze",
"input": {
"rows": 20,
"cols": 100
},
"expected": true
},
{
"uuid": "7fa0a0b1-8e48-4a9f-8e8d-af4f4f5e8f02",
"description": "the huge square maze is perfect",
"property": "generateMaze",
"input": {
"rows": 100,
"cols": 100
},
"expected": true
},
{
"uuid": "8fb1c1d2-9e49-4aa0-8e8e-bf5f5f6e9f03",
"description": "if the seed parameter is specified, the perfect maze generated",
"property": "generateMaze",
"input": {
"rows": 50,
"cols": 50,
"seed": 2342342
},
"expected": true
},
{
"uuid": "9fc2d2e3-af4a-4ab1-8e8f-cf6f6f7eaf04",
"description": "if the seed parameter is omitted, random mazes should be generated",
"property": "generateMaze",
"input": {
"rows": 8,
"cols": 16
},
"expected": true
},
{
"uuid": "a0d3e4f4-b05b-4ac2-8e8a-df7f7f8eaf05",
"description": "if the seed parameter is specified, the same maze should be generated",
"property": "generateMaze",
"input": {
"rows": 8,
"cols": 16,
"seed": 123
},
"expected": true
},
{
"uuid": "b2f1a0e5-1c3a-4d5e-9f2b-8a7b6c5d4e3f",
"description": "Error: rows less than 5",
"property": "generateMaze",
"input": {
"rows": 4,
"cols": 10
},
"expected": {
"error": "rows must be between 5 and 100"
}
}
]
}
56 changes: 56 additions & 0 deletions exercises/mazy-mice/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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 has a rectangular shape with an opening at the start and end.
- The maze has rooms and passages, which intersect at right angles.
- The program should accept two parameters: rows and columns. The maze should be between 5 and 100 cells in size.
- A maze which is `x` columns wide and `y` rows high should be `2x + 1` characters wide and `2y + 1` characters high.
- If no seed is provided, generate a random maze. If the same seed is provided multiple times, the resulting maze should be the same each time.

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

## Examples

The small square maze 5x5 cells (or 11x11 characters)

```text
┌───────┬─┐
│ │ │
│ ┌─┬── │ │
│ │ │ │ ⇨
│ │ │ ──┤ │
⇨ │ │ │ │
┌─┤ └── │ │
│ │ │ │
│ │ ────┘ │
│ │
└─────────┘
```

The rectangular maze 6x18 cells

```text
┌───────────┬─────────┬───────────┬─┐
│ │ │ │ │
│ ┌───────┐ │ ┌─┐ ──┐ └───┐ ┌───┐ │ │
│ │ │ │ │ │ │ │ │ │ ⇨
│ └─┐ ┌─┐ │ │ │ ├── ├───┐ │ │ ──┼── │
│ │ │ │ │ │ │ │ │ │ │ │
└── │ │ ├───┴───┤ ┌─┘ ┌─┘ │ ├── │ ──┤
⇨ │ │ │ │ │ │ │ │ │
Copy link
Contributor

Choose a reason for hiding this comment

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

There are still some wide arrows in the documentation.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are still some wide arrows in the documentation.

Yes, if I understood correctly we can keep UTF-8 symbols in description for information (illustration) purposes. The illustration rendered correctly for this exercise (AWK and Java tracks). I've deleted the table with symbols as mentioned by @ErikSchierboom

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you mean it's rendered correctly on the website? That's not the only place where people will see it. It's rendered badly here on GitHub and it will be rendered badly in all the various editors people use locally. It's kind of a minor thing but I don't see the benefit of using a fancy arrow symbol in ascii art instead of just >, -> or =>.

Copy link
Member

Choose a reason for hiding this comment

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

in the past i've used this one in some of my PRs and it seems to be rendered fine in editors and the website.

┌─┬─┴─┐ └─┐ ┌─┐ │ └─┐ │ ┌─┘ │ ──┴─┐ │
│ │ │ │ │ │ │ │ │ │ │ │
│ │ │ └── │ │ │ └── │ ──┘ ┌─┘ ──┐ │ │
│ │ │ │ │ │ │
└───┴───────┴───────┴─────┴─────┴───┘
```

## Hints

### Maze generation

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

[recursive-backtracker]: https://en.wikipedia.org/wiki/Maze_generation_algorithm
3 changes: 3 additions & 0 deletions exercises/mazy-mice/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 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 is only one correct path to the cheese.
4 changes: 4 additions & 0 deletions exercises/mazy-mice/metadata.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
title = "Mazy Mice"
blurb = "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 is only one correct path to the cheese."
source = "Inspired by the 'Maze Generator' created by Jan Boström at Alance AB."
source_url = "https://mazegenerator.net/"
Loading