SneakySquid

Discord Minesweeper v2

Feb 27th, 2026 (edited)
11,168
3
Never
4
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 3 0
  1. -- Made for use with NotSoBot
  2. -- Original version: https://pastebin.com/g2T2mHcE
  3.  
  4. math.randomseed(os.time())
  5.  
  6. local grid_width = tonumber("{arg:0}") or 9
  7. local difficulty = (tonumber("{arg:1}") or 15) / 100
  8.  
  9. local grid, numbers = {}, {
  10.         [0] = ":white_large_square:",
  11.         ":one:", ":two:", ":three:",
  12.         ":four:", ":five:", ":six:",
  13.         ":seven:", ":eight:", ":bomb:",
  14. }
  15.  
  16. local neighbour_offsets = {
  17.         {-1, 0, 1, -1, 1, -1, 0, 1},
  18.         {-1, -1, -1, 0, 0, 1, 1, 1},
  19. }
  20.  
  21. for i = 0, grid_width^2 - 1 do
  22.         if math.random() <= difficulty then
  23.                 local x = i % grid_width
  24.                 local y = math.floor(i / grid_width)
  25.  
  26.                 grid[i] = 9
  27.  
  28.                 for j = 1, 8 do
  29.                         local x = x + neighbour_offsets[1][j]
  30.                         local y = y + neighbour_offsets[2][j]
  31.  
  32.                         if x >= 0 and x < grid_width and y >= 0 and y < grid_width then
  33.                                 local k = y * grid_width + x
  34.                                 local count = grid[k] or 0
  35.  
  36.                                 if count < 9 then
  37.                                         grid[k] = count + 1
  38.                                 end
  39.                         end
  40.                 end
  41.         end
  42. end
  43.  
  44. for i = 0, grid_width^2 - 1 do
  45.         grid[i] = numbers[grid[i] or 0]
  46.  
  47.         if (i + 1) % grid_width == 0 then
  48.                 print("||" .. table.concat(grid, "||||", i - grid_width + 1, i) .. "||")
  49.         end
  50. end
Advertisement
Comments
  • Vinyuxor
    210 days
    Comment was deleted
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment