Cześć,
w jaki sposób mógłbym zmienić funkcję poniżej żeby nie powielać kodu ?
bool Matrix::update(uint8_t row, uint8_t col)
{
Cell *curr;
bool changed = false;
auto &root = _matrix[row][col];
u8_set temp;
for(uint8_t r = 0; r < MATRIX_ROWS; ++r)
{
if(r == row)
continue;
curr = &_matrix[r][col];
if(curr->get_value() > 0)
{
changed = root.cannot_have(curr->get_value()) ? true : changed;
if(changed) return true;
temp = {0};
}
else
{
if(temp.size() < curr->size())
temp = curr->get_possible_values();
}
}
if(root.get_possible_values().size() > temp.size())
changed = root.cannot_have(temp) ? true : changed;
temp = {0};
for(uint8_t c = 0; c < MATRIX_COLS; ++c)
{
if(c == col)
continue;
curr = &_matrix[row][c];
if(curr->get_value() > 0)
{
changed = root.cannot_have(curr->get_value()) ? true : changed;
if(changed) return true;
temp = {0};
}
else
{
if(temp.size() < curr->get_possible_values().size())
temp = curr->get_possible_values();
}
}
if(root.get_possible_values().size() > temp.size())
changed = root.cannot_have(temp) ? true : changed;
return changed;
}