Skip to content

Commit

Permalink
evaluator number of pieces ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
sos13004 committed Apr 15, 2017
1 parent a1d0377 commit daa9992
Show file tree
Hide file tree
Showing 16 changed files with 435 additions and 405 deletions.
Binary file added resources/boardstaterep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
23 changes: 21 additions & 2 deletions src/CheckersGameState3.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,27 @@ private int other(int player){
}
}

public boolean myPiece(int i){
if(this.player == 1 && i == 1 || this.player == 1 && i == 3) //black
return true;
if(this.player == 0 && i == 2 || this.player == 0 && i == 4) //white
return true;
else return false;
}

public double pieceRatio(){
double total = 0.0;
double mypieces = 0.0;
for(int i = 0; i<this.board.length; i++){
if(i%9!=8){
if(this.board[i] != 0 ) total+=1.0;
if(myPiece(this.board[i])) mypieces+=1.0;
}
}
//System.out.println("" + mypieces);
return mypieces/total;
}

public void printState(){
boolean leading = false;
int printed = 0;
Expand All @@ -274,5 +295,3 @@ public void printState(){
System.out.print("\n");
}
}


2 changes: 1 addition & 1 deletion src/Evaluator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public interface Evaluator{

int evaluate(CheckersGameState s);
double evaluate(CheckersGameState s);

}
11 changes: 11 additions & 0 deletions src/Evaluator00.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* Evaluates a given board state based on the ratio of pieces
the player has out of the total alive pieces on the board */

public class Evaluator00 implements Evaluator {

public double evaluate(CheckersGameState s){
CheckersGameState3 gs = (CheckersGameState3) s;
return gs.pieceRatio();
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit daa9992

Please sign in to comment.