Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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)

+3
−0

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.

Dodecahedron

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.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

3 comment threads

Hardcoding (1 comment)
That animated picture is seriously annoying and distracting! (3 comments)
Resource suggestion (1 comment)

2 answers

+4
−0

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)])
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+2
−0

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>
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »