Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,14 @@
"prerequisites": [],
"difficulty": 6
},
{
"slug": "flower-field",
"name": "Flower Field",
"uuid": "a989bd48-2ec8-4e23-bee7-9282ba3188a0",
"practices": [],
"prerequisites": [],
"difficulty": 6
},
{
"slug": "killer-sudoku-helper",
"name": "Killer Sudoku Helper",
Expand Down
26 changes: 26 additions & 0 deletions exercises/practice/flower-field/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Instructions

Your task is to add flower counts to empty squares in a completed Flower Field garden.
The garden itself is a rectangle board composed of squares that are either empty (`' '`) or a flower (`'*'`).

For each empty square, count the number of flowers adjacent to it (horizontally, vertically, diagonally).
If the empty square has no adjacent flowers, leave it empty.
Otherwise replace it with the count of adjacent flowers.

For example, you may receive a 5 x 4 board like this (empty spaces are represented here with the '·' character for display on screen):

```text
·*·*·
··*··
··*··
·····
```

Which your code should transform into this:

```text
1*3*1
13*31
·2*2·
·111·
```
7 changes: 7 additions & 0 deletions exercises/practice/flower-field/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Introduction

[Flower Field][history] is a compassionate reimagining of the popular game Minesweeper.
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.
"Flower Field" shipped in regional versions of Microsoft Windows in Italy, Germany, South Korea, Japan and Taiwan.

[history]: https://web.archive.org/web/20020409051321fw_/http://rcm.usr.dsi.unimi.it/rcmweb/fnm/
20 changes: 20 additions & 0 deletions exercises/practice/flower-field/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"authors": [
"IsaacG"
],
"files": {
"solution": [
"flower_field.gd"
],
"test": [
"flower_field_test.gd",
"run_tests",
"lib/test_runner.gd",
"project.godot"
],
"example": [
".meta/example.gd"
]
},
"blurb": "Mark all the flowers in a garden."
}
27 changes: 27 additions & 0 deletions exercises/practice/flower-field/.meta/example.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
func get_cell(garden, x, y):
if x < 0 or y < 0 or y >= len(garden) or x >= len(garden[y]) or garden[y][x] == " ":
return 0
return 1


func neighbors(garden, x, y):
var total = 0
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
total += get_cell(garden, x + dx, y + dy)
return total - get_cell(garden, x, y)


func annotate(garden):
var out = []
for y in range(len(garden)):
var row = []
for x in range(len(garden[y])):
if garden[y][x] == "*":
row.append("*")
elif neighbors(garden, x, y) == 0:
row.append(" ")
else:
row.append("%d" % neighbors(garden, x, y))
out.append("".join(row))
return out
11 changes: 11 additions & 0 deletions exercises/practice/flower-field/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% for case in cases %}
func test_{{ case.func_name }}(solution_script):
var got = solution_script.{{ case.property }}([{% for line in case.given %}
{{ line | quote }},{% endfor %}
])
var want = [{% for line in case.expected %}
{{ line | quote }},{% endfor %}
]
return [got, want]

{% endfor %}
49 changes: 49 additions & 0 deletions exercises/practice/flower-field/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[237ff487-467a-47e1-9b01-8a891844f86c]
description = "no rows"

[4b4134ec-e20f-439c-a295-664c38950ba1]
description = "no columns"

[d774d054-bbad-4867-88ae-069cbd1c4f92]
description = "no flowers"

[225176a0-725e-43cd-aa13-9dced501f16e]
description = "garden full of flowers"

[3f345495-f1a5-4132-8411-74bd7ca08c49]
description = "flower surrounded by spaces"

[6cb04070-4199-4ef7-a6fa-92f68c660fca]
description = "space surrounded by flowers"

[272d2306-9f62-44fe-8ab5-6b0f43a26338]
description = "horizontal line"

[c6f0a4b2-58d0-4bf6-ad8d-ccf4144f1f8e]
description = "horizontal line, flowers at edges"

[a54e84b7-3b25-44a8-b8cf-1753c8bb4cf5]
description = "vertical line"

[b40f42f5-dec5-4abc-b167-3f08195189c1]
description = "vertical line, flowers at edges"

[58674965-7b42-4818-b930-0215062d543c]
description = "cross"

[dd9d4ca8-9e68-4f78-a677-a2a70fd7a7b8]
description = "large garden"

[6e4ac13a-3e43-4728-a2e3-3551d4b1a996]
description = "multiple adjacent flowers"
2 changes: 2 additions & 0 deletions exercises/practice/flower-field/flower_field.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func annotate(garden):
pass
176 changes: 176 additions & 0 deletions exercises/practice/flower-field/flower_field_test.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
func test_no_rows(solution_script):
var got = solution_script.annotate([
])
var want = [
]
return [got, want]


func test_no_columns(solution_script):
var got = solution_script.annotate([
"",
])
var want = [
"",
]
return [got, want]


func test_no_flowers(solution_script):
var got = solution_script.annotate([
" ",
" ",
" ",
])
var want = [
" ",
" ",
" ",
]
return [got, want]


func test_garden_full_of_flowers(solution_script):
var got = solution_script.annotate([
"***",
"***",
"***",
])
var want = [
"***",
"***",
"***",
]
return [got, want]


func test_flower_surrounded_by_spaces(solution_script):
var got = solution_script.annotate([
" ",
" * ",
" ",
])
var want = [
"111",
"1*1",
"111",
]
return [got, want]


func test_space_surrounded_by_flowers(solution_script):
var got = solution_script.annotate([
"***",
"* *",
"***",
])
var want = [
"***",
"*8*",
"***",
]
return [got, want]


func test_horizontal_line(solution_script):
var got = solution_script.annotate([
" * * ",
])
var want = [
"1*2*1",
]
return [got, want]


func test_horizontal_line_flowers_at_edges(solution_script):
var got = solution_script.annotate([
"* *",
])
var want = [
"*1 1*",
]
return [got, want]


func test_vertical_line(solution_script):
var got = solution_script.annotate([
" ",
"*",
" ",
"*",
" ",
])
var want = [
"1",
"*",
"2",
"*",
"1",
]
return [got, want]


func test_vertical_line_flowers_at_edges(solution_script):
var got = solution_script.annotate([
"*",
" ",
" ",
" ",
"*",
])
var want = [
"*",
"1",
" ",
"1",
"*",
]
return [got, want]


func test_cross(solution_script):
var got = solution_script.annotate([
" * ",
" * ",
"*****",
" * ",
" * ",
])
var want = [
" 2*2 ",
"25*52",
"*****",
"25*52",
" 2*2 ",
]
return [got, want]


func test_large_garden(solution_script):
var got = solution_script.annotate([
" * * ",
" * ",
" * ",
" * *",
" * * ",
" ",
])
var want = [
"1*22*1",
"12*322",
" 123*2",
"112*4*",
"1*22*2",
"111111",
]
return [got, want]


func test_multiple_adjacent_flowers(solution_script):
var got = solution_script.annotate([
" ** ",
])
var want = [
"1**1",
]
return [got, want]
Loading
Loading