I had learnt to program only a couple of months ago in my Matlab course at college (Engineering Major). This one includes 10 mines as requested.A GUI game based on Minesweeper. These positions are given by x, which is here used as a logical index. y(x)=42 Īssigns 42 (ASCII code for '*') to the positions of the bombs. Concatenating with the empty matrix casts these ASCII codes to chars. y= Īdds 48 to the value, to convert from number to ASCII code. For entries that contain a bomb it includes that bomb, but the value there will be overwritten later. This counts how many bombs are adjacent to each entry. It convolves the matrix x (which needs to be cast to double, using +) with a 3×3 neighbourhood containing 1. Is an abbreviation of conv2(+x,ones(3),'same'). These entries are the ones that contain bombs. x(randperm(81,10))=1 Īssigns 1 (autoomatically cast to logical 1, or true) to 10 of theĨ1 entries of x, chosen randomly without replacement. The rest of the entries are automatically initiallized to logical 0 too. Old versions may need a different syntax.) x(9,9)=~1 Īssigns logical 0, or false (obtained by logically negating 1) to the entry (9,9) of a matrix x.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |