31
2
Minesweeper is a puzzle game where mines are hidden around a board of nondescript tiles with the goal of identifying the location of all mines. Clicking on a mine loses the game, but clicking on any other tile will reveal a number from 0-8 which signifies how many mines directly surround it.
Given a number, you must display a random* possible combination of empty tiles and mines surrounding it. This should be in the form of a 3x3 array. The center tile should be the number of mines taken as input.
*Must have a non-zero chance for all combinations to occur.
Examples
_ = blank square
X = mine
0
___
_0_
___
1
_X_
_1_
___
1
___
_1_
X__
___
_1_
__X
4
_X_
X4X
_X_
4
X_X
_4_
X_X
4
___
X4X
X_X
8
XXX
X8X
XXX
Input
- The number of mines surrounding the center tile (0-8)
Output
- Any reasonable form of output that displays the 3x3 array of tiles
Other rules
- Each combination does not have to have an equal chance of happening. There just must be a non-zero chance of each combination to occur when executing your program.
- Any 2 characters can be chosen for the mine and empty tile.
- This is code golf, the program with fewest bytes wins.
"Any 2 characters can be chosen for the mine and empty tile" may we still use, say,
1
and0
? – Jonathan Allan – 2018-06-03T01:10:30.0503@JonathanAllan I'll say yes, the 0/1 input cases might be a little bit confusing but I don't think it's a big deal. – aoemica – 2018-06-03T01:23:32.117
is a flat, 9-element list a 'reasonable form of output'? – Chas Brown – 2018-06-03T02:50:17.393
@ChasBrown no, a flat list is not really equivalent. – aoemica – 2018-06-03T03:44:01.537