Skip to content

Commit

Permalink
trying new features and weights
Browse files Browse the repository at this point in the history
  • Loading branch information
sos13004 committed Apr 30, 2017
1 parent 606c0b0 commit 687dae3
Show file tree
Hide file tree
Showing 8 changed files with 1,544 additions and 361 deletions.
1 change: 1 addition & 0 deletions src/CheckersAI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import java.util.Arrays;

/* holds minimax code */
public class CheckersAI{


Expand Down
46 changes: 23 additions & 23 deletions src/CheckersGameState3.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import java.util.LinkedList;
import java.util.ArrayList;

/* Holds board state code for
identifying available moves,
resultant states, and board
attributes */
public class CheckersGameState3 implements CheckersGameState{

int player;
Expand Down Expand Up @@ -387,70 +391,66 @@ else if(player == 2){
return sum;
}

private boolean isCentral(int i){
return i == 10 || i == 11 || i == 14 || i == 15 || i == 19 || i == 20 || i == 23 || i ==24;
}

/* computes feature vector:
[0: piece-ratio,
1: loners, //toss?
2: safes, /toss?
3: 1*#pawns+ 2*#kings //toss?
1: loners,
2: safes,
3: bridge pattern
4: # of moveable pawns + 2*#of moveable kings
5: aggregate distance of all pawns to promotion line
6: promotion line opening
7: num defending pieces
8: num attacking pieces
8: num attacking pieces //toss?
9: central pieces
10: # pawns on diagonal + 2 * # kings on diagonal
11: ^ same but for the two smaller diagonals
12: bridge pattern TODO!!!
13: triangle pattern TODO
14: dog pattern TODO, also take out useless features
]
*/
private boolean king(int piece){
return (piece == 3 || piece == 4);
}

public double[] getFeatures(int player){
double[] features = new double[12];
double[] features = new double[11];
double total = 0.0;
double mypieces = 0.0;
for(int i = 0; i<this.board.length; i++){
if(i%9!=8){ //valid square
if(this.board[i] != 0 ) total+=2.0;
if(king(this.board[i])) total+=1.0; // pawn is 2, king is 3
if(this.board[i] != 0 ) total+=2.0; //not empty square
if(king(this.board[i])) total+=1.0; // pawn is 2, king is 3
/****my pieces (pawns and kings)*****/
if(myPiece(this.board[i], player)){
mypieces+=2.0;
if(king(this.board[i])) mypieces+=1.0; // pawn is 2, king is 3
if(isLoner(i)) features[1] +=1.0;
if(isSafe(i)) features[2] +=1.0;
/*****pawns features****/
/*****pawns features****/
if(this.board[i] == player){
features[3]+=1.0;
if(pawn_can_move(i)) features[4] += 1.0; //moveable pawns
features[5] += getDistance(i); //aggregate distance
if(i == 10 || i == 11 || i == 14 || i == 15 || i == 19 || i == 20 || i == 23 || i ==24){
if(isCentral(i)){
features[9] +=1.0; //central pawns
}
}
/****kings features****/
else if(this.board[i] == player+2){
features[3]+=2.0; //add weight to #pawns
if(king_can_move(i)) features[4] += 2.0; //add to aggregate distance of the kings
if(i == 10 || i == 11 || i == 14 || i == 15 || i == 19 || i == 20 || i == 23 || i ==24){
//central kings
if(king_can_move(i)) features[4] += 2.0;
if(isCentral(i)){
features[9] +=2.0;
}
}

}
}
}
features[0] = mypieces/total; //piece ratio
features[3] = bridge(player);
features[6] = promotionLineOpenings(player);
features[7] = numDefending(player);
features[8] = numAttacking(player);
features[10] = numOnMainDiag(player);
features[11] = numOnDiag1(player) + numOnDiag2(player);
features[10] = numOnMainDiag(player) + numOnDiag1(player) + numOnDiag2(player);
return features;
}

Expand Down Expand Up @@ -635,7 +635,7 @@ public double triangle(int player){
if(player==2){
if((this.board[33]==2 || this.board[33]==4)
&&(this.board[34]==2 || this.board[34]==4)
&&(this.board[24]==2 || this.board[24]==4))
&&(this.board[29]==2 || this.board[29]==4))
return 1.0;
}
if(player==1){
Expand All @@ -649,7 +649,7 @@ public double triangle(int player){
/* feature: Dog pattern*/
public double dog(int player){
if(player==1){
if((this.board[0]==1 || this.board[0]==3) && (this.board[4]==2||this.board[4]==2)){
if((this.board[0]==1 || this.board[0]==3) && (this.board[4]==2||this.board[4]==4)){
return 1.0;
}
}
Expand Down
670 changes: 338 additions & 332 deletions src/weights/alpha.csv

Large diffs are not rendered by default.

483 changes: 483 additions & 0 deletions src/weights/alpha_old.csv

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions src/weights/beta.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
100, -5, 20, 20, 25, 10, 10, 20, 20, 30, 30, 30
1826.0705815169833, 12.365435899024902, 23.58295734807525, 57.36085478839676, -2.7837546960554285, -3.19771921999838, 47.08341161233382, -6.285784896148243, -5.208189183870571, 11.51522034240242, -3.2044344558613282, -8.223757596191781
2799.5131611566608, -1.944668143409672, -6.07582076732366, -15.020040153383759, -0.38978985234549934, 5.102487827528079, 45.55197753549653, -7.961856581907668, -11.80237286431448, 1.2111733368909983, -3.063047124671007, 1.986352732898951
3076.7942658791485, -3.9944372443193163, 1.203168899836871, -43.693533074303204, 7.046836478795926, 6.925610791602731, 46.47422315356045, -9.112299466489374, -9.291575137674116, 1.3828658839626127, -25.545464757418088, -19.754054491277657
100,-5,10,10,10,-10,25,10,10,15,15
4 changes: 4 additions & 0 deletions src/weights/beta_old.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
100, -5, 20, 20, 25, 10, 10, 20, 20, 30, 30, 30
1826.0705815169833, 12.365435899024902, 23.58295734807525, 57.36085478839676, -2.7837546960554285, -3.19771921999838, 47.08341161233382, -6.285784896148243, -5.208189183870571, 11.51522034240242, -3.2044344558613282, -8.223757596191781
2799.5131611566608, -1.944668143409672, -6.07582076732366, -15.020040153383759, -0.38978985234549934, 5.102487827528079, 45.55197753549653, -7.961856581907668, -11.80237286431448, 1.2111733368909983, -3.063047124671007, 1.986352732898951
3076.7942658791485, -3.9944372443193163, 1.203168899836871, -43.693533074303204, 7.046836478795926, 6.925610791602731, 46.47422315356045, -9.112299466489374, -9.291575137674116, 1.3828658839626127, -25.545464757418088, -19.754054491277657
Loading

0 comments on commit 687dae3

Please sign in to comment.