diff --git a/src/GomokuBoard.java b/src/GomokuBoard.java index 086701e..4cba30f 100644 --- a/src/GomokuBoard.java +++ b/src/GomokuBoard.java @@ -2,6 +2,10 @@ 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. @@ -247,6 +251,35 @@ public class GomokuBoard { return map; } + public EnumMap countAlignedCellsv2(GomokuCell cell) { + + EnumMap map = new EnumMap<>(Cardinal.class); + + // Iterate over all different axes (4 directions) + for (int i = 0; i < 4; i++) { + Cardinal direction = Cardinal.fromInt(i); + int count = 1; // Start with the current cell + + // Check in the positive direction + GomokuCell nextCell = cell.getNeighbour(direction); + while (nextCell != null && nextCell.getState() == cell.getState()) { + count++; + nextCell = nextCell.getNeighbour(direction); + } + + // Check in the negative direction + nextCell = cell.getNeighbour(direction.inverse()); + while (nextCell != null && nextCell.getState() == cell.getState()) { + count++; + nextCell = nextCell.getNeighbour(direction.inverse()); + } + + map.put(direction, count); + } + + return map; + } + /** * This method return the number max of the aligned Cells. * @@ -255,10 +288,9 @@ public class GomokuBoard { */ public int countMax(Map mapColor) { - Map map = new HashMap<>(); int max = 0; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() > max) { + for (Map.Entry entry : mapColor.entrySet()) { + if(entry.getValue() > max){ max = entry.getValue(); } } diff --git a/src/GomokuGame.java b/src/GomokuGame.java index e30982d..789fc51 100644 --- a/src/GomokuGame.java +++ b/src/GomokuGame.java @@ -29,18 +29,14 @@ public class GomokuGame { GomokuGame(boolean renderer) { this.playRenderer = renderer; - this.board = new GomokuBoard(15, 15); - this.board.get(7, 7).setState(Color.BLACK); - this.player1 = new Human("un", Color.WHITE, 60); - this.player2 = new GomokuAI("deux", Color.BLACK, 60); } public static void main(String[] args) { - int sizeX = 0; - int sizeY = 0; - int nbToken = 0; - int nbJetonsAligne = 0; + int sizeX = 15; + int sizeY = 15; + int nbToken = 50; + int nbJetonsAligne = 5; boolean renderer = false; String path_a_load = ""; @@ -88,6 +84,10 @@ public class GomokuGame { } } GomokuGame g = new GomokuGame(false);// metre true ou fals si in veut l'affichage ou non + g.board = new GomokuBoard(sizeX, sizeY); + g.board.get(sizeX / 2, sizeY / 2).setState(Color.BLACK); + g.player1 = new Human("un", Color.WHITE, nbToken); + g.player2 = new GomokuAI("deux", Color.BLACK, nbToken - 1); System.out.println(g.board); // g.renderer.update(); g.startGame(); @@ -146,7 +146,7 @@ public class GomokuGame { } System.out.println(board.countMax(board.countAlignedCells(currentPlay))); if (NB_CELL_PLAY <= board.countMax(board.countAlignedCells(currentPlay))) { - this.renderer.updateStatus("Le joueur " + this.currentPlayer + "a gagné !"); + // this.renderer.updateStatus("Le joueur " + this.currentPlayer + "a gagné !"); return; } this.currentPlayer.tokens -= 1; @@ -154,7 +154,8 @@ public class GomokuGame { System.out.println(this.board); } - this.renderer.updateStatus("Match nul, il ne reste plus de jeton."); + // this.renderer.updateStatus("Match nul, il ne reste plus de jeton."); + System.out.println("Match nul, il ne reste plus de jeton"); return; }