From abdb473669544dd4a22f93d9ab55f36dd4f13c47 Mon Sep 17 00:00:00 2001 From: Dorian HAMDANI Date: Mon, 7 Apr 2025 10:28:32 +0200 Subject: [PATCH] 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 = '.';