I have the following code, which has performance issues due to having to convert a long Stream to an Array. The Board.getReachables() method returns a stream, so it would be much more performant to be able to do this while loop using streams. I am however, unsure as to how to proceed.
int counter = 1;
while (check(board, counter)) {
for (int i = 0; i < board.length; i++) {
if (board[i] == counter) {
for (Pos reach2 :
Board.getReachables(currentTurn.getBoard().pos(i),
currentTurn.getBoard())
.toArray(Pos[]::new)) {
if (board[currentTurn.getBoard().index(reach2)] == 0) {
board[currentTurn.getBoard().index(reach2)] = counter + 1;
}
}
}
}
counter++;
}