@name hexc5
@inputs 
@outputs 
@persist 
@trigger 

#[
.......................
......a a a a a a......
.....b b b b b b b.....
....c c c c c c c c....
...d d d d d d d d d...
..e e e e e e e e e e..
.f f f f f f f f f f f.
..g g g g g g g g g g..
...h h h h h h h h h...
....i i i i i i i i....
.....k k k k k k k.....
......l l l l l l......
.......................


.......................
......aaaaaa......
.....bbbbbbb.....
....cccccccc....
...ddddddddd...
..eeeeeeeeee..
.fffffffffff.
..gggggggggg..
...hhhhhhhhh...
....iiiiiiii....
.....kkkkkkk.....
......llllll......
.......................

]#


Files = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L")
Ranks = array("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11")

local Tiles = table()
local Index = 0

for (I = 1, 6) {
    for (J = 1, 6 + I) {
        Index++
        Tiles[Index, table] = table(
            "index" = Index, 
            "file"  = Files[I, string], 
            "rank"  = Ranks[J, string],
            "neighbors" = array()
        )
    }
}


for (I = 7, 11) {
    for (J = 1, 16 - I) {
        Index++
        Tiles[Index, table] = table(
            "index" = Index, 
            "file"  = Files[I, string], 
            "rank"  = Ranks[J, string],
            "neighbors" = array()
        )
    }
}


for (Index = 1, 91) {
#[    if (Index != 91 & Tiles[Index, table]["file", string] == Tiles[Index + 1, table]["file", string]) {
        Tiles[Index, table]["neighbors", array]:pushNumber(Index + 1)
    }
    if (Index != 1 & Tiles[Index, table]["file", string] == Tiles[Index - 1, table]["file", string]) {
        Tiles[Index, table]["neighbors", array]:pushNumber(Index - 1)
    }]#
    
    local This = Tiles[Index, table]
    local Rank = This["rank", string]
    local File = This["file", string]

    if (Index != 91) {
        if (File == Tiles[Index + 1, table]["file", string]) {
            This["neighbors", array][1, number] = Index - 1 + 1 
        }
    }
    
    if (Index != 1) {
        if (File == Tiles[Index - 1, table]["file", string]) {
            This["neighbors", array][2, number] = Index - 1  - 1  
        }           
    }
    
    local ByteFile = toByte(File)
    
    if (ByteFile < 70) { #abcde
        This["neighbors", array][3, number] = Index - 1 + 7 + ByteFile
        This["neighbors", array][5, number] = Index - 1 + 6 + ByteFile
        
        if (File != "A") {
            if (File == Tiles[Index - 1, table]["file", string]) {
                This["neighbors", array][4, number] = Index - 1 - 5 + ByteFile
            } 
            
            if (Rank != "1") {
                This["neighbors", array][6, number] = Index - 1 - 6 + ByteFile
            }  
        }
    }
    elseif (File == "F") {
        if (Rank != "11") {
            This["neighbors", array][3, number] = Index - 1 + 11
            This["neighbors", array][4, number] = Index - 1 - 10
        }
        if (Rank != "1") {
            This["neighbors", array][5, number] = Index - 1 + 10
            This["neighbors", array][6, number] = Index - 1 - 11
        }
    }

}





#[  
                else if (tiles[index].file == File.F)               // F
                {
                    if (tiles[index].rank != Rank.Eleven)
                    {
                        tiles[index].Neighbors[2] = tiles[index + 11];
                        tiles[index].Neighbors[3] = tiles[index - 10];
                    }
                    if (tiles[index].rank != Rank.One)
                    {
                        tiles[index].Neighbors[4] = tiles[index + 10];
                        tiles[index].Neighbors[5] = tiles[index - 11];
                    }
                }
                else                                                // GHIKL
                {
                    tiles[index].Neighbors[3] = tiles[index - 11 + ((int)tiles[index].file - (int)File.F)];
                    tiles[index].Neighbors[5] = tiles[index - 12 + ((int)tiles[index].file - (int)File.F)];
                    if (tiles[index].file != File.L)
                    {
                        if (tiles[index].file == tiles[index + 1].file)
                            tiles[index].Neighbors[2] = tiles[index + 11 + ((int)File.F - (int)tiles[index].file)];
                        if (tiles[index].rank != Rank.One)
                            tiles[index].Neighbors[4] = tiles[index + 10 + ((int)File.F - (int)tiles[index].file)];
                    }
                }
            }]#

