package soko import "opslag.de/schobers/geom" type Direction int const ( DirectionUp Direction = iota DirectionRight DirectionDown DirectionLeft ) var Directions = [4]Direction{DirectionUp, DirectionRight, DirectionDown, DirectionLeft} func (d Direction) String() string { switch d { case DirectionUp: return "up" case DirectionRight: return "right" case DirectionDown: return "down" case DirectionLeft: return "left" } return "invalid" } func (d Direction) ToPoint() geom.Point { switch d { case DirectionUp: return geom.Pt(0, -1) case DirectionRight: return geom.Pt(1, 0) case DirectionDown: return geom.Pt(0, 1) case DirectionLeft: return geom.Pt(-1, 0) } return geom.Point{} } func Neighbours(p geom.Point) []geom.Point { neighbours := make([]geom.Point, 4) for i, dir := range Directions { neighbours[i] = p.Add(dir.ToPoint()) } return neighbours }