Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int Neighbours(int xCoordinate, int yCoordinate)
- {
- xCoordinate = xCoordinate -1;
- yCoordinate = yCoordinate -1;
- int NeighbourCounter =0;
- int incrementer = 0;
- int i1 =-1;
- int j1 =-1;
- int i2 =1;
- int j2 =1;
- if(yCoordinate==0)
- {
- j1=1;
- }
- if(xCoordinate==0)
- {
- i1=1;
- }
- if(yCoordinate+1==xLen)
- {
- j2=0;
- }
- if(xCoordinate+1==yLen)
- {
- i2=0;
- }
- for(int j=j1; j<=j2; j++)
- {
- if(j==0)
- {
- incrementer = 2;
- }
- else
- {
- incrementer = 1;
- }
- for(int i=i1; i<=i2; i+=incrementer)
- {
- if(CG[yCoordinate + j][xCoordinate + i] == 1)
- {
- NeighbourCounter++;
- }
- }
- }
- return NeighbourCounter;
- }
- enum Neighbor {
- North(0, 1),
- NorthEast(1, 1),
- East(1, 0);
- private final int dx;
- private final int dy;
- Neighbor(int dx, int dy) {
- this.dx = dx;
- this.dy = dy;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement