import java.util.List;
import java.util.ArrayList;

public class GomokuBoard {
    /** The firstcell in the board, at the top left of the board. */
    private GomokuCell firstCell;
    /** The width of the GomokuBoard.*/
    private int boardWith;
    /**  The height of the GomokuBoard.*/
    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){
        this.firstCell = new GomokuCell(Color.NIL);
        this.boardWith = width;
        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){
        int i = 0, j = 0;
        GomokuCell act = this.firstCell;
        while (i != x && j != y){
            Cardinal c = Cardinal.SE;
            if (i < x) i++;
            else c = Cardinal.E;
            if (j < y) j++;
            else c = Cardinal.S;
            act = act.getNeighbour(c);
        }
        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;

    }
}
