Class catan.logic.EdgeMap
An associative array with hexagonal grid edges as keys.
Methods
catan.logic.edgemap:new () | Create an empty edge map. |
catan.logic.edgemap:get (edge) | Get the object associated with edge . |
catan.logic.edgemap:set (edge, o) | Associate edge with some object. |
catan.logic.edgemap:iter (f) | Iterate through all the associations. |
Methods
- catan.logic.edgemap:new ()
-
Create an empty edge map.
Returns:
-
catan.logic.EdgeMap
an empty edge map
- catan.logic.edgemap:get (edge)
-
Get the object associated with
edge
.Parameters:
- edge {q=number,r=number,e='NW', 'W' or 'NE'}
Returns:
-
the object associated with
edge
Usage:
local edgemap = EdgeMap:new() local edge = {q=1, r=0, e='W'} print(edgemap:get(edge)) --> nil edgemap:set(edge, 'hah') print(edgemap:get(edge)) --> hah
- catan.logic.edgemap:set (edge, o)
-
Associate
edge
with some object. You can also remove any association withedge
by passing the valuenil
as parametero
.Parameters:
- edge {q=number,r=number,e='NW', 'W' or 'NE'}
- o
the object to associate
edge
with
Usage:
local edgemap = EdgeMap:new() local edge = {q=1, r=0, e='W'} print(edgemap:get(edge)) --> nil edgemap:set(edge, 'hah') print(edgemap:get(edge)) --> hah
- catan.logic.edgemap: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
,e
ando
, whereq
,r
ande
uniquely identify the edge ando
is the value associated with such edge. If this function returns a value different fromnil
orfalse
, iteration is interrupted and this value is returned immediately.
Usage:
local haystack = EdgeMap:new() -- ... local edge = haystack:iter(function (q, r, e, o) if o == 'needle' then return {q = q, r = r, e = e} end end) if edge ~= nil then print(haystack:get(edge)) --> needle end
- f
function
the iterator that will be called
for each association, receiving as parameter the
values