Skip to content

Instantly share code, notes, and snippets.

@strokirk
Last active March 19, 2020 13:55
Show Gist options
  • Select an option

  • Save strokirk/f690c7960dcc5c57e44a9eda10d0e32f to your computer and use it in GitHub Desktop.

Select an option

Save strokirk/f690c7960dcc5c57e44a9eda10d0e32f to your computer and use it in GitHub Desktop.

Introduction

Add the mine counts to a completed Minesweeper board.

Minesweeper is a popular game where the user has to find the mines using numeric hints that indicate how many mines are directly adjacent (horizontally, vertically, diagonally) to a square.

In this exercise you have to create some code that counts the number of mines adjacent to a given empty square and replaces that square with the count.

The board is a rectangle composed of blank space (' ') characters. A mine is represented by an asterisk ('*') character.

If a given space has no adjacent mines at all, leave that square blank.

Examples

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

·*·*·
··*··
··*··
·····

And your code will transform it into this:

1*3*1
13*31
·2*2·
·111·
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment