40 if (rows == 0 || cols == 0) {
41 throw std::invalid_argument(
"BestNeighborSelection requires non-zero grid dimensions.");
44 const std::size_t up = (row == 0) ? rows - 1 : row - 1;
45 const std::size_t down = (row + 1) % rows;
46 const std::size_t left = (col == 0) ? cols - 1 : col - 1;
47 const std::size_t right = (col + 1) % cols;
51 const std::size_t candidates[] = {
57 for (
const std::size_t idx : candidates) {