minesweeper board in matlab

main.m
function minesweeper_board(row, col, num_mines)
    board = zeros(row, col);
    
    % Randomly place mines
    mine_spots = randperm(row * col, num_mines);
    
    for i = 1:num_mines
        r = floor((mine_spots(i)-1) / col) + 1;
        c = mod(mine_spots(i)-1, col) + 1;
        
        board(r, c) = -1;  % -1 represents a mine
    end
    
    disp(board);
end
371 chars
16 lines

gistlibby LogSnag