Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
CheckersAI/src/BaseEvaluator.java
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (34 sloc)
1.13 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BaseEvaluator implements Evaluator{ | |
// meant for beta to use | |
// when beta should use alpha's weights, have alpha commit to beta.csv and then call refreshWeights() | |
protected WeightsParser wp; | |
protected String file; | |
protected 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){ // function for dot product | |
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){ | |
if(s.isTerminal()){ | |
if(s.winner() == player){ | |
return 1000; // what should this be? | |
} | |
else{ | |
return 0; // assuming only positive evalutions | |
} | |
} | |
double[] params = s.getFeatures(player); | |
return dot(this.weights, params); | |
} | |
public void refreshWeights(){ | |
this.weights = this.wp.getWeights(this.file); | |
} | |
} |