package direction import ( "math/rand" ) type Direction int const ( Down Direction = iota Left Right Up ) func (d Direction) Opposite() Direction { switch d { case Down: return Up case Left: return Right case Right: return Left case Up: return Down default: return d } } func Directions() [4]Direction { return [4]Direction{Down, Left, Right, Up} } func RandomDirections() [4]Direction { var dirs = [...]Direction{Down, Left, Right, Up} rand.Shuffle(len(dirs), func(i, j int) { dirs[i], dirs[j] = dirs[j], dirs[i] }) return dirs }