Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
end game features started
  • Loading branch information
sos13004 committed Apr 26, 2017
1 parent a5dd019 commit eed3140
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/CheckersGameState3.java
Expand Up @@ -430,6 +430,50 @@ public class CheckersGameState3 implements CheckersGameState{
features[11] = numOnDiag1(player) + numOnDiag2(player);
return features;
}

/* computes feature vector:
[0: piece-ratio,
1: # of moveable pawns + 2*#of moveable kings
2: num attacking pieces
3: central pieces
4: # pawns on diagonal + 2 * # kings on diagonal
5: ^ same but for the two smaller diagonals
]
*/
public double[] getEndGameFeatures(int player){
double[] features = new double[6];
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+=1.0;
/****my pieces (pawns and kings)*****/
if(myPiece(this.board[i], player)){
mypieces+=1.0;
/*****pawns features****/
if(this.board[i] == player){
if(pawn_can_move(i)) features[1] += 1.0; //moveable pawns
if(i == 10 || i == 11 || i == 14 || i == 15 || i == 19 || i == 20 || i == 23 || i ==24){
features[3] +=1.0; //central pawns
}
}
/****kings features****/
else if(this.board[i] == player+2){
if(king_can_move(i)) features[1] += 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){
features[3] +=2.0; //central kings
}
}
}
}
}
features[0] = mypieces/total; //piece ratio
features[2] = numAttacking(player);
features[4] = numOnMainDiag(player);
features[5] = numOnDiag1(player) + numOnDiag2(player);
return features;
}

/* number of pawns and kings on the long diagonal*/
public int numOnMainDiag(int player){
int count = 0;
Expand Down Expand Up @@ -540,8 +584,8 @@ public class CheckersGameState3 implements CheckersGameState{
return false;
}
/* feature: Dog pattern*/
public boolean isDog(int player){
public boolean isDog(int player){

return false;
}
public boolean isTerminal(){
Expand Down

0 comments on commit eed3140

Please sign in to comment.