Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. public int Neighbours(int xCoordinate, int yCoordinate)
  2. {
  3. xCoordinate = xCoordinate -1;
  4. yCoordinate = yCoordinate -1;
  5. int NeighbourCounter =0;
  6. int incrementer = 0;
  7. int i1 =-1;
  8. int j1 =-1;
  9. int i2 =1;
  10. int j2 =1;
  11.  
  12. if(yCoordinate==0)
  13. {
  14. j1=1;
  15. }
  16.  
  17. if(xCoordinate==0)
  18. {
  19. i1=1;
  20. }
  21.  
  22. if(yCoordinate+1==xLen)
  23. {
  24. j2=0;
  25. }
  26.  
  27. if(xCoordinate+1==yLen)
  28. {
  29. i2=0;
  30. }
  31.  
  32. for(int j=j1; j<=j2; j++)
  33. {
  34. if(j==0)
  35. {
  36. incrementer = 2;
  37. }
  38. else
  39. {
  40. incrementer = 1;
  41. }
  42.  
  43. for(int i=i1; i<=i2; i+=incrementer)
  44. {
  45. if(CG[yCoordinate + j][xCoordinate + i] == 1)
  46. {
  47. NeighbourCounter++;
  48. }
  49. }
  50. }
  51. return NeighbourCounter;
  52. }
  53.  
  54. enum Neighbor {
  55. North(0, 1),
  56. NorthEast(1, 1),
  57. East(1, 0);
  58.  
  59. private final int dx;
  60. private final int dy;
  61.  
  62. Neighbor(int dx, int dy) {
  63. this.dx = dx;
  64. this.dy = dy;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement