The method described in this answer can certainly work and is incredibly flexible. For example, that method would allow modifying the board at runtime! If you know you do not need that level of flexibility though, you can make things (subjectively) simpler by writingtailoring the code to your specific use case.
For example, if we wanted to allow moving on this board:
3--4--5
/ /
0--1--2
Then the following implementation which hard-codes in the split and join could be used:
SPLIT = 1
JOINS_TO_FOUR = [2,3]
LAST_SPACE = 5
def moves_from(space_index):
"""Returns an array of the space indexes of the moves that can
be made from this space index.
"""
if space_index == SPLIT:
return [2,3]
elif space_index in JOINS_TO_FOUR:
return [4]
elif 0 <= space_index < LAST_SPACE:
return [space_index + 1]
else:
return []