doc + getPlayableCells on gomokuBoard.
This commit is contained in:
@@ -1,15 +1,32 @@
|
|||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class GomokuBoard {
|
public class GomokuBoard {
|
||||||
private GomokuCell firstCell;
|
private GomokuCell firstCell;
|
||||||
private int boardWith;
|
private int boardWith;
|
||||||
private int bordHeight;
|
private int bordHeight;
|
||||||
|
|
||||||
|
//------------------Constructors--------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constructor take the width and the height to creat a board of gomoku.
|
||||||
|
* @param width Size of width.
|
||||||
|
* @param height Size of height.
|
||||||
|
*/
|
||||||
public GomokuBoard(int width, int height){
|
public GomokuBoard(int width, int height){
|
||||||
this.firstCell = new GomokuCell(Color.NIL);
|
this.firstCell = new GomokuCell(Color.NIL);
|
||||||
this.boardWith = width;
|
this.boardWith = width;
|
||||||
this.bordHeight = height;
|
this.bordHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------Gets--------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method get a cell in specific position in the board.
|
||||||
|
* @param x The position x on the board.
|
||||||
|
* @param y The position y on the board.
|
||||||
|
* @return GomokuCell in the position.
|
||||||
|
*/
|
||||||
public GomokuCell get(int x, int y){
|
public GomokuCell get(int x, int y){
|
||||||
int i = 0, j = 0;
|
int i = 0, j = 0;
|
||||||
GomokuCell act = this.firstCell;
|
GomokuCell act = this.firstCell;
|
||||||
@@ -24,4 +41,25 @@ public class GomokuBoard {
|
|||||||
return act;
|
return act;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method return a list of playable cell.
|
||||||
|
* @return List of GomokuCell wich all is playable.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public List<GomokuCell> getPlayableCells(){
|
||||||
|
List<GomokuCell> output = new ArrayList<>();
|
||||||
|
GomokuCell act = null;
|
||||||
|
for (int i = 0; i < this.boardWith; i++) {
|
||||||
|
for (int j = 0; j < this.bordHeight; j++) {
|
||||||
|
act = this.get(i,j);
|
||||||
|
if (act.isPlayable()){
|
||||||
|
output.add(act);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user