Add maze pkg

This commit is contained in:
dwrz
2026-10-25 02:51:07 +00:00
parent 1aabbdfee7
commit 17d9903f17
6 changed files with 388 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
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
}