I'm writing a game simulator called Iso-Path. It consists of a hexagonal grid, being itself formed of hexagons
You can see what I've already done on this link
But I packed the time to pick up the neighbors of a certain cell.
For example, cell 5 has 6 neighbors (0, 1, 4, 6, 10, 11)
Solet'sgotothecode
vartabuleiro="4567654";
podeMover(5, 0); // => true
podeMover(5, 1); // => true
podeMover(5, 4); // => true
podeMover(5, 7); // => false (Não são vizinhos)
One cell on the horizontal border would also have the cell of the other horizontal end. Soon ...
podeMover(22, 27); // true
Imightaswellcreateanarraywitheachneighbormanually,butI'dliketoknowhowtodothisprocedurally.
Theboardwouldalwaysbeahexagonmadeupofsmallerhexagons,sovalidtrayswouldberepresentedbystringsas(whereeachnumberdescribesthenumberofsmallerhexagonsinalineofthelargerhexagon,indicatedfromlefttorightastheyappearfromabovelowinfigure):
"3456543"
"4567654" // Padrão Iso-path
"567898765" // ... etc