-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPercept.java
164 lines (149 loc) · 4.16 KB
/
Percept.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import java.awt.Color;
/**
* Class for representing the way one agent appears to another
*
* @author Matthew Stone
* @version 1.0
*
*/
public class Percept {
/**
* A percept shows an agent as being of a particular category.
* This need not match an agent's class, for example if an
* agent is camouflaged, but could. Add additional values
* here as you extend the world to include new kinds of things.
*/
static enum ObjectCategory {
/** A light source */
LIGHT,
/** A peaceful creature */
BOID,
/** An agressive creature */
PREDATOR,
/** A dead creature */
CORPSE,
/** An inert object that must be avoided */
OBSTACLE;
}
/** What was seen */
private ObjectCategory objectCategory;
/** What color it had */
private Color color;
/** How far perceived agent was */
private double distance;
/** Where perceived agent is relative to you (0 is forward, positive angle is to the right) */
private double angle;
/** What direction is perceived agent facing (0 is the same as you, etc...) */
private double orientation;
/** How fast is perceived agent going (negative if it's going in reverse) */
private double speed;
/**
* Constructor for percept object
*
* @param c what was seen
* @param dis how far perceived agent was
* @param a where perceived agent is relative to you
* @param h what direction perceived agent is facing
* @param s how fast perceived agent is going
*/
public Percept(ObjectCategory c, Color f, double dis, double a, double h, double s) {
objectCategory = c;
color = f;
distance = dis;
angle = a;
orientation = h;
speed = s;
}
/**
* Accessor
* @return what was seen
*/
public ObjectCategory getObjectCategory() {
return objectCategory;
}
/**
* Accessor
* @return color of was seen
*/
public Color getColor() {
return color;
}
/**
* Accessor
* @return how far perceived agent was
*/
public double getDistance() {
return distance;
}
/**
* Accessor
* @return where perceived agent is relative to you
*/
public double getAngle() {
return angle;
}
/**
* Accessor
* @return what direction perceived agent is facing
*/
public double getOrientation() {
return orientation;
}
/**
* Acessor
* @return how fast perceived agent is going
*/
public double getSpeed() {
return speed;
}
/**
* A measure is a way of associating a cost with
* each percept. That allows for general methods
* that go through a list of percepts and find
* the one with the least cost. The notion of
* cost involved can vary with the capabilities
* and interests of the agents getting the percept.
*/
static interface Measure {
public double cost(Percept p);
}
/**
* A percept measure object where
* close objects have the lowest cost.
*/
static Measure distanceMeasure = new Measure() {
public double cost(Percept p) {
return p.getDistance();
}
};
/**
* A percept measure object where
* objects with a high red component
* to their color have the lowest cost.
*/
static Measure redMeasure = new Measure() {
public double cost(Percept p) {
return -p.getColor().getRed();
}
};
/**
* A percept measure object where
* objects with a high green component
* to their color have the lowest cost.
*/
static Measure greenMeasure = new Measure() {
public double cost(Percept p) {
return -p.getColor().getGreen();
}
};
/**
* A percept measure object where
* objects with a high blue component
* to their color have the lowest cost.
*/
static Measure blueMeasure = new Measure() {
public double cost(Percept p) {
return -p.getColor().getBlue();
}
};
}