Skip to content

Instantly share code, notes, and snippets.

@stuartpb
Created April 5, 2011 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuartpb/904137 to your computer and use it in GitHub Desktop.
Save stuartpb/904137 to your computer and use it in GitHub Desktop.
--The values used to represent trees, fires, and empty space.
local TREE = 'T'
local BURNING = '#'
local EMPTY = ' '
--Returns a table with gettors and settors for 2D coordinates.
--This implementation uses a single underlying 1-dimensional
--array table. It could also be changed to use a 2-dimensional
--table of row/column tables, or a table with serialized coordinates.
local function array2d(w,h)
local function coords(x,y)
return y * w + x
end
local array = {}
local methods = {}
function methods.get(x, y)
return array[coords(x, y)]
end
function methods.set(x, y, val)
array[coords(x, y)] = val
end
function methods.tostring()
local rows={}
for i=1,#h do
rows[i]=table.concat(array,'',coords(0,i),coords(w,i))
end
end
return access
end
local function makeforest (width, height, init_tree_prob, f_prob, p_prob)
local forest = array2d(width, height)
--add additional methods to the array
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment