Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change client so it takes time into account
  • Loading branch information
joesweeney committed May 1, 2017
1 parent 3dd9976 commit 25feb38
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/RmCheckersClient.java
Expand Up @@ -55,7 +55,7 @@ public class RmCheckersClient {
public RmCheckersClient(){
_socket = openSocket();
//e = new Evaluator00();
e = new BaseEvaluator("weights/beta.csv");
e = new BaseEvaluator("weights/beta-history.csv");
endEval = new EndEvaluator("../src/weights/endbeta.csv");
currentState = new CheckersGameState3();
user = _user1;
Expand Down Expand Up @@ -152,8 +152,10 @@ public class RmCheckersClient {
}

public void playGame(int player) {
int minPly = 8;
int maxPly = 12;
int minPly = 10;
int maxPly = 13;
boolean switched = false;
int time = 180;
try {
String msg = readAndEcho(); // initial message
if(player == 1) { // black
Expand All @@ -165,10 +167,14 @@ public class RmCheckersClient {
readAndEcho(); // move query
}
while(currentState.actions().size()>0){
if(currentState.isEndGame() && minPly < maxPly){
if(currentState.isEndGame() && !switched){
minPly = maxPly;
switched = true;
ai.eval = endEval;
}
if(time < 30) {
minPly = 8;
}
currentState.printState();
Move myMove = ai.minimax(currentState, minPly);
writeMessageAndEcho(myMove.toString());
Expand All @@ -188,6 +194,7 @@ public class RmCheckersClient {
break;
}
msg = readAndEcho(); // move query
time = parseTime(msg);
if(msg.contains("Result")) {
System.out.println("Done.");
break;
Expand All @@ -199,6 +206,12 @@ public class RmCheckersClient {
}
}

public int parseTime(String msg) {
String time = msg.substring(msg.indexOf("(")+1,msg.indexOf(")"));
return Integer.parseInt(time);
}


public String parseMove(String msg) {
return msg.substring(11,msg.length());
}
Expand Down

0 comments on commit 25feb38

Please sign in to comment.