get la somme des gomoku cell aligned

This commit is contained in:
Cyprien111
2025-03-31 09:40:32 +02:00
parent 0140f1ed93
commit 7ba07d7498
2 changed files with 56 additions and 3 deletions

View File

@@ -1,7 +1,10 @@
import java.util.List;
import java.util.ArrayList; 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. */ /** The firstcell in the board, at the top left of the board. */
private GomokuCell firstCell; private GomokuCell firstCell;
/** The width of the GomokuBoard.*/ /** The width of the GomokuBoard.*/
@@ -72,6 +75,24 @@ public class GomokuBoard {
return output; return output;
} }
//-------------------Methods-------------------------
/**
* This method return a Map of number aligned cells.
* @param cell A cell.
* @return Map of number aligned cells.
*/
public Map<Cardinal, Integer> countAlignedCells(GomokuCell cell){
Map<Cardinal, Integer> map = new HashMap<>();
Map<Cardinal, Integer> 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-------------------------- //------------------Overides--------------------------

View File

@@ -1,4 +1,6 @@
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
/** /**
@@ -40,11 +42,41 @@ public class GomokuCell{
return neighbour; return neighbour;
} }
/**
* Return the number of same colored neighbours in all direction.
* @return The Map of neighbours.
*/
public Map<Cardinal, Integer> getSameColorNeighbour(){
Map<Cardinal, Integer> 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<Cardinal, Integer> 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.
* @return The state of the current cell with one Color. * @return The state of the current cell with one Color.
*/ */
public Color getSate(){ public Color getState(){
return this.state; return this.state;
} }