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 withvertex
by passing the valuenil
as parametero
.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
ando
, whereq
,r
andv
uniquely identify the vertex ando
is the value associated with such vertex. If this function returns a value different fromnil
orfalse
, 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
- f
function
the iterator that will be called
for each association, receiving as parameter the
values