move enqueue(ns[dir]) into loop

This commit is contained in:
onyx-and-iris 2024-12-25 21:01:35 +00:00
parent 33ee076cf1
commit 5a6947af2c

View File

@ -47,36 +47,30 @@ func exploreBFS(graph *graph, dir direction) (*orderedmap.OrderedMap[point, stru
case '#':
return om, false
case '[', ']':
log.Debugf("adding %s to the queue", string(graph.valueAt(ns[dir])))
queue.Enqueue(ns[dir])
_, ok := om.Get(ns[dir])
if !ok {
om.Set(ns[dir], struct{}{})
}
nextDirections := []direction{dir}
var additionalDirections []direction
if graph.valueAt(ns[dir]) == '[' {
switch dir {
case N:
additionalDirections = []direction{NE}
nextDirections = append(nextDirections, NE)
case S:
additionalDirections = []direction{SE}
nextDirections = append(nextDirections, SE)
}
} else if graph.valueAt(ns[dir]) == ']' {
switch dir {
case N:
additionalDirections = []direction{NW}
nextDirections = append(nextDirections, NW)
case S:
additionalDirections = []direction{SW}
nextDirections = append(nextDirections, SW)
}
}
for _, dir := range additionalDirections {
log.Debugf("adding %s to the queue", string(graph.valueAt(ns[dir])))
queue.Enqueue(ns[dir])
_, ok := om.Get(ns[dir])
for _, nextDirection := range nextDirections {
log.Debugf("adding %s to the queue", string(graph.valueAt(ns[nextDirection])))
queue.Enqueue(ns[nextDirection])
_, ok := om.Get(ns[nextDirection])
if !ok {
om.Set(ns[dir], struct{}{})
om.Set(ns[nextDirection], struct{}{})
}
}
}