Hexagonal Lattice Graph in C++?
Ich versuche catan in C++ zu programmieren und bin dabei darauf gestoßen:
Dies scheint perfekt zu sein, aber leider gibt es die NetworkX Bibliothek nur für Python. Meine Frage lautet daher: Gibt es so etwas auch für C++?
Ich wüsste nämlich nicht wie ich sowas mit Boost Graph machen könnte.
1 Antwort
Programmier dir das doch einfach selber. Du brauchst nur einen 2D-Array und eine Funktion, die dein Zugriffe passend verwaltet.
Ein Beispiel habe ich selber implementiert:
https://destra.uber.space/resources/scripts/snowflakes.js
Im Prinzip schibst du jede zweite Reihe um ein Stückchen nach rechts und schon hast du Hexagons statt Quader. Am Besten zeichnest du dir das einmal irgendwo auf, dann sollte die Idee recht schnell klar sein.
Steht im Script kurz so:
/*hexagon array:
. . . . . . . .
. . . . . . . . .
. . . . . . . .
. . . . . . . . .
. . . . . . . .
. . . . . . . . .
Neighbours are:
Horizontal: Vertical:
y-1 x top top left
y-1 x+1 right top top right
y x-1 left top left
y x+1 right bottom right
y+1 x left bottom bottom left
y+1 x+1 bottom bottom right
Clockwise order:
Horizontal: Vertical:
y-1 x top top left
y-1 x+1 right top top right
y x+1 right bottom right
y+1 x+1 bottom bottom right
y+1 x left bottom bottom left
y x-1 left top left
*/
Das Horizontal/Vertical ist da nur eine Aussage bezüglich wie die Schneeflocken gedreht sind, erkennbar darin, dass die eine Drehung eine top/bottom hat, die andere ein left/right.
(Und ich habe nur die zwei Drehungen, da das für ASCII-Art-Schneeflocken war, in anderen Anwendungsfällen würde man da wohl gar nicht unterscheiden, sondern nur eine Gesamtdrehung des Gitters angeben.)