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
33 changes: 21 additions & 12 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,23 @@
],
"difficulty": 5
},
{
"slug": "flower-field",
"name": "Flower Field",
"uuid": "e987a3e1-3e79-459a-97e1-d1173ffd934b",
"practices": [
"string-formatting",
"chars"
],
"prerequisites": [
"strings",
"chars",
"string-formatting",
"arrays",
"if-statements"
],
"difficulty": 5
},
{
"slug": "food-chain",
"name": "Food Chain",
Expand All @@ -1665,18 +1682,10 @@
"slug": "minesweeper",
"name": "Minesweeper",
"uuid": "466f17d4-13d0-4d6e-8564-c8bdfede35d1",
"practices": [
"string-formatting",
"chars"
],
"prerequisites": [
"strings",
"chars",
"string-formatting",
"arrays",
"if-statements"
],
"difficulty": 5
"practices": [],
"prerequisites": [],
"difficulty": 5,
"status": "deprecated"
},
{
"slug": "scale-generator",
Expand Down
15 changes: 15 additions & 0 deletions exercises/Exercises.sln
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwiftScheduling", "practice
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RelativeDistance", "practice\relative-distance\RelativeDistance.csproj", "{2C37454E-8624-47B8-A09B-ADE201C2B04C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlowerField", "practice\flower-field\FlowerField.csproj", "{88E165C6-5E27-4F48-942A-0D41A9A6326D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -2539,6 +2541,18 @@ Global
{2C37454E-8624-47B8-A09B-ADE201C2B04C}.Release|x64.Build.0 = Release|Any CPU
{2C37454E-8624-47B8-A09B-ADE201C2B04C}.Release|x86.ActiveCfg = Release|Any CPU
{2C37454E-8624-47B8-A09B-ADE201C2B04C}.Release|x86.Build.0 = Release|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Debug|x64.ActiveCfg = Debug|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Debug|x64.Build.0 = Debug|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Debug|x86.ActiveCfg = Debug|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Debug|x86.Build.0 = Debug|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Release|Any CPU.Build.0 = Release|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Release|x64.ActiveCfg = Release|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Release|x64.Build.0 = Release|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Release|x86.ActiveCfg = Release|Any CPU
{88E165C6-5E27-4F48-942A-0D41A9A6326D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2725,6 +2739,7 @@ Global
{FA726133-BC1C-D753-28C5-C9ACB44C0776} = {E276EF69-669A-43E0-88AC-8ABB17A9C026}
{9A073412-4B64-48EB-A346-A56DE6847CCC} = {FA726133-BC1C-D753-28C5-C9ACB44C0776}
{2C37454E-8624-47B8-A09B-ADE201C2B04C} = {E276EF69-669A-43E0-88AC-8ABB17A9C026}
{88E165C6-5E27-4F48-942A-0D41A9A6326D} = {E276EF69-669A-43E0-88AC-8ABB17A9C026}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {AB4EA6C9-5461-4024-BDC7-2AE0C3A85CD1}
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/
141 changes: 141 additions & 0 deletions exercises/practice/flower-field/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
###############################
# Core EditorConfig Options #
###############################

; This file is for unifying the coding style for different editors and IDEs.
; More information at:
; https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017
; https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2017

root = true

[*]
indent_style = space

[FlowerField.cs]
indent_size = 4

###############################
# .NET Coding Conventions #
###############################

# Organize usings
dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = true

# this. preferences
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion

# Modifier preferences
dotnet_style_require_accessibility_modifiers = always:suggestion
dotnet_style_readonly_field = true:suggestion

# Expression-level preferences
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion

###############################
# Naming Conventions #
###############################

# Style Definitions
dotnet_naming_style.pascal_case_style.capitalization = pascal_case

# Use PascalCase for constant fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
dotnet_naming_symbols.constant_fields.applicable_kinds = field
dotnet_naming_symbols.constant_fields.applicable_accessibilities = *
dotnet_naming_symbols.constant_fields.required_modifiers = const

###############################
# C# Code Style Rules #
###############################

# var preferences
csharp_style_var_for_built_in_types = true:none
csharp_style_var_when_type_is_apparent = true:none
csharp_style_var_elsewhere = true:none

# Expression-bodied members
csharp_style_expression_bodied_methods = true:suggestion
csharp_style_expression_bodied_constructors = true:suggestion
csharp_style_expression_bodied_operators = true:suggestion
csharp_style_expression_bodied_properties = true:suggestion
csharp_style_expression_bodied_indexers = true:suggestion
csharp_style_expression_bodied_accessors = true:suggestion

# Pattern-matching preferences
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion

# Null-checking preferences
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Modifier preferences
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion

# Expression-level preferences
csharp_prefer_braces = true:none
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion

###############################
# C# Formatting Rules #
###############################

# New line preferences
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = false
csharp_new_line_before_members_in_anonymous_types = false
csharp_new_line_between_query_expression_clauses = true

# Indentation preferences
csharp_indent_case_contents = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left

# Space preferences
csharp_space_after_cast = false
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false

# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
57 changes: 57 additions & 0 deletions exercises/practice/flower-field/.meta/Example.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
public class FlowerField
{
public static string[] Annotate(string[] input)
{
var results = new List<string>();

var board = input;

for (int i = 0; i < board.Length; i++)
{
var result = string.Empty;

for (int j = 0; j < board[0].Length; j++)
{
if (board[i][j] == '*')
{
result += '*';
}
else
{
var numMines = GetCountForSquare(board, i, j);
result += numMines == 0
? " "
: numMines.ToString();
}
}

results.Add(result);
}

return results.ToArray();
}

private static int GetCountForSquare(string[] board, int x, int y)
{
var result = 0;

for (int i = -1; i <= 1; i++)
{
for (int j = -1; j <= 1; j++)
{
try
{
if (board[x + i][y + j] == '*')
{
result++;
}
}
catch (IndexOutOfRangeException)
{
}
}
}

return result;
}
}
24 changes: 24 additions & 0 deletions exercises/practice/flower-field/.meta/Generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
public class {{ testClass }}
{
{{- for test in tests }}
[Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}]
public void {{ test.testMethod }}()
{
{{- if test.input.garden.empty? }}
Assert.Empty({{ testedClass }}.{{ test.testedMethod }}(Array.Empty<string>()));
{{ else }}
string[] garden = [
{{- for line in test.input.garden }}
{{ line | string.literal }}{{- if !for.last }},{{ end -}}
{{ end }}
];
string[] expected = [
{{- for line in test.expected }}
{{ line | string.literal }}{{- if !for.last }},{{ end -}}
{{ end }}
];
Assert.Equal(expected, {{ testedClass }}.{{ test.testedMethod }}(garden));
{{ end -}}
}
{{ end -}}
}
24 changes: 24 additions & 0 deletions exercises/practice/flower-field/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"authors": [
"robkeim"
],
"contributors": [
"BNAndras",
"ErikSchierboom",
"felix91gr",
"j2jensen",
"wolf99"
],
"files": {
"solution": [
"FlowerField.cs"
],
"test": [
"FlowerFieldTests.cs"
],
"example": [
".meta/Example.cs"
]
},
"blurb": "Mark all the flowers in a garden."
}
Loading
Loading