diff --git a/src/GomokuBoard.java b/src/GomokuBoard.java index 089ffc5..be17475 100644 --- a/src/GomokuBoard.java +++ b/src/GomokuBoard.java @@ -1,7 +1,10 @@ -import java.util.List; import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; -public class GomokuBoard { + +public class GomokuBoard{ /** The firstcell in the board, at the top left of the board. */ private GomokuCell firstCell; /** The width of the GomokuBoard.*/ @@ -72,6 +75,24 @@ public class GomokuBoard { return output; } + //-------------------Methods------------------------- + /** + * This method return a Map of number aligned cells. + * @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; + } //------------------Overides-------------------------- diff --git a/src/GomokuCell.java b/src/GomokuCell.java index 9c6cdb6..4b7c95d 100644 --- a/src/GomokuCell.java +++ b/src/GomokuCell.java @@ -1,4 +1,6 @@ import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.ExecutionException; /** @@ -39,12 +41,42 @@ public class GomokuCell{ public EnumMap getAllNeighbour(){ return neighbour; } + + /** + * Return the number of same colored neighbours in all direction. + * @return The Map of neighbours. + */ + public Map getSameColorNeighbour(){ + + Map map = new HashMap<>(); + map.put(Cardinal.N, 0); + map.put(Cardinal.W,0); + map.put(Cardinal.NW, 0); + map.put(Cardinal.SW, 0); + map.put(Cardinal.S, 0); + map.put(Cardinal.SE, 0); + map.put(Cardinal.E, 0); + map.put(Cardinal.NE, 0); + + Color color = this.getState(); + + for (Map.Entry entry : map.entrySet()) { + + GomokuCell actualcell = this; + while(this.getState() == actualcell.getNeighbour(entry.getKey()).getState()) + { + entry.setValue(entry.getValue()+1); + actualcell=actualcell.getNeighbour(entry.getKey()); + } + } + return map; + } /** * Return the state. * @return The state of the current cell with one Color. */ - public Color getSate(){ + public Color getState(){ return this.state; }