get la somme des gomoku cell aligned
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class GomokuBoard{
|
||||
/** The firstcell in the board, at the top left of the board. */
|
||||
@@ -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<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--------------------------
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
@@ -40,11 +42,41 @@ public class GomokuCell{
|
||||
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 of the current cell with one Color.
|
||||
*/
|
||||
public Color getSate(){
|
||||
public Color getState(){
|
||||
return this.state;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user