Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Algorithmically generating the grid formed by the vertices of a dodecahedron (Hunt The Wumpus)
I am attempting to write a program to simulate Hunt The Wumpus in the K programming language. The game requires a grid that is created by the vertices of a Dodecahedron, which is cyclic and triangular in nature.
The general approach I can find on Rosetta Code is generally a hardcoded list of points, like as follows:
Adjacent_Rooms : constant Rooms :=
((1, 4, 7), (0, 2, 9), (1, 3, 11), (2, 3, 13), (0, 3, 5), (4, 6, 14),
(5, 7, 16), (0, 6, 8), (7, 9, 17), (1, 8, 10), (9, 11, 18), (2, 10, 12),
(11, 13, 19), (3, 12, 14), (5, 13, 15), (14, 16, 19), (5, 15, 17),
(8, 16, 18), (10, 17, 19), (12, 15, 18));
basically encoding the indices of the points that each point links to. I seek to find out a way to algorithmically generate these points (not necessarily using math), or somehow simulate the grid with an ordinary 1D or 2D array somehow.
Since K isn't a popular language, I would appreciate answers in a pseudocode format so I can translate the approach correctly.
2 answers
When I implemented this for a code golf challenge, the state had to encode not only the vertex you were at but the edge by which you had entered (or, equivalently, the direction in which you were facing) so that you could choose "left", "right", or "back" as the exit to use. Thus the state is effectively an element of the symmetry group of the icosahedron, which is isomorphic to the alternating group on 5 letters, $A_5$.
I used elements of $A_5$ directly, but you could use the standard presentation
<a, b | a^2 = b^3 = (ab)^5 = 1>
0 comment threads
Here is an animation of a cube with faces subdivided into two rectangles, morphing into a rhombic dodecahedron, with the Platonic dodecahedron as an intermediate state. This demonstrates that the edge graph of the Platonic dodecahedron is the same as the edge graph of the subdivided cube.
There are probably a lot of ways you could generate this graph algorithmically, but here's one (in Python rather than pseudocode, but Python is pretty close to pseudocode):
edges = []
for x, y, z in [(0, 1, 2), (1, 2, 0), (2, 0, 1)]:
for side in [0, 2]:
a0 = {x: 0, y: 0, z: side}
a1 = {x: 1, y: 0, z: side}
a2 = {x: 2, y: 0, z: side}
b0 = {x: 0, y: 2, z: side}
b1 = {x: 1, y: 2, z: side}
b2 = {x: 2, y: 2, z: side}
edges.extend([(a0, a1), (a1, a2), (b0, b1), (b1, b2), (a1, b1)])
3 comment threads