I haven’t reviewed your project or code in detail, but I feel like whether a given square is in range can be expressed by adding up the differences in rows and columns. I.e. if you need to move one column and three rows, that’s a distance of four.
local range = 4
local in_range = math.abs(start_col-target_col)+math.abs(start_row-target_row) <= range