Skip to content

Commit beef674

Browse files
authored
Add flower-field, deprecating minesweeper (#2711)
1 parent 246e2fb commit beef674

File tree

15 files changed

+400
-0
lines changed

15 files changed

+400
-0
lines changed

config.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,13 +2382,27 @@
23822382
"parsing"
23832383
]
23842384
},
2385+
{
2386+
"slug": "flower-field",
2387+
"name": "Flower Field",
2388+
"uuid": "cb4da136-db03-44fa-a5c8-5235f273320c",
2389+
"practices": [],
2390+
"prerequisites": [],
2391+
"difficulty": 7,
2392+
"topics": [
2393+
"algorithms",
2394+
"arrays",
2395+
"games"
2396+
]
2397+
},
23852398
{
23862399
"slug": "minesweeper",
23872400
"name": "Minesweeper",
23882401
"uuid": "8bafe6c4-9154-4037-9070-7f57f91d495a",
23892402
"practices": [],
23902403
"prerequisites": [],
23912404
"difficulty": 7,
2405+
"status": "deprecated",
23922406
"topics": [
23932407
"algorithms",
23942408
"arrays",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Instructions
2+
3+
Your task is to add flower counts to empty squares in a completed Flower Field garden.
4+
The garden itself is a rectangle board composed of squares that are either empty (`' '`) or a flower (`'*'`).
5+
6+
For each empty square, count the number of flowers adjacent to it (horizontally, vertically, diagonally).
7+
If the empty square has no adjacent flowers, leave it empty.
8+
Otherwise replace it with the count of adjacent flowers.
9+
10+
For example, you may receive a 5 x 4 board like this (empty spaces are represented here with the '·' character for display on screen):
11+
12+
```text
13+
·*·*·
14+
··*··
15+
··*··
16+
·····
17+
```
18+
19+
Which your code should transform into this:
20+
21+
```text
22+
1*3*1
23+
13*31
24+
·2*2·
25+
·111·
26+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Introduction
2+
3+
[Flower Field][history] is a compassionate reimagining of the popular game Minesweeper.
4+
The object of the game is to find all the flowers in the garden using numeric hints that indicate how many flowers are directly adjacent (horizontally, vertically, diagonally) to a square.
5+
"Flower Field" shipped in regional versions of Microsoft Windows in Italy, Germany, South Korea, Japan and Taiwan.
6+
7+
[history]: https://web.archive.org/web/20020409051321fw_/http://rcm.usr.dsi.unimi.it/rcmweb/fnm/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/node_modules
2+
/bin/configlet
3+
/bin/configlet.exe
4+
/package-lock.json
5+
/yarn.lock
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"authors": [
3+
"matthewmorgan"
4+
],
5+
"contributors": [
6+
"BNAndras",
7+
"brendanmckeown",
8+
"cr0t",
9+
"rchavarria",
10+
"serixscorpio",
11+
"SleeplessByte",
12+
"xarxziux"
13+
],
14+
"files": {
15+
"solution": [
16+
"flower-field.js"
17+
],
18+
"test": [
19+
"flower-field.spec.js"
20+
],
21+
"example": [
22+
".meta/proof.ci.js"
23+
]
24+
},
25+
"blurb": "Mark all the flowers in a garden.",
26+
"custom": {
27+
"version.tests.compatibility": "jest-27",
28+
"flag.tests.task-per-describe": false,
29+
"flag.tests.may-run-long": false,
30+
"flag.tests.includes-optional": false
31+
}
32+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const FLOWER = '*';
2+
3+
const DELTAS = [
4+
[-1, -1],
5+
[-1, 0],
6+
[-1, 1],
7+
[1, 1],
8+
[1, 0],
9+
[1, -1],
10+
[0, 1],
11+
[0, -1],
12+
];
13+
14+
function adjacentSquareIsOnBoard(board, x, d) {
15+
return board[x + d[0]];
16+
}
17+
18+
function adjacentSquareHasFlower(board, x, y, d) {
19+
return board[x + d[0]][y + d[1]] === FLOWER;
20+
}
21+
22+
function countAdjacentFlowers(board, x, y) {
23+
return DELTAS.filter((d) => adjacentSquareIsOnBoard(board, x, d)).filter(
24+
(d) => adjacentSquareHasFlower(board, x, y, d),
25+
).length;
26+
}
27+
28+
function cellToFlowerOrCount(cell, inputBoard, x, y) {
29+
if (cell === FLOWER) {
30+
return FLOWER;
31+
}
32+
33+
return countAdjacentFlowers(inputBoard, x, y) || ' ';
34+
}
35+
36+
function stringify(board) {
37+
return board.map((row) => row.join(''));
38+
}
39+
40+
function noDataPresent(rows) {
41+
return rows.length === 0 || rows[0].length === 0;
42+
}
43+
44+
export function annotate(rows) {
45+
if (noDataPresent(rows)) {
46+
return rows;
47+
}
48+
49+
const inputBoard = rows.map((row) => [...row]);
50+
51+
return stringify(
52+
inputBoard.map((row, x) =>
53+
[...row].map((cell, y) => cellToFlowerOrCount(cell, inputBoard, x, y)),
54+
),
55+
);
56+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[237ff487-467a-47e1-9b01-8a891844f86c]
13+
description = "no rows"
14+
15+
[4b4134ec-e20f-439c-a295-664c38950ba1]
16+
description = "no columns"
17+
18+
[d774d054-bbad-4867-88ae-069cbd1c4f92]
19+
description = "no flowers"
20+
21+
[225176a0-725e-43cd-aa13-9dced501f16e]
22+
description = "garden full of flowers"
23+
24+
[3f345495-f1a5-4132-8411-74bd7ca08c49]
25+
description = "flower surrounded by spaces"
26+
27+
[6cb04070-4199-4ef7-a6fa-92f68c660fca]
28+
description = "space surrounded by flowers"
29+
30+
[272d2306-9f62-44fe-8ab5-6b0f43a26338]
31+
description = "horizontal line"
32+
33+
[c6f0a4b2-58d0-4bf6-ad8d-ccf4144f1f8e]
34+
description = "horizontal line, flowers at edges"
35+
36+
[a54e84b7-3b25-44a8-b8cf-1753c8bb4cf5]
37+
description = "vertical line"
38+
39+
[b40f42f5-dec5-4abc-b167-3f08195189c1]
40+
description = "vertical line, flowers at edges"
41+
42+
[58674965-7b42-4818-b930-0215062d543c]
43+
description = "cross"
44+
45+
[dd9d4ca8-9e68-4f78-a677-a2a70fd7a7b8]
46+
description = "large garden"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
audit=false
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Exercism
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
presets: [['@exercism/babel-preset-javascript', { corejs: '3.40' }]],
3+
plugins: [],
4+
};

0 commit comments

Comments
 (0)