Log In  
Follow
mranderson455
[ :: Read More :: ]

Hello all!

I have been trying to make a minesweeper clone in order to practice grid based games. Everything was going well, until I tried to make the mechanic where adjacent 0 tiles are revealed. I made a recursive function, but when set to all eight directions, it would run out of memory almost instantly. Any tips on how to either optimize the function or replace it? Any help would be awesome, I'm not the best programmer, thanks!

Recursive function:

function tile_reveal(x,y)
    if y > 0
    and y <= #board.board
    and x > 0
    and x <= #board.board[1] then
        if board.overlay[y][x] == 11 then
            if board.board[y][x] != 9 then
                for d=1,#dirs do
                    if y+dirs[d][2] > 0
                    and y+dirs[d][2] <= #board.board
                    and x+dirs[d][1] > 0
                    and x+dirs[d][1] <= #board.board[1]
                    and board.overlay[y+dirs[d][2]][x+dirs[d][1]] == 11 then
                        board:change_overlay(x+dirs[d][1],y+dirs[d][2],0)
                    end
                end
            end
            board:change_overlay(x,y,0)
        end
    end
end

Cart #tyofagzi-0 | 2020-07-02 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

P#78805 2020-07-02 22:00 ( Edited 2020-07-02 22:01)