lualife, v1.3
Posted on

The library that implements Conway's Game of Life.
Supporting complement and intersection of fields as sets and extending of possibilities of size and field models.
Change Log
- models:
- size:
- supporting of checking if an other size with offset fits inside;
- field:
- supporting of counting of set cells;
- size:
- operations with fields as with sets:
- complement of fields:
- supporting an offset for the second operand;
- intersection of fields:
- supporting an offset for the second operand.
- complement of fields:
Features
- models:
- size:
- supporting of checking if an other size with offset fits inside;
- point:
- supporting of translation;
- supporting of scaling;
- supporting of textual representation;
- field:
- storing only of set cells;
- supporting of counting of set cells;
- supporting of checking if a cell is set;
- supporting of mapping;
- size:
- generating of a 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;
- complement of fields:
- supporting an offset for the second operand;
- intersection of fields:
- supporting an offset for the second 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:
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)
io.write("\n")
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)
local complemented_field = sets.complement(glider, blinker, Point:new(-1, 0))
print_field(complemented_field)
local intersected_field = sets.intersection(glider, blinker, Point:new(-1, 0))
print_field(intersected_field)
Repository
Link: https://github.com/thewizardplusplus/lualife/tree/v1.3.
Content: code.
License: MIT.