Created
April 5, 2011 18:01
-
-
Save stuartpb/904137 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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