-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathSensor.java
More file actions
41 lines (35 loc) · 714 Bytes
/
Copy pathSensor.java
File metadata and controls
41 lines (35 loc) · 714 Bytes
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
class Sensor{
protected GameSimulator game;
protected Robot robot;
Sensor(GameSimulator g, Robot r){
game = g;
robot = r;
}
protected GameSimulator getGameSimulator(){
return game;
}
protected Robot getRobot(){
return robot;
}
/*
Performs readings
*/
public float[] readValues(){
return null;
}
/*
Performs readings and returns the value at index
*/
public float readValue(int index){
return readValues()[index];
}
/**
* Applies random noise to a given value
*
* @return The new computed reading
*/
protected float getReadingAfterNoise(float reading, float noise) {
float addedNoise = (float) Math.random() * noise - noise / 2f;
return reading + addedNoise;
}
}