Blinks Mapping Library

I have a first version of my Blinks Mapping Library. For now it just deals with maintaining the map itself so there is no support for the complicated part of actually making every blink know about every other blink in a cluster (but this will come).

The API is not frozen in stone. Specially the position iteration functions that take a function pointer will most likely change (Doing it like I did is taking a lot of storage space), but the general idea is there.

How it works:

1 - You first need to determine what is the maximum width and height of the map you want to maintain. If you use the custom Blinklib and disable or tweak the maximum size off datagrams, you can easily have a 256 position map (16x16) whcih each position taking one byte.
2 - After you do that, then you use Get() and Set() functions to set positions in the map and get them.

What it does that makes it not a simple 2D map is that it accept negative coordinates without problems and automatically adjusts the map to make the best use of space in it possible. Also, it is Blink aware and although you usually only deal with x and y, internally it keeps track of axial coordinates which means there is a third implicit z coordinate that can be inferred from x and y. This, for example, allows it to know what 6 of the 8 neighbors a square has in 2d space are real neighbors in an hexagon.

With all of the above, operations like iterating through all neighbors of a specific position or up to n positions away from it is very efficient (as efficient as possible considering the memory limitations).

This is specially useful if you want to develop AIs hint hint :slight_smile:


I added a full example of using this library (and the broadcast library) to map a cluster of Blinks. The example is jut to show one way this could be done and it is not really optimized at all (with debug disabled, it takes 49% of storage) although it is pretty close to what I do in Hexenwood (except it currently does not use the new library).

The sample code will show several things:

1 - When starting, you will see all Blinks zeroing-in on a single orientation (via face values). It should take only a couple of seconds unless you have too many Blinks).
2 - After they settle, clicking on a Blink will set that as the origin of the coordinate system and will start mapping all Blinks (you will see them turning to green).
3 - After the mapping process ends Blinks will turn back to blue and dump to the serial port all positions (I will update it later to actually dump a map representation).
4 - At this point, all blinks in the cluster know the position and associated value (currently only the number 1) of all other Blinks.