diff --git a/src/student_player/CustomBoardFunctions.java b/src/student_player/CustomBoardFunctions.java index 72a97f7..ae763bf 100644 --- a/src/student_player/CustomBoardFunctions.java +++ b/src/student_player/CustomBoardFunctions.java @@ -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 constructor = PentagoBoardState.class.getDeclaredConstructor(); + constructor.setAccessible(true); + + PentagoBoardState b1 = constructor.newInstance(); CustomPentagoBoardState b2 = new CustomPentagoBoardState(); PentagoMove move; @@ -177,8 +180,6 @@ public static void main(String[] args) throws NoSuchMethodException, IllegalAcce } - Constructor constructor = PentagoBoardState.class.getDeclaredConstructor(); - constructor.setAccessible(true); PentagoBoardState boardState = constructor.newInstance(); initNewGame(boardState); @@ -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(); @@ -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); diff --git a/src/student_player/MonteCarloTreeSearch.java b/src/student_player/MonteCarloTreeSearch.java index 9ea2176..14445b8 100644 --- a/src/student_player/MonteCarloTreeSearch.java +++ b/src/student_player/MonteCarloTreeSearch.java @@ -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; @@ -207,9 +209,12 @@ private static MonteCarloTreeNode findNodeWithMove(List node - public static void main(String[] args) { + public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { - PentagoBoardState boardState = new PentagoBoardState(); + Constructor constructor = PentagoBoardState.class.getDeclaredConstructor(); + constructor.setAccessible(true); + + PentagoBoardState boardState = constructor.newInstance(); while (!boardState.gameOver()) { PentagoMove move = (PentagoMove) boardState.getRandomMove();