Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
evaluator number of pieces ratio
  • 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
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
Expand Up @@ -252,6 +252,27 @@ public class CheckersGameState3 implements CheckersGameState{
}
}

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 class CheckersGameState3 implements CheckersGameState{
System.out.print("\n");
}
}


2 changes: 1 addition & 1 deletion src/Evaluator.java
@@ -1,5 +1,5 @@
public interface Evaluator{

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

}
11 changes: 11 additions & 0 deletions src/Evaluator00.java
@@ -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.

0 comments on commit daa9992

Please sign in to comment.