-1

/** * Checks whether there exists a legal move for the piece. * If such a move exists, returns true and adds information to the piece. * @param colour - colour of the current player * @param cells - current information about the board * @return whether move is possible for the piece. If this is the case, then possible moves are stored in Piece. */

public boolean isLegal(CellStatus colour, Cell[][] cells){
        CellStatus opponent = colour == CellStatus.LIGHT ? CellStatus.DARK : CellStatus.LIGHT;
        int score = 0;
        ArrayList<DirectedMove> moves = new ArrayList<DirectedMove>();
        int[][] DIRS = {{-1,-1}, {-1,0}, {-1,1}, {0,1}, {0,-1}, {1,1}, {1,0}, {1,-1}};

        for (int[] dir : DIRS){
            int temp_score = 0;
            Cell cell = IsOnBoard(this.getRow() + dir[1], this.getColumn() + dir[1]) ? cells[this.getRow() + dir[0]][this.getColumn() + dir[1]] : null;
            if (cell != null
                    && cell.getValue() != CellStatus.EMPTY
                    && cell.getValue() == opponent) {
                while (true){
                    cell = IsOnBoard(cell.row + dir[0],cell.column + dir[1]) ? cells[cell.row + dir[0]][cell.column + dir[1]] :  null;
                    temp_score += 1;
                    if (!(cell != null
                            && cell.getValue() != CellStatus.EMPTY)){
                        if (cell.getValue() == colour) {
                            score += temp_score;
                            moves.add(new DirectedMove(cell, dir));
                         }
                    } else {
                        break;
                    }
                }
            }
        }

        Move move = new Move(moves, score);
        this.setMove(move);
        return !moves.isEmpty();
    }

error in : Cell cell = IsOnBoard(this.getRow() + dir[1], this.getColumn() + dir[1]) ? cells[this.getRow() + dir[0]][this.getColumn() + dir[1]] : null; I dont understand what the error means could be very helpful if you can explain to me. Thank you

user
  • 1

0 Answers0