Skip to content
Permalink
Browse files

Change end game evaluator

  • Loading branch information
joesweeney committed Apr 30, 2017
1 parent b92429d commit 5480119a047481c42e0aef304f5d96e58d635c8a
@@ -14,7 +14,7 @@ public BaseEvaluator(String file){
this.weights = this.wp.getWeights(file);
}

private double dot(double[] a1, double[] a2){ // function for dot product
public 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]);
@@ -0,0 +1,31 @@

public class EndEvaluator extends LearningEvaluator {


public EndEvaluator(String file) {
super(file);
}

public double evaluate(CheckersGameState s, int player) {
double endVal = 100;

if(s.isTerminal()){
if(s.winner() == player){
return endVal; // what should this be?
}
else{
return -endVal; // assuming only positive evalutions
}
}
double[] params = s.getFeatures(player);
double value = dot(this.weights, params);
if(value > endVal) {
value = endVal - 1;
} else if(value < -endVal) {
value = -endVal + 1;
}
return value;

}

}
@@ -4,9 +4,9 @@
CheckersAI alpha;
CheckersAI beta;
LearningEvaluator le;
LearningEvaluator endle;
EndEvaluator endle;
BaseEvaluator be;
BaseEvaluator endbe;
EndEvaluator endbe;

public static void main(String[] args){
Learn learn = new Learn();
@@ -17,8 +17,8 @@ public Learn(){
beta = new CheckersAI(be, 2);
le = new LearningEvaluator("../src/weights/alpha.csv");
be = new BaseEvaluator("../src/weights/beta.csv");
endle = new LearningEvaluator("../src/weights/endalpha.csv");
endbe = new BaseEvaluator("../src/weights/endbeta.csv");
endle = new EndEvaluator("../src/weights/endalpha.csv");
endbe = new EndEvaluator("../src/weights/endbeta.csv");
}

// need to decide what to do if we are going on the wrong track
@@ -46,7 +46,7 @@ public void updateWeights(double alpha){
reg.setNoIntercept(true);
double[] new_weights = reg.estimateRegressionParameters(); //get parameters
for(double x: new_weights){
if(Math.abs(x) > 100000){
if(Math.abs(x) > 1000000000){
System.out.println("bad data, not updating");
return;
}
@@ -48,13 +48,15 @@
protected String _myColor;

public Evaluator e;
public Evaluator endEval;
public CheckersAI ai;
public CheckersGameState3 currentState;

public RmCheckersClient(){
_socket = openSocket();
//e = new Evaluator00();
e = new BaseEvaluator("weights/beta-hisotry.csv");
e = new BaseEvaluator("weights/beta.csv");
endEval = new EndEvaluator("../src/weights/endbeta.csv");
currentState = new CheckersGameState3();
user = _user1;
password = _password1;
@@ -63,7 +65,8 @@ public RmCheckersClient(){

public RmCheckersClient(int player, String opponent){
_socket = openSocket();
e = new BaseEvaluator("../src/weights/beta-history.csv");
e = new BaseEvaluator("../src/weights/beta.csv");
endEval = new EndEvaluator("../src/weights/endbeta.csv");
currentState = new CheckersGameState3();
user = player==1 ? _user1 : _user2;
password = player==1 ? _password1 : _password2;
@@ -150,7 +153,7 @@ public static void main(String[] argv){

public void playGame(int player) {
int minPly = 8;
int maxPly = 15;
int maxPly = 12;
try {
String msg = readAndEcho(); // initial message
if(player == 1) { // black
@@ -164,6 +167,7 @@ else if(player == 2) { // white
while(currentState.actions().size()>0){
if(currentState.isEndGame() && minPly < maxPly){
minPly = maxPly;
ai.eval = endEval;
}
currentState.printState();
Move myMove = ai.minimax(currentState, minPly);

Large diffs are not rendered by default.

@@ -1 +1,2 @@
100,-5,10,10,10,-10,25,10,10,15,15
619.1129910441612, 0.6895488937820718, -1.1199996022123313, -3.2553715234496643, -0.31578284477567353, 0.010016913799175443, 8.533324440209533, -9.020827934112503, -2.873788720831274, -1.327538739955206, 2.5452505773373453
@@ -832,3 +832,108 @@
35.965104398007746, -0.02942870491859534, 0.15814532874941442
36.49805409483658, -0.07193530912020332, 0.20425558836685967
36.76827173791227, -0.09359477914038225, 0.22594495667414363
32.46373907315618, 5.4767934804170775, 0.15672024123385814
37.108651121332876, 3.840699237797126, 0.16175066605601363
39.44080931643052, 3.460099844319622, 0.11852094134831342
42.32975593645219, 3.1154498741112437, 0.10910938985303208
44.57105274741802, 2.661717340941064, 0.07017230731840839
50.36368792448434, 1.3214569278139672, 0.031014228889030597
56.133827635619156, 1.1879192012453141, 0.3014706840181392
56.86441222691511, 1.06540548915741, 0.2934696753362602
54.56564497468886, 2.6113316969278104, 0.269624999589004
59.7613306303446, 0.18534471770945338, 1.01188888850925
66.246533117652, -3.673195409208473, 0.9657221761704988
66.42357560054944, -3.5167665020723415, 0.9013361561600779
70.15853641830697, -3.53839304933744, 1.7019122037280456
83.58922050951175, -6.371223469427493, 1.1736820542297726
86.93439990635915, -5.457698421256145, 0.3980825475100682
84.80688581392687, -4.405460733582206, 0.3291967857604745
83.84301381494777, -4.212171681349201, 0.32353623116233926
87.28612270818817, -4.543118227457056, 0.4164978259414996
92.58739412416296, -5.090726922019488, 0.08561558547071141
92.83913552284325, -4.048905582681879, 0.3345647565373743
92.27923680836821, -3.0629665615619377, 0.3368520612775433
92.12049273142392, -2.3783249866802922, 0.5891991750346847
93.26513366288049, -1.6785857143184169, 1.0245758354779844
94.91717912065245, -1.388370426788964, 0.8663959175847746
98.58729859837467, -2.511578574603652, 0.8070434116620587
98.4635740476306, -2.410315831573127, 0.7929639817732087
98.27496589069412, -2.320943848996322, 0.7837710798279535
98.33723066563968, -2.282285114617935, 0.7675694536047742
98.67277215526573, -2.2372189426230875, 0.6855272334852822
99.86392144996225, -2.1951568868309588, 0.5965791757596844
99.13078736806574, -1.5387629548962989, 0.531492058572022
88.00031267770774, 3.931138613122391, 0.4885975409135558
90.67278154023734, 3.702576248122938, 0.439904388638179
89.6712694024125, 3.091017771602629, 0.5595662983650832
90.69202061514001, 3.0381659611431866, 0.5033378584743172
92.9584359764052, 2.6650005934168517, 0.4764931726890201
92.6443565871982, 3.023551700362916, 0.5024810775039563
93.74227696046863, 3.332604617148288, 0.45014922201863516
94.6576758570299, 3.008228679552248, 0.40839195866032757
96.03611213152227, 2.5183687052542583, 0.3838634262429845
96.9022795190196, 2.3366831926598133, 0.35004207285402905
96.9902695289248, 2.5525771415681975, 0.32477737099535736
97.28909967310545, 2.480593743280424, 0.31954569703198904
97.58188956898019, 2.412507076751747, 0.31370183161116094
98.33723066563968, -2.282285114617935, 0.7675694536047742
98.67277215526573, -2.2372189426230875, 0.6855272334852822
99.86392144996225, -2.1951568868309588, 0.5965791757596844
99.13078736806574, -1.5387629548962989, 0.531492058572022
88.00031267770774, 3.931138613122391, 0.4885975409135558
90.83445954706109, 3.1803997729181237, 0.41272720991304335
93.53088560333273, 2.6972155504373614, 0.36109704012539384
96.35245685878776, 2.236389718101277, 0.3187892015928781
95.96485984103558, 2.3492284326189687, 0.2772479618979195
97.90209477203891, 2.1831754211214585, 0.24327185556785974
98.6071975324568, 2.0172384103018435, 0.2223762074116978
100.01780277465305, 1.8463621031534794, 0.19811393717186324
101.19226365776983, 1.5505696718872382, 0.18857890709423858
102.29789934690795, 2.7606955716939785, -0.38933660522053365
103.25677843542914, 2.58596453497574, -0.35222909074586595
103.55943307869279, 2.3445768832961873, -0.29350523956948976
103.30062121995454, 2.349945964215788, -0.24107931608915373
104.32707290304117, 2.1885088716806402, -0.21771462246955542
105.69684029378581, 2.3168391239058694, -0.2122734966410709
107.33480115027798, 1.907719717824034, -0.19122700971659223
133.9360758264308, -9.2768119316227, -0.486122942408543
151.90813887773217, -17.39640952861001, -0.6342895323295961
151.35518244970996, -16.901675936457327, -0.6164119663570183
150.2756568237227, -16.553251083993164, -0.5865550723062467
158.8641308348878, -20.463335119321286, -0.6580470540063482
98.33723066563968, -2.282285114617935, 0.7675694536047742
98.67277215526573, -2.2372189426230875, 0.6855272334852822
99.86392144996225, -2.1951568868309588, 0.5965791757596844
99.13078736806574, -1.5387629548962989, 0.531492058572022
88.00031267770774, 3.931138613122391, 0.4885975409135558
90.83445954706109, 3.1803997729181237, 0.41272720991304335
93.94736176279909, 2.894469026580463, 0.3578730333775517
95.89098482941559, 2.498604095039502, 0.3352294489518127
97.58974428219261, 2.088215935796854, 0.29734208422503405
99.36548829195553, 1.818906922262535, 0.27185732170912796
100.52665785681397, 1.5733399258721992, 0.2478230744879535
101.88273253537258, 1.2789146263189257, 0.2067784384339458
103.49022856071464, 1.1381234036925274, 0.12745387074363002
105.5800308357391, 0.9517662300300295, 0.0683078631151761
107.58685387049728, 0.7905493172327112, 0.014774791160030637
107.71684820531466, 0.8213930275759983, 0.017102415216978584
108.47068446499873, 0.5125039556690261, 0.016166001627790156
107.5118228773228, 0.7591808164799634, 0.029939491763027126
108.03299877649188, 0.6974779310987261, 0.028765910078854432
108.35209176471884, 0.6111330145313483, 0.028136115101001138
108.48968959385948, 0.5935022162631687, 0.026977825323793645
98.33723066563968, -2.282285114617935, 0.7675694536047742
98.67277215526573, -2.2372189426230875, 0.6855272334852822
99.86392144996225, -2.1951568868309588, 0.5965791757596844
99.13078736806574, -1.5387629548962989, 0.531492058572022
88.00031267770774, 3.931138613122391, 0.4885975409135558
90.69096866935517, 3.462786768640699, 0.44516356061173706
89.59220059054556, 2.878673581236927, 0.5620435282311668
91.13368794720357, 2.9034699051008506, 0.5080068642309672
91.72992175241433, 2.5471269501147766, 0.48013660835927974
93.8014904091882, 2.0609571586420654, 0.4319510214358731
96.6007968723152, 2.168055561040518, 0.3729552664972666
97.89366248357514, 1.6829106220246637, 0.33785856798841013
99.79778042309012, 1.123222307777273, 0.2782751471873174
100.93254564395056, 0.880063019927813, 0.23541241839389573
102.84649050153195, 0.8877763449444849, 0.20551109750514732
@@ -1,2 +1,3 @@
20, 4, -4
34.2499822651518, -0.76447480492721, -0.29487874028639965
98.33723066563968, -2.282285114617935, 0.7675694536047742

0 comments on commit 5480119

Please sign in to comment.
You can’t perform that action at this time.