-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirection.go
55 lines (48 loc) · 1.07 KB
/
direction.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ggworkshop
// Direction is an int enum that represents a direction in a maze
// (North, East, South and West).
type Direction int
const (
North Direction = iota
East
South
West
)
// Directions is a slice of maze.Direction.
type Directions []Direction
var (
// PossibleDirections is a Directions that contains all the possible
// directions the enum can have.
PossibleDirections Directions
)
func init() {
PossibleDirections = make(Directions, 4, 4)
PossibleDirections[North] = North
PossibleDirections[East] = East
PossibleDirections[South] = South
PossibleDirections[West] = West
}
// Contains returns whether Directions contains a given direction.
func (ds Directions) Contains(find Direction) bool {
for _, x := range ds {
if x == find {
return true
}
}
return false
}
// String formats the Direction. It returns the name of the enum value.
func (d Direction) String() string {
switch d {
case North:
return "North"
case East:
return "East"
case South:
return "South"
case West:
return "West"
default:
return "error , wrong direction"
}
}