lualife, v1.2
Posted on

The library that implements Conway's Game of Life.
Supporting union of fields as sets, and generating of a random field with limiting by a cell count.
Change Log
- generating of a random field:
- limiting by a cell count:
- lower limit;
- upper limit;
- limiting by a cell count:
- operations with fields as with sets:
- union of fields:
- supporting an offset for the second operand;
- restricting of the result size by the size of the first operand.
- union of fields:
Features
- models:
- size;
- point:
- supporting of translation;
- supporting of scaling;
- supporting of textual representation;
- field:
- storing only of set cells;
- supporting of mapping;
- generating of random field:
- customizable filling factor;
- limiting by a cell count:
- lower limit;
- upper limit;
- operations with fields as with sets:
- union of fields:
- supporting an offset for the second operand;
- restricting of the result size by the size of the first operand;
- union of fields:
- populating of a field according to Conway's Game of Life rules:
- using of the naive algorithm with iterating and copying of a whole field.
Examples
lualife.sets.union():
local Size = require("lualife.models.size")
local Point = require("lualife.models.point")
local Field = require("lualife.models.field")
local sets = require("lualife.sets")
local function print_field(field)
assert(field:isInstanceOf(Field))
field:map(function(point, contains)
io.write(contains and "O" or ".")
if point.x == field.size.width - 1 then
io.write("\n")
end
end)
end
local glider = Field:new(Size:new(3, 3))
glider:set(Point:new(1, 0))
glider:set(Point:new(2, 1))
glider:set(Point:new(0, 2))
glider:set(Point:new(1, 2))
glider:set(Point:new(2, 2))
local blinker = Field:new(Size:new(3, 3))
blinker:set(Point:new(1, 0))
blinker:set(Point:new(1, 1))
blinker:set(Point:new(1, 2))
local unioned_field = sets.union(glider, blinker, Point:new(-1, 0))
print_field(unioned_field)
Repository
Link: https://github.com/thewizardplusplus/lualife/tree/v1.2.
Content: code.
License: MIT.