lualife, v1.4
Posted on

The library that implements Conway's Game of Life.
Supporting of field rotating.
Change Log
- operations with fields as with matrices:
- rotating of a field clockwise.
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:
- operations with fields as with matrices:
- rotating of a field clockwise;
- 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.matrix.rotate():
local Size = require("lualife.models.size")
local Point = require("lualife.models.point")
local Field = require("lualife.models.field")
local matrix = require("lualife.matrix")
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 field = Field:new(Size:new(3, 3))
field:set(Point:new(1, 0))
field:set(Point:new(2, 1))
field:set(Point:new(0, 2))
field:set(Point:new(1, 2))
field:set(Point:new(2, 2))
local rotated_field = matrix.rotate(field)
print_field(rotated_field)
Repository
Link: https://github.com/thewizardplusplus/lualife/tree/v1.4.
Content: code.
License: MIT.