Class catan.logic.VertexMap

An associative array with hexagonal grid vertices as keys.

Methods

catan.logic.vertexmap:new () Create an empty vertex map.
catan.logic.vertexmap:get (vertex) Get the object associated with vertex.
catan.logic.vertexmap:set (vertex, o) Associate vertex with some object.
catan.logic.vertexmap:iter (f) Iterate through all the associations.


Methods

catan.logic.vertexmap:new ()
Create an empty vertex map.

Returns:

    catan.logic.VertexMap an empty vertex map
catan.logic.vertexmap:get (vertex)
Get the object associated with vertex.

Parameters:

  • vertex {q=number,r=number,v='N' or 'S'}

Returns:

    the object associated with vertex

Usage:

    local vertexmap = VertexMap:new()
    local vertex = {q=1, r=0, v='N'}
    print(vertexmap:get(vertex)) --> nil
    vertexmap:set(vertex, 'hah')
    print(vertexmap:get(vertex)) --> hah
catan.logic.vertexmap:set (vertex, o)
Associate vertex with some object. You can also remove any association with vertex by passing the value nil as parameter o.

Parameters:

  • vertex {q=number,r=number,v='N' or 'S'}
  • o the object to associate vertex with

Usage:

    local vertexmap = VertexMap:new()
    local vertex = {q=1, r=0, v='N'}
    print(vertexmap:get(vertex)) --> nil
    vertexmap:set(vertex, 'hah')
    print(vertexmap:get(vertex)) --> hah
catan.logic.vertexmap:iter (f)
Iterate through all the associations.

Parameters:

  • f function the iterator that will be called for each association, receiving as parameter the values q, r, v and o, where q, r and v uniquely identify the vertex and o is the value associated with such vertex. If this function returns a value different from nil or false, iteration is interrupted and this value is returned immediately.

Usage:

    local haystack = VertexMap:new()
    -- ...
    local vertex = haystack:iter(function (q, r, v, o)
      if o == 'needle' then
        return {q = q, r = r, v = v}
      end
    end)
    if vertex ~= nil then
      print(haystack:get(vertex)) --> needle
    end
generated by LDoc 1.5.0 Last updated 2023-07-02 05:10:58