Skip to content
Permalink
Browse files

Fix isterminal and winner

  • Loading branch information
joesweeney committed Apr 22, 2017
1 parent 8ccf6e9 commit efbddb79f00f568c080e8ab4f435414809bd87d5
Showing with 56 additions and 13 deletions.
  1. +6 −10 src/CheckersGameState3.java
  2. +1 −3 src/Learn.java
  3. +49 −0 src/weights/alpha.csv
@@ -437,20 +437,16 @@ private boolean isSafe(int pos){
}

public boolean isTerminal(){
double rat = pieceRatio(this.player);
return (rat == 0 || rat == Double.POSITIVE_INFINITY);
return this.actions.size() == 0;
}

public int winner(){ // only call after isTerminal
for(int i = 0; i < board.length; i++){
if(board[i] == 1 || board[i] == 3){
return 1;
}
else if(board[i] == 2 || board[i] == 4){
return 2;
}
}
if(this.actions.size()==0){
return this.other(this.player);
}
else {
return 0;
}
}

public void printState(){
@@ -57,9 +57,7 @@ public static int play(CheckersGameState s, CheckersAI alpha, CheckersAI beta, L
current.printState();
moves++;
}
while(!current.isTerminal() && moves <= 50){
System.out.println("alphas moves:");
System.out.println(current.actions());
while(!current.isTerminal() && moves <= 100){
Move next = alpha.minimax(current, 7); // get alpha's move
le.addData(current.getFeatures(alpha.getPlayer()), next.getValue()); // add this moves data to the data set (the value of the state is stored in the move. there is probably a better way to do this)
current = current.result(next); // make the move
@@ -28,3 +28,52 @@
-2.1067562907318428E94, -4.468385728885715E92, -2.5123998504920498E93, -9.180443867939546E93, 6.345104944836925E93, 7.980054086800604E92
-7.81284835659837E94, -1.6166995865070447E93, -5.128336274216761E93, -1.9307596009148744E94, 9.615561351884508E93, 2.7628625498248885E93
-2.258434065448233E95, -4.623187033028576E93, -1.148760484999136E94, -4.5123076330934E94, 1.837401892192431E94, 7.685804031253954E93
-5.93270569518934E95, -1.2179885523035712E94, -2.6919664426146295E94, -1.116428094278299E95, 4.095229300948579E94, 2.0184988122242285E94
-1.5083902458448829E96, -3.1195729898408022E94, -6.5067624803416886E94, -2.8256191207802704E95, 9.855495591231279E94, 5.201710733519623E94
-3.8242743911695337E96, -7.949860758792979E94, -1.6165660460677667E95, -7.185734039156593E95, 2.4545302408971198E95, 1.3301856426905589E95
-9.710347537587419E96, -2.024247357048025E95, -4.0734592761910777E95, -1.8290286366781025E96, 6.19666756998271E95, 3.391717900088333E95
-2.4686967045252624E97, -5.153378848356433E95, -1.0327532584713221E96, -4.656039610313936E96, 1.5725034763761852E96, 8.638894292622773E95
-6.280485442306609E97, -1.3118694603100839E96, -2.624816580681474E96, -1.1852321057908368E97, 3.9981875187532214E96, 2.1994947182294275E96
-1.5982873120861247E98, -3.339430601538756E96, -6.677504323371107E96, -3.017025657708568E97, 1.0172912331194606E97, 5.599170386817502E96
-4.067953518620855E98, -8.500508964953238E96, -1.699360188302013E97, -7.679769206484304E97, 2.5890599597871548E97, 1.4252824405608781E97
-1.0354335156710992E99, -2.1637778592222754E97, -4.325287271447302E97, -1.9548535506069905E98, 6.589935504628375E97, 3.628019141785354E97
-2.635595922443393E99, -5.507799702571274E97, -1.1009460988448516E98, -4.975983130011972E98, 1.677396654612718E98, 9.234960700382757E97
-6.708719900343698E99, -1.4019824333242893E98, -2.802367657244242E98, -1.2666101920707552E99, 4.2696876344509503E98, 2.3507117623388797E98
-1.707663105600756E100, -3.5686713681435347E98, -7.133244158974422E98, -3.2240874329474916E99, 1.0868222993916483E99, 5.983610115894489E98
-4.346757503101084E100, -9.083858305412935E98, -1.8157252686776552E99, -8.206737502532644E99, 2.766443168016082E99, 1.523095170185315E99
4.316219773666513E101, -2.579287435201645E102, -1.679753806738501E99, -2.040760919574368E100, 2.733442258463015E100, 8.700736537906343E99
-4.925516098241543E102, -2.7046485274110696E102, 6.858614784170087E101, 6.855682021726422E101, -3.393649539620627E101, -4.83037215464781E100
-2.711955005060931E102, -2.829286549067488E102, 5.195223683393236E101, -3.899050165863116E101, -1.840230215550894E101, 1.1148547940845893E101
2.9473035520985574E102, -1.5726851129285975E102, -1.378476112589548E102, 1.6278965867121477E102, -8.771160181424325E101, -1.316961316188185E101
-8.874358106517808E118, 6.747854436457687E116, 5.063517528523918E117, 2.8297954815784326E117, -7.201943125524851E115, 1.4585479369364279E116
-7.986922295866027E118, 6.0730689928119186E116, 4.5571657756715244E117, 2.546815933420589E117, -6.481748812972357E115, 1.3126931432427856E116
-7.5873597016385285E118, 2.8241902009391522E116, 4.0420294984679027E117, 2.5020497909781708E117, 2.90258709204577E116, 9.911181743799115E115
-7.07875054336167E118, -9.980139535822082E115, 2.6787769361624997E117, 4.210358964111711E117, 1.0398383422908654E117, -2.281235201852E116
-7.7153423628577595E118, 4.567253963767239E116, 1.6398748117824353E117, 5.06594095461392E117, 6.918232282278952E116, -2.1970648333417053E116
-3.482631460346609E118, 1.9824703556209402E116, -8.46756127037961E116, -5.573666578602387E116, 1.477174367579954E117, 4.517163683870958E116
-3.2575414882591176E118, -1.0602511817586348E116, -6.577758303438208E116, 2.4703692438184636E116, 1.295253517613324E117, 2.6767740337760626E116
-1.0082546440767943E119, 1.0456027329676361E116, -1.3234425611172846E117, 5.66287032347044E116, 9.338453873036478E116, 7.742908347854508E116
-3.7111731583210614E119, 1.2399308679815333E120, -3.8895347211777505E117, 8.742781200941638E116, -2.5215536799319936E118, 1.7464970503088395E117
-3.341570600104462E119, 1.1156913578366783E120, -3.6513385036206194E117, 1.722451556439077E117, -2.2578950819920126E118, 1.4102393645321858E117
-3.318085875265668E120, 1.2566645585453988E120, -3.5342395903989245E119, -1.5431488416274842E119, 6.290548406190194E118, 6.1016765488921E118
-4.6890633592274224E120, 1.0451569035023765E120, -2.8349005937492217E119, -3.8883861577831265E118, 2.603629517885398E119, 2.030192581140221E118
-3.3905908217679644E135, 9.534903863544694E119, 6.164710585032644E134, 1.541177646258165E134, 3.0394671520610528E119, 1.1721239838620668E118
-1.9195213634880834E135, 3.755388776903841E132, 5.699542969927841E134, 9.667031385365135E133, -1.7420207117599852E133, -2.2695970102288078E132
-2.802107700970753E134, 8.433283564138338E131, 5.568732565353974E134, -2.501400302732303E134, -1.1251887511080571E133, 3.8688486199045417E133
-8.298137247545212E134, 8.016486283007024E132, 5.000142277222163E134, -2.0408919322518715E134, -3.202148120254839E133, 4.1095464373948417E133
-3.542025509192739E135, -3.007434677708521E134, 8.280041895735795E134, -4.896163017015126E133, 4.2099637466713336E134, -3.0268557810933743E133
-4.410867677082294E135, -3.00557041960234E134, 7.063234092507215E134, 2.938863312831542E134, 4.55600136644576E134, -8.025227475106195E133
-3.212360264555974E135, -3.051224956606415E134, 6.227288346185055E134, 2.890000646895986E134, 4.0796695203539476E134, -8.082283866166946E133
-3.3916249891631083E135, -2.971811650902598E134, 5.5246006466636514E134, 3.425567391161245E134, 3.568707368142004E134, -8.145050559434726E133
-2.394807564274314E135, -2.616851809779073E134, 4.771604885674543E134, 3.233523383188688E134, 2.4837846997087104E134, -6.557402698708495E133
-6.554228285573563E134, -2.3657837461924497E134, 4.212794906183832E134, 4.416224761346117E134, 1.7468682034923028E134, -9.544164020142754E133
-4.42889689382171E135, -2.965760895761052E134, 4.882532210857346E134, 3.996597235450047E134, 2.854609803129413E134, -6.747259300210892E133
-7.190943615461931E135, -3.632896618852873E134, 5.46630949356728E134, 4.7880976600812886E134, 3.917516836382274E134, -6.914170944151214E133
-8.973935613926772E135, -3.3104793834230842E134, 5.49953142791823E134, 5.620794284380505E134, 3.067863770227461E134, -4.997792808368401E133
-7.46896495704528E135, -2.7650774802278054E134, 4.693522488983142E134, 5.36462445435481E134, 1.489862799477855E134, -3.188110509036976E133
-1.0010040177462204E136, -3.1607591870443623E134, 4.964038792048077E134, 6.091259615758092E134, 2.415959628264406E134, -3.4353630885821064E133
-6.652379191110286E135, -2.2166788909601385E134, 8.776577333355429E134, 2.0259487885100192E134, 4.0909273590064106E134, -2.7427571227651354E133
-5.545531575894305E135, -2.130984573596715E134, 7.555531213089498E134, 1.2790077655760925E134, 3.954669292072566E134, -1.7190402577077208E133
-1.2047495154686113E136, -1.8504175009436753E134, 5.375464811573108E134, 9.86258987716117E147, -9.862589877160188E147, -1.7908189013988733E133
1.6056593769901746E148, -2.6053122234409257E146, 1.3357420879349493E147, 8.39609861617831E147, -8.486651805943722E147, -1.1582568252922155E146
-1.0759861533693697E149, -3.577604735742749E146, 1.0788855056770694E147, 1.2241218946211611E148, -7.144857131491475E147, 2.6560400611713813E146

0 comments on commit efbddb7

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