-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPath.java
More file actions
69 lines (57 loc) · 1.35 KB
/
Path.java
File metadata and controls
69 lines (57 loc) · 1.35 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.ArrayList;
/**
* Used by the state machine agent to store a sequence of steps in the state
* machine environment. This is primarily used to store the best known path
* from the init state to the goal state.
*/
public class Path {
//list of steps taken along the path
private ArrayList<Character> path;
//Debugging Variable
private boolean debug = true;
/**
* initializes a path with an array of character
*
* @param generated
*/
public Path (ArrayList<Character> generated) {
path = new ArrayList<Character>();
for (int i = 0; i < generated.size(); i++) {
path.add(generated.get(i));
}
}
/**
* creates a copy of this object
*/
public Path copy() {
ArrayList<Character> createdCopy = new ArrayList<Character>();
for (int i = 0; i < path.size(); i++) {
createdCopy.add(path.get(i));
}
return new Path(createdCopy);
}
public int size() {
return path.size();
}
public char get(int index) {
return path.get(index);
}
public String toString() {
String result = "";
for (int i = 0; i < path.size(); i++) {
result += path.get(i);
}
return result;
}
public void printpath() {
if (debug) {
System.out.println("path: " + toString());
}
}
public void remove(int index) {
path.remove(index);
}
public void add(int index, char toAdd) {
path.add(index, toAdd);
}
}