Skip to content

Commit

Permalink
Montecarlo v1 done
Browse files Browse the repository at this point in the history
  • Loading branch information
vaquierm committed Mar 15, 2019
1 parent 4a529d5 commit 5b59106
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/student_player/CustomBoardFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ public static boolean movesEqual(PentagoMove move1, PentagoMove move2) {

public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {

PentagoBoardState b1 = new PentagoBoardState();
Constructor<PentagoBoardState> constructor = PentagoBoardState.class.getDeclaredConstructor();
constructor.setAccessible(true);

PentagoBoardState b1 = constructor.newInstance();
CustomPentagoBoardState b2 = new CustomPentagoBoardState();
PentagoMove move;

Expand All @@ -177,8 +180,6 @@ public static void main(String[] args) throws NoSuchMethodException, IllegalAcce
}


Constructor<PentagoBoardState> constructor = PentagoBoardState.class.getDeclaredConstructor();
constructor.setAccessible(true);
PentagoBoardState boardState = constructor.newInstance();

initNewGame(boardState);
Expand Down Expand Up @@ -211,13 +212,13 @@ public static void main(String[] args) throws NoSuchMethodException, IllegalAcce

System.out.println("Benchmark what runs faster");

boardState = new PentagoBoardState();
boardState = constructor.newInstance();
PentagoBoardState clone = null;

long start = System.currentTimeMillis();
for (int i = 0; i < 1000000; i ++) {
if (boardState.gameOver()) {
boardState = new PentagoBoardState();
boardState = constructor.newInstance();
}
else {
move = (PentagoMove) boardState.getRandomMove();
Expand All @@ -227,7 +228,7 @@ public static void main(String[] args) throws NoSuchMethodException, IllegalAcce
}
System.out.println("Cloning took : " + (System.currentTimeMillis() - start) + "ms");

boardState = new PentagoBoardState();
boardState = constructor.newInstance();
initNewGame(boardState);
move = (PentagoMove) boardState.getRandomMove();
boardState.processMove(move);
Expand Down
9 changes: 7 additions & 2 deletions src/student_player/MonteCarloTreeSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import pentago_swap.PentagoBoardState;
import pentago_swap.PentagoMove;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedList;
import java.util.List;

Expand Down Expand Up @@ -207,9 +209,12 @@ private static MonteCarloTreeNode findNodeWithMove(List<MonteCarloTreeNode> node



public static void main(String[] args) {
public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

PentagoBoardState boardState = new PentagoBoardState();
Constructor<PentagoBoardState> constructor = PentagoBoardState.class.getDeclaredConstructor();
constructor.setAccessible(true);

PentagoBoardState boardState = constructor.newInstance();

while (!boardState.gameOver()) {
PentagoMove move = (PentagoMove) boardState.getRandomMove();
Expand Down

0 comments on commit 5b59106

Please sign in to comment.