MCPcopy Create free account
hub / github.com/Neop/mudmap2 / breadthSearch

Method breadthSearch

src/main/java/mudmap2/backend/World.java:567–593  ·  view source on GitHub ↗

does a breadth search @param start start place @param end end place @return end place or null. Following the predecessors of this path leads to the start place

(Place start, Place end)

Source from the content-addressed store, hash-verified

565 * to the start place
566 */
567 @Override
568 public Place breadthSearch(Place start, Place end) {
569 for(Layer layer: getLayers()){
570 for(Place place: layer.getPlaces()){
571 place.breadthSearchReset();
572 }
573 }
574 start.getBreadthSearchData().marked = true;
575
576 LinkedList<Place> queue = new LinkedList<>();
577 queue.add(start);
578
579 while(!queue.isEmpty()){
580 Place v = queue.pollFirst();
581 if(v == end) return v;
582
583 for(Path pa: v.getPaths()){
584 Place vi = pa.getOtherPlace(v);
585 if(!vi.getBreadthSearchData().marked && vi != v && !pa.getExit(v).equals("-")){
586 vi.getBreadthSearchData().marked = true;
587 vi.getBreadthSearchData().predecessor = v;
588 queue.addLast(vi);
589 }
590 }
591 }
592 return null;
593 }
594
595 // --------- listeners -----------------------------------------------------
596 /**

Callers 1

testBreadthSearchMethod · 0.95

Calls 9

getLayersMethod · 0.95
getPathsMethod · 0.95
getBreadthSearchDataMethod · 0.95
getOtherPlaceMethod · 0.80
breadthSearchResetMethod · 0.65
getBreadthSearchDataMethod · 0.65
isEmptyMethod · 0.65
getPlacesMethod · 0.45
getExitMethod · 0.45

Tested by 1

testBreadthSearchMethod · 0.76