1 package cz.cuni.amis.pogamut.ut2004.agent.navigation.astar;
2
3 import cz.cuni.amis.pathfinding.alg.astar.AStar;
4 import cz.cuni.amis.pathfinding.alg.astar.AStarResult;
5 import cz.cuni.amis.pathfinding.map.IPFMapView;
6 import cz.cuni.amis.pathfinding.map.IPFMapView.DefaultView;
7 import cz.cuni.amis.pogamut.base.agent.navigation.IPathFuture;
8 import cz.cuni.amis.pogamut.base.agent.navigation.IPathPlanner;
9 import cz.cuni.amis.pogamut.base.agent.navigation.impl.PrecomputedPathFuture;
10 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.NavigationGraphBuilder;
11 import cz.cuni.amis.pogamut.ut2004.agent.navigation.UT2004PathAutoFixer;
12 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
13 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.NavPoint;
14 import cz.cuni.amis.utils.collections.MyCollections;
15
16 public class UT2004AStar extends AStar<NavPoint> implements IPathPlanner<NavPoint> {
17
18
19
20
21
22 public UT2004AStar(UT2004Bot bot) {
23 this(new UT2004PFMap(bot.getWorldView()));
24 }
25
26
27
28
29
30 public UT2004AStar(UT2004Bot bot, IPFMapView<NavPoint> view) {
31 this(new UT2004PFMap(bot.getWorldView()), view);
32 }
33
34
35
36
37
38 public UT2004AStar(UT2004PFMap map) {
39 this(map, new IPFMapView.DefaultView());
40 }
41
42
43
44
45
46
47 public UT2004AStar(UT2004PFMap map, IPFMapView<NavPoint> view) {
48 super(map, view);
49 }
50
51 @Override
52 public UT2004PFMap getMap() {
53 return (UT2004PFMap) super.getMap();
54 }
55
56
57
58
59
60
61
62
63 public synchronized AStarResult<NavPoint> findPath(NavPoint from, NavPoint to, IPFMapView<NavPoint> mapView) {
64 return findPath(new UT2004PFGoal(from, to), mapView);
65 }
66
67
68
69
70 @Override
71 public IPathFuture<NavPoint> computePath(NavPoint from, NavPoint to) {
72 if (from == null || to == null) return new PrecomputedPathFuture<NavPoint>(from, to, null);
73 if (from == to) return new PrecomputedPathFuture<NavPoint>(from, to, MyCollections.toList(from));
74 AStarResult<NavPoint> result = findPath(from, to);
75 if (result == null) return new PrecomputedPathFuture<NavPoint>(from, to, null);
76 return new PrecomputedPathFuture<NavPoint>(from, to, result.getPath());
77 }
78
79
80
81
82
83
84
85
86 public synchronized AStarResult<NavPoint> findPath(NavPoint from, NavPoint to) {
87 return findPath(new UT2004PFGoal(from, to));
88 }
89
90
91
92
93 public void mapChanged() {
94 getMap().mapChanged();
95 }
96
97 }