Reject move commands in non-cardinal directions

This commit is contained in:
Marc Di Luzio 2020-07-19 11:26:08 +01:00
parent 0e731df1a3
commit c2e3c9f090
4 changed files with 23 additions and 9 deletions

View file

@ -55,8 +55,8 @@ func (d Bearing) ShortString() string {
return bearingStrings[d].Short
}
// FromString gets the Direction from a string
func FromString(s string) (Bearing, error) {
// BearingFromString gets the Direction from a string
func BearingFromString(s string) (Bearing, error) {
for i, d := range bearingStrings {
if strings.EqualFold(d.Long, s) || strings.EqualFold(d.Short, s) {
return Bearing(i), nil
@ -80,3 +80,15 @@ var bearingVectors = []Vector{
func (d Bearing) Vector() Vector {
return bearingVectors[d]
}
// IsCardinal returns if this is a cardinal (NESW)
func (d Bearing) IsCardinal() bool {
switch d {
case North:
case East:
case South:
case West:
return true
}
return false
}