Add expandable board mechanic, and add static array in Cardinal
This commit is contained in:
@@ -83,4 +83,7 @@ public enum Cardinal {
|
|||||||
public Cardinal rotate90CCW() {
|
public Cardinal rotate90CCW() {
|
||||||
return rotate(-2);
|
return rotate(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// North, South, East, West cardinals array
|
||||||
|
public static final Cardinal[] NS_EW = {N, S, E, W};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class ConsoleRenderer extends GomokuRenderer {
|
|||||||
System.out.println(horizontalLine);
|
System.out.println(horizontalLine);
|
||||||
}
|
}
|
||||||
System.out.print("x");
|
System.out.print("x");
|
||||||
for (int i = 0; i < height; i++) {
|
for (int i = 0; i < width; i++) {
|
||||||
if(i<10) {
|
if(i<10) {
|
||||||
System.out.print(" "+i+" ");
|
System.out.print(" "+i+" ");
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -147,6 +147,14 @@ public class GomokuGame {
|
|||||||
while (currentPlay == null) {
|
while (currentPlay == null) {
|
||||||
currentPlay = this.play(this.currentPlayer);
|
currentPlay = this.play(this.currentPlayer);
|
||||||
}
|
}
|
||||||
|
// Expand the board if one of the neighbours of the cell is null
|
||||||
|
// Only check for North, South, East and West neighbours
|
||||||
|
for (Cardinal cardinal : Cardinal.NS_EW) {
|
||||||
|
GomokuCell neighbour = currentPlay.getNeighbour(cardinal);
|
||||||
|
if (neighbour == null) {
|
||||||
|
this.board.expandBoard(cardinal);
|
||||||
|
}
|
||||||
|
}
|
||||||
System.out.println(board.countMax(board.countAlignedCells(currentPlay)));
|
System.out.println(board.countMax(board.countAlignedCells(currentPlay)));
|
||||||
if (NB_CELL_PLAY <= board.countMax(board.countAlignedCells(currentPlay))) {
|
if (NB_CELL_PLAY <= board.countMax(board.countAlignedCells(currentPlay))) {
|
||||||
System.out.println("Le joueur " + this.currentPlayer + " a gagné !");
|
System.out.println("Le joueur " + this.currentPlayer + " a gagné !");
|
||||||
|
|||||||
Reference in New Issue
Block a user