Moving right along
This commit is contained in:
@@ -28,22 +28,55 @@ type Maze struct {
|
||||
path []*helpers.Coordinate
|
||||
dirHistory []int
|
||||
dnt bool
|
||||
|
||||
bfs map[*helpers.Coordinate]*BFSNode
|
||||
|
||||
startCoord *helpers.Coordinate
|
||||
o2Coord *helpers.Coordinate
|
||||
}
|
||||
|
||||
func NewMaze() *Maze {
|
||||
m := &Maze{
|
||||
maze: make(map[string]int),
|
||||
maxX: helpers.MIN_INT,
|
||||
minX: helpers.MAX_INT,
|
||||
maxY: helpers.MIN_INT,
|
||||
minY: helpers.MAX_INT,
|
||||
bot: helpers.NewCoordinate(0, 0),
|
||||
maze: make(map[string]int),
|
||||
maxX: helpers.MIN_INT,
|
||||
minX: helpers.MAX_INT,
|
||||
maxY: helpers.MIN_INT,
|
||||
minY: helpers.MAX_INT,
|
||||
bot: helpers.NewCoordinate(0, 0),
|
||||
bfs: make(map[*helpers.Coordinate]*BFSNode),
|
||||
startCoord: helpers.NewCoordinate(0, 0),
|
||||
}
|
||||
m.path = append(m.path, helpers.NewCoordinate(0, 0))
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *Maze) SetCoord(c *helpers.Coordinate, val int) {
|
||||
var b *BFSNode
|
||||
var ok bool
|
||||
if b, ok = m.bfs[c]; !ok {
|
||||
b = &BFSNode{Value: val}
|
||||
m.bfs[c] = b
|
||||
}
|
||||
// Create the BFS node for this
|
||||
if n, ok := m.bfs[c.GetNorthCoord()]; ok {
|
||||
n.South = b
|
||||
b.North = n
|
||||
}
|
||||
if e, ok := m.bfs[c.GetEastCoord()]; ok {
|
||||
e.West = b
|
||||
b.East = e
|
||||
}
|
||||
if s, ok := m.bfs[c.GetSouthCoord()]; ok {
|
||||
s.North = b
|
||||
b.South = s
|
||||
}
|
||||
if w, ok := m.bfs[c.GetWestCoord()]; ok {
|
||||
w.East = b
|
||||
b.West = w
|
||||
}
|
||||
if val == 2 {
|
||||
m.o2Coord = c
|
||||
}
|
||||
m.maze[c.String()] = val
|
||||
if m.maxX < c.X {
|
||||
m.maxX = c.X
|
||||
@@ -137,3 +170,26 @@ func (m *Maze) Print() {
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
type BFSNode struct {
|
||||
Value int
|
||||
North, East *BFSNode
|
||||
South, West *BFSNode
|
||||
}
|
||||
|
||||
func (b *BFSNode) getChildren() []*BFSNode {
|
||||
var ret []*BFSNode
|
||||
if b.North != nil {
|
||||
ret = append(ret, b.North)
|
||||
}
|
||||
if b.East != nil {
|
||||
ret = append(ret, b.East)
|
||||
}
|
||||
if b.South != nil {
|
||||
ret = append(ret, b.South)
|
||||
}
|
||||
if b.West != nil {
|
||||
ret = append(ret, b.West)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user