Files

44 lines
568 B
Go
Raw Permalink Normal View History

2026-10-25 02:51:07 +00:00
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
}