Advertisement
Guest User

Untitled

a guest
Aug 16th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.07 KB | None | 0 0
  1.   neighbors_number = 0
  2.     # |x|-|-|
  3.     # |x|c|-|
  4.     # |x|-|-|
  5.  
  6.     neighbors_number += 1 if in_bound?(row-1,column) && @board[row-1][column] && @board[row-1][column].alive
  7.     neighbors_number += 1 if in_bound?(row-1,column+1) && @board[row-1][column+1] && @board[row-1][column+1].alive
  8.     neighbors_number += 1 if in_bound?(row-1,column-1) && @board[row-1][column-1] && @board[row-1][column-1].alive
  9.     # |-|x|-|
  10.     # |-|c|-|
  11.     # |-|x|-|
  12.  
  13.     neighbors_number += 1 if in_bound?(row,column+1) && @board[row][column+1] && @board[row][column+1].alive
  14.     neighbors_number += 1 if in_bound?(row,column-1) && @board[row][column-1] && @board[row][column-1].alive
  15.     # |-|-|x|
  16.     # |-|c|x|
  17.     # |-|-|x|
  18.  
  19.     neighbors_number += 1 if in_bound?(row+1,column) && @board[row+1][column] && @board[row+1][column].alive
  20.     neighbors_number += 1 if in_bound?(row+1,column+1) && @board[row+1][column+1] && @board[row+1][column+1].alive
  21.     neighbors_number += 1 if in_bound?(row+1,column-1) && @board[row+1][column-1] && @board[row+1][column-1].alive
  22.  
  23.     neighbors_number
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement