World Conquest Chronicles

World Conquest Chronicles

lualife, v1.1

The library that implements Conway's Game of Life.

Supporting of point scaling, field mapping, and generating of a random field.

Change Log

  • models:
    • point:
      • supporting of scaling;
    • field:
      • supporting of mapping;
  • generating of a random field:
    • customizable filling factor.

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;
  • 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.random.generate():

local Size = require("lualife.models.size")
local Field = require("lualife.models.field")
local random = require("lualife.random")
local life = require("lualife.life")

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 function sleep(seconds)
  assert(type(seconds) == "number")

  local start = os.clock()
  while os.clock() - start < seconds do end
end

math.randomseed(os.time())

local field = random.generate(Size:new(10, 10), 0.5)
while true do
  field = life.populate(field)
  print_field(field)
  sleep(0.2)
end

Repository

Link: https://github.com/thewizardplusplus/lualife/tree/v1.1.

Content: code.

License: MIT.