-
Notifications
You must be signed in to change notification settings - Fork 0
/
Slave.java
34 lines (30 loc) · 1004 Bytes
/
Slave.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
/**
* Created by john on 3/31/2016.
*/
import java.util.ArrayList;
import java.util.concurrent.Callable;
public class Slave implements Callable <Float> {
private ImprovedState currentState;
private int move;
private ArrayList<FeatureWeightPair> features;
public Slave(ImprovedState currentState, int move, ArrayList<FeatureWeightPair> features) {
this.currentState = currentState;
this.features = features;
this.move = move;
}
private float evaluate(ImprovedState s) {
if(s.hasLost())
return Float.NEGATIVE_INFINITY;
float sum = 0.0f;
for (int i=0; i<features.size(); i++) {
FeatureWeightPair f = features.get(i);
sum += f.feature.evaluate(s)*f.weight;
}
return sum;
}
public Float call() {
// System.out.println("Slave running: " + move);
ImprovedState resultingState = currentState.tryMove(move);
return evaluate(resultingState);
}
}