Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int GameOfLife::getNeighbourSum(unsigned int row, unsigned int col)
- {
- int sum = 0;
- /*
- ---------------------------------------> col ili m_width
- 0 1 2 3 4 5 6 7 8
- r | 0 I II II II II II II II III
- o | 1 IV V V V V V V V VI
- w | 2 IV V V V V V V V VI
- | 3 IV V V V V V V V VI
- | 4 IV V V V V V V V VI
- | 5 IV V V V V V V V VI
- | 6 IV V V V V V V V VI
- | 7 IV V V V V V V V VI
- v 8 VII VIII VIII VIII VIII VIII VIII VIII IX
- */
- // TODO: PLACE CODE HERE
- // I
- if(row == 0 && col == 0){
- if (m_buffer[row * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[(row + 1) * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[(row + 1) * m_width + col] == 1){ sum +=1; }
- }
- // II
- if(row == 0 && col != 0 && col != m_width - 1){
- if (m_buffer[row * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[(row + 1) * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[(row + 1) * m_width + col] == 1){ sum +=1; }
- if (m_buffer[(row + 1) * m_width + (col - 1)] == 1){ sum +=1; }
- if (m_buffer[row * m_width + (col - 1)] == 1){ sum += 1; }
- }
- // III
- if(row == 0 && col == m_width - 1){
- if (m_buffer[(row + 1) * m_width + col] == 1){ sum +=1; }
- if (m_buffer[(row + 1) * m_width + (col - 1)] == 1){ sum +=1; }
- if (m_buffer[row * m_width + (col - 1)] == 1){ sum += 1; }
- }
- // IV
- if(col == 0 && row != 0 && row != m_height - 1){
- if (m_buffer[(row - 1) * m_width + col] == 1){ sum +=1; }
- if (m_buffer[(row - 1) * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[row * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[(row + 1) * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[(row + 1) * m_width + col] == 1){ sum +=1; }
- }
- // V
- if(row != 0 && row != m_height - 1 &* col != 0 && col != m_width - 1){
- if (m_buffer[(row - 1) * m_width + col] == 1){ sum +=1; }
- if (m_buffer[(row - 1) * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[row * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[(row + 1) * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[(row + 1) * m_width + col] == 1){ sum +=1; }
- if (m_buffer[(row + 1) * m_width + (col - 1)] == 1){ sum += 1; }
- if (m_buffer[row * m_width + (col - 1)] == 1){ sum += 1; }
- if (m_buffer[(row - 1) * m_width + (col - 1)] == 1){ sum += 1; }
- }
- // VI
- if(col == m_width - 1 && row != 0 && row != m_height - 1){
- if (m_buffer[(row + 1) * m_width + col] == 1){ sum +=1; }
- if (m_buffer[(row + 1) * m_width + (col - 1)] == 1){ sum +=1; }
- if (m_buffer[row * m_width + (col - 1)] == 1){ sum += 1; }
- if (m_buffer[(row - 1) * m_width + (col - 1)] == 1){ sum +=1; }
- if (m_buffer[(row - 1) * m_width + col] == 1){ sum +=1; }
- }
- // VII
- if( row == m_height - 1 && col == 0){
- if (m_buffer[(row - 1) * m_width + col] == 1){ sum +=1; }
- if (m_buffer[(row - 1) * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[row * m_width + (col + 1)] == 1){ sum += 1; }
- }
- // VIII
- if(row == m_height - 1 && col != 0 && col != m_width - 1){
- if (m_buffer[row * m_width + (col - 1)] == 1){ sum += 1; }
- if (m_buffer[(row - 1) * m_width + (col - 1)] == 1){ sum += 1; }
- if (m_buffer[(row - 1) * m_width + col] == 1){ sum +=1; }
- if (m_buffer[(row - 1) * m_width + (col + 1)] == 1){ sum += 1; }
- if (m_buffer[row * m_width + (col + 1)] == 1){ sum += 1; }
- }
- // IX
- if(row == m_height - 1 && col == m_width - 1){
- if (m_buffer[row * m_width + (col - 1)] == 1){ sum += 1; }
- if (m_buffer[(row - 1) * m_width + (col - 1)] == 1){ sum +=1; }
- if (m_buffer[(row - 1) * m_width + col] == 1){ sum +=1; }
- }
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement