From c4c4a7ac76838247ea0fbeeb1d2da488b6385d28 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Sun, 28 Feb 2021 20:32:31 +0100 Subject: [PATCH] fixed previousSituation --- src/othello/Main.java | 1 + src/othello/MainStats.java | 1 + src/othello/State.java | 7 +++---- statsj1.txt | 33 +++++++++++++++++++++++++++++++++ statsj2.txt | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) diff --git a/src/othello/Main.java b/src/othello/Main.java index 1b14ff0..ffa11c8 100644 --- a/src/othello/Main.java +++ b/src/othello/Main.java @@ -19,6 +19,7 @@ public class Main { System.out.println("joueur 1: " + p1); System.out.println("joueur 2: " + p2); while(!game.isOver()) { + State.previousSituations.add(game.toString()); Player player = game.getCurrentPlayer(); System.out.println(game.toString()); game = game.play(player.play(game)); diff --git a/src/othello/MainStats.java b/src/othello/MainStats.java index 02e0f69..c0888ef 100644 --- a/src/othello/MainStats.java +++ b/src/othello/MainStats.java @@ -26,6 +26,7 @@ public class MainStats { PrintWriter writer2 = new PrintWriter("statsj2.txt"); while(!game.isOver()) { + State.previousSituations.add(game.toString()); Player player = game.getCurrentPlayer(); System.out.println(game.toString()); game = game.play(player.play(game)); diff --git a/src/othello/State.java b/src/othello/State.java index 523aebd..126d3ef 100644 --- a/src/othello/State.java +++ b/src/othello/State.java @@ -12,7 +12,7 @@ public class State { * been played, the game ends. * We only keep the 10 previous situations due to performances issues */ - public static List previousSituations = new LinkedList<>(); + public static List previousSituations = new LinkedList<>(); private final Player[][] board; private final Player player1; @@ -32,7 +32,7 @@ public class State { public boolean isOver() { return n1 == 0 || n2 == 0 || (getMove(player1).isEmpty() && getMove(player2).isEmpty()) - || previousSituations.contains(this.board); + || previousSituations.contains(toString()); } /** @@ -101,9 +101,8 @@ public class State { * @return a modified copy of the current situation */ public State play(Pair move) { - if(previousSituations.size() == 10) // on ne garde que les 10 dernieres situations par soucis de perfs + if(previousSituations.size() == 15) // on ne garde que les 10 dernieres situations par soucis de perfs previousSituations.remove(0); - previousSituations.add(board); State copy = this.copy(); boolean isJump = move.getLeft().isJump(move.getRight(), copy.board); copy.board[move.getRight().getY()][move.getRight().getX()] = copy.currentPlayer; diff --git a/statsj1.txt b/statsj1.txt index e69de29..2382333 100644 --- a/statsj1.txt +++ b/statsj1.txt @@ -0,0 +1,33 @@ +6 +16 +29 +46 +66 +98 +134 +166 +208 +233 +262 +291 +327 +382 +442 +497 +537 +590 +651 +680 +718 +758 +786 +804 +812 +828 +853 +863 +889 +918 +945 +974 +1003 diff --git a/statsj2.txt b/statsj2.txt index e69de29..8d020c1 100644 --- a/statsj2.txt +++ b/statsj2.txt @@ -0,0 +1,33 @@ +6 +16 +28 +39 +42 +52 +68 +82 +111 +139 +172 +208 +224 +234 +248 +261 +278 +281 +294 +318 +350 +387 +437 +480 +524 +557 +587 +632 +664 +689 +711 +733 +757