Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. int GameOfLife::getNeighbourSum(unsigned int row, unsigned int col)
  2. {
  3.     int sum = 0;
  4.  
  5.     // I) Da li se nalazimo u prvom redu?
  6.     // II) Da li se nalazimo u poslednjem redu?
  7.     // III) Posto smo red proverili sa gornje i donje strane,ostale su samo pozicije levo i desno od tekuce
  8.  
  9.     if(row>0){           //proveravamo red iznad tekuceg pa zato ide row-1                                        
  10.         if(col>0) sum += m_buffer[(row-1)*m_width+col-1];             //  col-1 jer proveravamo gornjeg levog od tekuce pozicije
  11.         sum += m_buffer[(row-1)*m_width+col];                        
  12.         if(col<m_width-1) sum += m_buffer[(row-1)*m_width+col+1];    
  13.     }
  14.  
  15.  
  16.     if(row<m_height-1){                                            
  17.         if(col>0) sum += m_buffer[(row+1)*m_width+col-1];            
  18.         sum += m_buffer[(row+1)*m_width+col];                        
  19.         if(col<m_width-1) sum += m_buffer[(row+1)*m_height+col+1];    
  20.     }
  21.  
  22.  
  23.     if(col>0) sum += m_buffer[row*m_width+col-1];                     //levi element do tekuceg mozemo proveriti samo ako se on ne nalazi u nultoj koloni
  24.     if(col<m_width-1) sum += m_buffer[row*m_width+col+1];             //desni el. do tekuceg mozemo samo ako nije u poslednjoj koloni
  25.    
  26.  
  27.  
  28.     return sum;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement