MATLAB, 94 93 bytes
rng(input(''));x(9,9)=~1;x(randperm(81,10))=1;y=[conv2(+x,ones(3),'s')+48 ''];y(x)=42;disp(y)
Example run (the first line after the code is the input typed by the user):
>> rng(input(''));x(9,9)=~1;x(randperm(81,10))=1;y=[conv2(+x,ones(3),'s')+48 ''];y(x)=42;disp(y)
99
*10001*2*
220001232
*201111*1
*312*1111
12*211000
011211000
0001*1000
000112110
000001*10
Explanation
rng(input(''));
takes an integer and uses it as seed. (This works in modern MATLAB versions. Old versions may need a different syntax.)
x(9,9)=~1;
assigns logical 0
, or false
(obtained by logically negating 1
) to the entry (9,9)
of a matrix x
. The rest of the entries are automatically initiallized to logical 0
too.
x(randperm(81,10))=1;
assigns 1
(autoomatically cast to logical 1
, or true
) to 10
of the
81
entries of x
, chosen randomly without replacement. These entries are the ones that contain bombs.
conv2(+x,ones(3),'s')
is an abbreviation of conv2(+x,ones(3),'same')
. It convolves the matrix x
(which needs to be cast to double
, using +
) with a 3×3 neighbourhood containing 1
. This counts how many bombs are adjacent to each entry. For entries that contain a bomb it includes that bomb, but the value there will be overwritten later.
y=[...+48 ''];
adds 48 to the value, to convert from number to ASCII code. Concatenating with the empty matrix casts these ASCII codes to chars.
y(x)=42;
assigns 42 (ASCII code for '*'
) to the positions of the bombs. These positions are given by x
, which is here used as a logical index.
disp(y)
displays the result.
3You should indicate what the numbers mean :) – Nathan Merrill – 2016-09-02T20:11:47.630
4
Microsoft Minesweeper is a heck of a lot older than XP and minesweeper-like games date back to at least the 60s.
– AdmBorkBork – 2016-09-02T20:19:33.88711Also, I don't have time to play Minesweeper while at work -- I'm too busy on PPCG. ;-) – AdmBorkBork – 2016-09-02T20:41:02.713
1What counts as a PRNG, exactly? How many different configurations must it be able to produce? Can we not use the seed and just generate a different configuration each time, if our language has a PRNG which is automatically initallized to a "random" seed? – Luis Mendo – 2016-09-02T21:07:33.920
1@TimmyD But XP's version is the first version that had a 9x9 grid. Anything older uses an 8x8 grid for Beginner. #outnerded ;) – mbomb007 – 2016-09-02T21:37:06.623