From 3acd568e4e6b9592a9a882281e3dd68017b280ee Mon Sep 17 00:00:00 2001 From: Dorian HAMDANI Date: Mon, 14 Apr 2025 09:26:31 +0200 Subject: [PATCH 1/2] Remove old countAlignedCells method --- src/GomokuBoard.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/GomokuBoard.java b/src/GomokuBoard.java index 4cba30f..2edc5a0 100644 --- a/src/GomokuBoard.java +++ b/src/GomokuBoard.java @@ -1,11 +1,7 @@ import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; -<<<<<<< HEAD -======= import java.util.EnumMap; ->>>>>>> 20e2f2eaec0f2988bef55ac30d3f0b3f123b171d /** * The board of the game Gomoku. @@ -238,20 +234,7 @@ public class GomokuBoard { * @param cell A cell. * @return Map of number aligned cells. */ - public Map countAlignedCells(GomokuCell cell) { - - Map map = new HashMap<>(); - Map mapColor = cell.getSameColorNeighbour(); - - map.put(Cardinal.N, mapColor.get(Cardinal.N) + mapColor.get(Cardinal.S) + 1); - map.put(Cardinal.W, mapColor.get(Cardinal.W) + mapColor.get(Cardinal.E) + 1); - map.put(Cardinal.NW, mapColor.get(Cardinal.NW) + mapColor.get(Cardinal.SE) + 1); - map.put(Cardinal.SW, mapColor.get(Cardinal.SW) + mapColor.get(Cardinal.NE) + 1); - - return map; - } - - public EnumMap countAlignedCellsv2(GomokuCell cell) { + public EnumMap countAlignedCells(GomokuCell cell) { EnumMap map = new EnumMap<>(Cardinal.class); From f8b5bf5d10cb6667827f9f4f17b910fb8d7ec5dd Mon Sep 17 00:00:00 2001 From: Dorian HAMDANI Date: Mon, 14 Apr 2025 09:33:49 +0200 Subject: [PATCH 2/2] Fix null pointer in chooseMove method --- src/Human.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Human.java b/src/Human.java index bf208c3..27c23ae 100644 --- a/src/Human.java +++ b/src/Human.java @@ -34,6 +34,7 @@ public class Human extends Player { int x = 0, y = 0; boolean pass = false; + GomokuCell cell = null; do { @@ -61,7 +62,8 @@ public class Human extends Player { } } while (!pass); - pass = board.get(x, y).isPlayable(); + cell = board.get(y, x); + pass = cell == null ? false : cell.isPlayable(); if (!pass) { System.out.println("Cette case n'est pas jouable !"); } @@ -69,6 +71,6 @@ public class Human extends Player { System.out.println("Vous avez saisi : " + x + ", " + y); - return board.get(x, y); + return cell; } }