-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStupidAI.java
More file actions
executable file
·49 lines (43 loc) · 1.48 KB
/
StupidAI.java
File metadata and controls
executable file
·49 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
/// A sample AI that takes a very suboptimal path.
/**
* This is a sample AI that moves as far horizontally as necessary to reach the target,
* then as far vertically as necessary to reach the target. It is intended primarily as
* a demonstration of the various pieces of the program.
*
* @author Leonid Shamis
*/
public class StupidAI implements AIModule
{
/// Creates the path to the goal.
public List<Point> createPath(final TerrainMap map)
{
// Holds the resulting path
final ArrayList<Point> path = new ArrayList<Point>();
// Keep track of where we are and add the start point.
final Point CurrentPoint = map.getStartPoint();
path.add(new Point(CurrentPoint));
// Keep moving horizontally until we match the target.
while(map.getEndPoint().x != CurrentPoint.x)
{
if(map.getEndPoint().x > CurrentPoint.x)
++CurrentPoint.x;
else
--CurrentPoint.x;
path.add(new Point(CurrentPoint));
}
// Keep moving vertically until we match the target.
while(map.getEndPoint().y != CurrentPoint.y)
{
if(map.getEndPoint().y > CurrentPoint.y)
++CurrentPoint.y;
else
--CurrentPoint.y;
path.add(new Point(CurrentPoint));
}
// We're done! Hand it back.
return path;
}
}