Skip to content

Commit 361d583

Browse files
BNAndrasahans
andauthored
chore: add flower-field, deprecate minesweeper
* Add `flower-field` * Deprecate `minesweeper` * add minor improvements --------- Co-authored-by: Alexander Hans <ahans@users.noreply.github.com>
1 parent a61daf8 commit 361d583

File tree

13 files changed

+18278
-1
lines changed

13 files changed

+18278
-1
lines changed

config.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,13 +1131,22 @@
11311131
"prerequisites": [],
11321132
"difficulty": 3
11331133
},
1134+
{
1135+
"slug": "flower-field",
1136+
"name": "Flower Field",
1137+
"uuid": "d17d040b-b214-4079-ad3e-b518f776aeeb",
1138+
"practices": [],
1139+
"prerequisites": [],
1140+
"difficulty": 5
1141+
},
11341142
{
11351143
"slug": "minesweeper",
11361144
"name": "Minesweeper",
11371145
"uuid": "3753a72a-78b7-429f-b79a-f68d55a00387",
11381146
"practices": [],
11391147
"prerequisites": [],
1140-
"difficulty": 5
1148+
"difficulty": 5,
1149+
"status": "deprecated"
11411150
},
11421151
{
11431152
"slug": "sublist",
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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"authors": [
3+
"vaeng"
4+
],
5+
"contributors": [
6+
"BNAndras"
7+
],
8+
"files": {
9+
"solution": [
10+
"flower_field.cpp",
11+
"flower_field.h"
12+
],
13+
"test": [
14+
"flower_field_test.cpp"
15+
],
16+
"example": [
17+
".meta/example.cpp",
18+
".meta/example.h"
19+
]
20+
},
21+
"blurb": "Mark all the flowers in a garden."
22+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "flower_field.h"
2+
3+
namespace flower_field {
4+
int score(const std::vector<std::string>& garden, size_t row, size_t column) {
5+
int flowers{};
6+
// north
7+
if (row > 0 && garden.at(row - 1).at(column) == '*') ++flowers;
8+
// north-east
9+
if (row > 0 && column < garden.at(0).size() - 1 &&
10+
garden.at(row - 1).at(column + 1) == '*')
11+
++flowers;
12+
// north-west
13+
if (row > 0 && column > 0 && garden.at(row - 1).at(column - 1) == '*')
14+
++flowers;
15+
// east
16+
if (column < garden.at(0).size() - 1 &&
17+
garden.at(row).at(column + 1) == '*')
18+
++flowers;
19+
// west
20+
if (column > 0 && garden.at(row).at(column - 1) == '*') ++flowers;
21+
// south
22+
if (row < garden.size() - 1 && garden.at(row + 1).at(column) == '*')
23+
++flowers;
24+
// south-east
25+
if (row < garden.size() - 1 && column < garden.at(0).size() - 1 &&
26+
garden.at(row + 1).at(column + 1) == '*')
27+
++flowers;
28+
// south-west
29+
if (row < garden.size() - 1 && column > 0 &&
30+
garden.at(row + 1).at(column - 1) == '*')
31+
++flowers;
32+
return flowers;
33+
}
34+
35+
std::vector<std::string> annotate(const std::vector<std::string>& garden) {
36+
std::vector<std::string> annotation{};
37+
for (size_t row{}; row < garden.size(); ++row) {
38+
std::string annotated{};
39+
for (size_t column{}; column < garden.at(0).size(); ++column) {
40+
if (garden.at(row).at(column) == '*') {
41+
annotated += '*';
42+
} else {
43+
int score_number = score(garden, row, column);
44+
char score_char = (score_number == 0)
45+
? ' '
46+
: static_cast<char>(score_number) + '0';
47+
annotated += score_char;
48+
}
49+
}
50+
annotation.push_back(std::move(annotated));
51+
}
52+
return annotation;
53+
}
54+
} // namespace flower_field
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#include <string>
4+
#include <vector>
5+
6+
namespace flower_field {
7+
std::vector<std::string> annotate(const std::vector<std::string>& garden);
8+
} // namespace flower_field
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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Get the exercise name from the current directory
2+
get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME)
3+
4+
# Basic CMake project
5+
cmake_minimum_required(VERSION 3.5.1)
6+
7+
# Name the project after the exercise
8+
project(${exercise} CXX)
9+
10+
# Get a source filename from the exercise name by replacing -'s with _'s
11+
string(REPLACE "-" "_" file ${exercise})
12+
13+
# Implementation could be only a header
14+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cpp)
15+
set(exercise_cpp ${file}.cpp)
16+
else()
17+
set(exercise_cpp "")
18+
endif()
19+
20+
# Use the common Catch library?
21+
if(EXERCISM_COMMON_CATCH)
22+
# For Exercism track development only
23+
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h $<TARGET_OBJECTS:catchlib>)
24+
elseif(EXERCISM_TEST_SUITE)
25+
# The Exercism test suite is being run, the Docker image already
26+
# includes a pre-built version of Catch.
27+
find_package(Catch2 REQUIRED)
28+
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
29+
target_link_libraries(${exercise} PRIVATE Catch2::Catch2WithMain)
30+
# When Catch is installed system wide we need to include a different
31+
# header, we need this define to use the correct one.
32+
target_compile_definitions(${exercise} PRIVATE EXERCISM_TEST_SUITE)
33+
else()
34+
# Build executable from sources and headers
35+
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h test/tests-main.cpp)
36+
endif()
37+
38+
set_target_properties(${exercise} PROPERTIES
39+
CXX_STANDARD 17
40+
CXX_STANDARD_REQUIRED OFF
41+
CXX_EXTENSIONS OFF
42+
)
43+
44+
set(CMAKE_BUILD_TYPE Debug)
45+
46+
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
47+
set_target_properties(${exercise} PROPERTIES
48+
COMPILE_FLAGS "-Wall -Wextra -Wpedantic -Werror"
49+
)
50+
endif()
51+
52+
# Configure to run all the tests?
53+
if(${EXERCISM_RUN_ALL_TESTS})
54+
target_compile_definitions(${exercise} PRIVATE EXERCISM_RUN_ALL_TESTS)
55+
endif()
56+
57+
# Tell MSVC not to warn us about unchecked iterators in debug builds
58+
# Treat warnings as errors
59+
# Treat type conversion warnings C4244 and C4267 as level 4 warnings, i.e. ignore them in level 3
60+
if(${MSVC})
61+
set_target_properties(${exercise} PROPERTIES
62+
COMPILE_DEFINITIONS_DEBUG _SCL_SECURE_NO_WARNINGS
63+
COMPILE_FLAGS "/WX /w44244 /w44267")
64+
endif()
65+
66+
# Run the tests on every build
67+
add_custom_target(test_${exercise} ALL DEPENDS ${exercise} COMMAND ${exercise})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "flower_field.h"
2+
3+
namespace flower_field {
4+
5+
// TODO: add your solution here
6+
7+
} // namespace flower_field
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#pragma once
2+
3+
namespace flower_field {
4+
5+
// TODO: add your solution here
6+
7+
} // namespace flower_field

0 commit comments

Comments
 (0)