Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement evaluator that reads weights from file and returns value
  • Loading branch information
sas12028 committed Apr 20, 2017
1 parent 5302555 commit fb63957
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/BaseEvaluator.java
@@ -0,0 +1,29 @@

public class BaseEvaluator implements Evaluator{

WeightsParser wp;
String file;
double[] weights;

public BaseEvaluator(String file){
this.wp = new WeightsParser();
this.file = file;
this.weights = this.wp.getWeights(file);
}

private double dot(double[] a1, double[] a2){
double res = 0;
for(int i = 0; i < a1.length; i++){
res += (a1[i] * a2[i]);
}
return res;
}

public double evaluate(CheckersGameState s, int player){
double[] params = s.getFeatures(player);
return dot(this.weights, params);
}


}

1 change: 1 addition & 0 deletions src/CheckersGameState.java
Expand Up @@ -5,4 +5,5 @@ List < Move > actions ();
CheckersGameState result ( Move x );
boolean isTerminal();
void printState ();
public double[] getFeatures(int player);
}

0 comments on commit fb63957

Please sign in to comment.