From abdb473669544dd4a22f93d9ab55f36dd4f13c47 Mon Sep 17 00:00:00 2001 From: Dorian HAMDANI Date: Mon, 7 Apr 2025 10:28:32 +0200 Subject: [PATCH 1/4] Fix get() method in GomokuBoard and save() method in GomokuGame --- src/GomokuBoard.java | 2 ++ src/GomokuGame.java | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GomokuBoard.java b/src/GomokuBoard.java index 6f469be..f8d7ecd 100644 --- a/src/GomokuBoard.java +++ b/src/GomokuBoard.java @@ -129,6 +129,8 @@ public class GomokuBoard{ * @return GomokuCell in the position. */ public GomokuCell get(int x, int y){ + if (x < 0 || x >= this.boardWidth) return null; + if (y < 0 || y >= this.boardHeight) return null; int i = 0, j = 0; GomokuCell act = this.firstCell; while (i != x || j != y){ diff --git a/src/GomokuGame.java b/src/GomokuGame.java index 3d100cf..4798cfe 100644 --- a/src/GomokuGame.java +++ b/src/GomokuGame.java @@ -147,13 +147,13 @@ public class GomokuGame { // Write the board for (int i = 0; i < this.getBoard().getHeight(); ++i) { for (int j = 0; j < this.getBoard().getWidth(); ++j) { - char c = ' '; + char c; switch (board.get(i, j).getState()) { case BLACK: c = 'X'; break; case WHITE: - + c = 'O'; break; case NIL: c = '.'; From 1fd94a0828f30f843b390344d31978d7b21b7279 Mon Sep 17 00:00:00 2001 From: Cyprien111 <105004796+Cyprien111@users.noreply.github.com> Date: Mon, 7 Apr 2025 10:39:10 +0200 Subject: [PATCH 2/4] MAIN CHANGE --- src/GomokuGame.java | 50 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/GomokuGame.java b/src/GomokuGame.java index f44fed5..8c93b34 100644 --- a/src/GomokuGame.java +++ b/src/GomokuGame.java @@ -25,14 +25,62 @@ public class GomokuGame { int nbTokens1, nbTokens2; public static void main(String[] args) { + + GomokuGame g = new GomokuGame();//metre true ou fals si in veut l'affichage ou non + + int sizeX = 0; + int sizeY = 0; + int nbToken = 0; + int nbJetonsAligne = 0; + + for (int i = 0; i < args.length; i++) { + switch (args[i]) { + case "--save": + if (i + 1 < args.length) { + //load(g.load(Path.of(".cache/test.dat"))); + } + break; + + case "--size": + if (i + 2 < args.length) { + sizeX = Integer.parseInt(args[++i]); + sizeY = Integer.parseInt(args[++i]); + } + break; + + case "--nbToken": + if (i + 1 < args.length) { + nbToken = Integer.parseInt(args[++i]); + } + break; + + case "--nbTokenToWin": + if (i + 1 < args.length) { + nbJetonsAligne = Integer.parseInt(args[++i]); + } + break; + + case "--renderer": + if (i + 1 < args.length) { + //renderer = args[++i]; + } + break; + + default: + System.out.println("Option inconnue : " + args[i]); + break; + } + } + // Test - GomokuGame g = new GomokuGame(); System.out.println(g.load(Path.of(".cache/test.dat"))); g.renderer = new ConsoleRenderer(); g.renderer.init(g); g.renderer.update(); g.board.expandBoard(Cardinal.SE); g.renderer.update(); + + } public void newGame(boolean bot, String name1, String name2) { From 3769b68be259e847ccaba47e139b831efe887965 Mon Sep 17 00:00:00 2001 From: Cyprien111 <105004796+Cyprien111@users.noreply.github.com> Date: Mon, 7 Apr 2025 10:40:02 +0200 Subject: [PATCH 3/4] invalid --- src/GomokuGame.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GomokuGame.java b/src/GomokuGame.java index fbf1dcf..c8da8be 100644 --- a/src/GomokuGame.java +++ b/src/GomokuGame.java @@ -70,7 +70,7 @@ public class GomokuGame { break; default: - System.out.println("Option inconnue : " + args[i]); + System.out.println("Invalid option : " + args[i]); break; } } From b626d3a3711c006278a1e090362e9450a03bf5b8 Mon Sep 17 00:00:00 2001 From: Cyprien111 <105004796+Cyprien111@users.noreply.github.com> Date: Mon, 7 Apr 2025 10:51:04 +0200 Subject: [PATCH 4/4] correction boolean --- src/GomokuGame.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/GomokuGame.java b/src/GomokuGame.java index c8da8be..ccda391 100644 --- a/src/GomokuGame.java +++ b/src/GomokuGame.java @@ -35,6 +35,8 @@ public class GomokuGame { int sizeY = 0; int nbToken = 0; int nbJetonsAligne = 0; + boolean renderer = false; + for (int i = 0; i < args.length; i++) { switch (args[i]) { @@ -65,7 +67,13 @@ public class GomokuGame { case "--renderer": if (i + 1 < args.length) { - //renderer = args[++i]; + String bool = args[++i]; + if(bool=="true"){ + renderer = true; + } + else { + renderer=false; + } } break;