Skip to content

Add flower-field, deprecating minesweeper #328

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 5 commits into
base: main
Choose a base branch
from
Open
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
67 changes: 45 additions & 22 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,25 @@
"representer": false,
"analyzer": false
},
"test_runner": {
"average_run_time": 9
},
"blurb": "ABAP is a high level programming language created by SAP",
"version": 3,
"online_editor": {
"indent_style": "space",
"indent_size": 2,
"highlightjs_language": "abap"
},
"test_runner": {
"average_run_time": 9
},
"exercises": {
"concept": [
{
"slug": "lasagna",
"name": "Lucian's Luscious Lasagna",
"uuid": "0bb8f970-fe74-41f2-8ae6-2d771d87b607",
"concepts": ["basics"],
"concepts": [
"basics"
],
"prerequisites": [],
"status": "wip"
}
Expand Down Expand Up @@ -181,7 +183,10 @@
"practices": [],
"prerequisites": [],
"difficulty": 2,
"topics": ["parsing", "transforming"]
"topics": [
"parsing",
"transforming"
]
},
{
"slug": "raindrops",
Expand Down Expand Up @@ -223,13 +228,22 @@
"prerequisites": [],
"difficulty": 2
},
{
"slug": "flower-field",
"name": "Flower Field",
"uuid": "6e096ef1-5502-446f-b32c-65c3e4a8166b",
"practices": [],
"prerequisites": [],
"difficulty": 5
},
{
"slug": "minesweeper",
"name": "Minesweeper",
"uuid": "c8f6abc0-41a4-4104-8050-2df35f0d469a",
"practices": [],
"prerequisites": [],
"difficulty": 5
"difficulty": 5,
"status": "deprecated"
},
{
"slug": "word-count",
Expand All @@ -238,7 +252,12 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": ["loops", "lists", "regular_expressions", "strings"]
"topics": [
"loops",
"lists",
"regular_expressions",
"strings"
]
},
{
"slug": "beer-song",
Expand All @@ -247,7 +266,11 @@
"practices": [],
"prerequisites": [],
"difficulty": 5,
"topics": ["conditionals", "loops", "strings"]
"topics": [
"conditionals",
"loops",
"strings"
]
},
{
"slug": "darts",
Expand Down Expand Up @@ -380,43 +403,43 @@
],
"key_features": [
{
"icon": "evolving",
"title": "Evolving",
"content": "ABAP is a modern and constantly evolving language supported by SAP."
"content": "ABAP is a modern and constantly evolving language supported by SAP.",
"icon": "evolving"
},
{
"icon": "fun",
"title": "Fun",
"content": "Always a new or old feature to discover."
"content": "Always a new or old feature to discover.",
"icon": "fun"
},
{
"icon": "easy",
"title": "Easy",
"content": "Statements are easily readable and understandable."
"content": "Statements are easily readable and understandable.",
"icon": "easy"
},
{
"icon": "productive",
"title": "Productive",
"content": "Easily create data structures and interact with database contents."
"content": "Easily create data structures and interact with database contents.",
"icon": "productive"
},
{
"icon": "statically-typed",
"title": "Typed",
"content": "Static types linked to database schemas."
"content": "Static types linked to database schemas.",
"icon": "statically-typed"
},
{
"icon": "stable",
"title": "Reliability",
"content": "Stable functionality to run the core of the worlds largest businesses."
"content": "Stable functionality to run the core of the worlds largest businesses.",
"icon": "stable"
}
],
"tags": [
"execution_mode/compiled",
"paradigm/object_oriented",
"paradigm/procedural",
"runtime/language_specific",
"typing/static",
"typing/strong",
"execution_mode/compiled",
"runtime/language_specific",
"used_for/backends",
"used_for/financial_systems"
]
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": [
"mbtools"
],
"contributors": [
"BNAndras"
],
"files": {
"solution": [
"zcl_flower_field.clas.abap"
],
"test": [
"zcl_flower_field.clas.testclasses.abap"
],
"example": [
".meta/zcl_flower_field.clas.abap"
]
},
"blurb": "Mark all the flowers in a garden."
}
46 changes: 46 additions & 0 deletions exercises/practice/flower-field/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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"
87 changes: 87 additions & 0 deletions exercises/practice/flower-field/.meta/zcl_flower_field.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
CLASS zcl_flower_field DEFINITION PUBLIC FINAL CREATE PUBLIC.

PUBLIC SECTION.

METHODS annotate
IMPORTING
!input TYPE string_table
RETURNING
VALUE(result) TYPE string_table.

ENDCLASS.



CLASS zcl_flower_field IMPLEMENTATION.
METHOD annotate.

DATA n TYPE n LENGTH 1.
DATA res TYPE string.

CONCATENATE LINES OF input INTO DATA(field) RESPECTING BLANKS.
DATA(count) = strlen( field ).
DATA(rows) = lines( input ).
DATA(cols) = count DIV rows.

DO rows TIMES.
DATA(row) = sy-index - 1.
DO cols TIMES.
DATA(col) = sy-index - 1.
n = 0.
DO 9 TIMES.
CASE sy-index.
WHEN 1.
DATA(r) = row.
DATA(c) = col.
WHEN 2.
r = row.
c = col + 1.
WHEN 3.
r = row.
c = col - 1.
WHEN 4.
r = row + 1.
c = col.
WHEN 5.
r = row + 1.
c = col + 1.
WHEN 6.
r = row + 1.
c = col - 1.
WHEN 7.
r = row - 1.
c = col.
WHEN 8.
r = row - 1.
c = col + 1.
WHEN 9.
r = row - 1.
c = col - 1.
ENDCASE.
IF r BETWEEN 0 AND rows - 1 AND c BETWEEN 0 AND cols - 1.
IF substring( val = field off = r * cols + c len = 1 ) = `*`.
IF r = row AND c = col.
n = 9.
EXIT.
ELSE.
n = n + 1.
ENDIF.
ENDIF.
ENDIF.
ENDDO.
IF n = 0.
res = res && ` `.
ELSEIF n = 9.
res = res && `*`.
ELSE.
res = res && n.
ENDIF.
ENDDO.
ENDDO.

DO rows TIMES.
INSERT substring( val = res off = ( sy-index - 1 ) * cols len = cols ) INTO TABLE result.
ENDDO.

ENDMETHOD.
ENDCLASS.
10 changes: 10 additions & 0 deletions exercises/practice/flower-field/package.devc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DEVC" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DEVC>
<CTEXT>Exercism: Flower Field</CTEXT>
</DEVC>
</asx:values>
</asx:abap>
</abapGit>
19 changes: 19 additions & 0 deletions exercises/practice/flower-field/zcl_flower_field.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CLASS zcl_flower_field DEFINITION PUBLIC FINAL CREATE PUBLIC.

PUBLIC SECTION.

METHODS annotate
IMPORTING
!input TYPE string_table
RETURNING
VALUE(result) TYPE string_table.

ENDCLASS.

CLASS zcl_flower_field IMPLEMENTATION.

METHOD annotate.
" add solution here
ENDMETHOD.

ENDCLASS.
Loading