- import java.util.ArrayList;
- /**
- * Created by Glizda on 10.05.2017.
- */
- public class Node
- {
- Coordinates myCoor;
- private Integer color;
- private int[] domain;
- private ArrayList<Coordinates> neighbourhood = new ArrayList<>();
- Node(int sideOfSquare, Coordinates coor)
- {
- color = null;
- myCoor = new Coordinates(coor.x, coor.y);
- setDomain(sideOfSquare);
- findNeighbours(sideOfSquare, coor);
- }
- public void setDomain(int sideOfSquare)
- {
- if(sideOfSquare % 2 == 0)
- domain = new int[2 * sideOfSquare];
- else domain = new int[(2 * sideOfSquare) + 1];
- for(int i : domain)
- {
- domain[i] = i;
- }
- }
- public void findNeighbours(int sideOfSquare, Coordinates coor)//uwaga, zapewnić idiotoodporność na rozmiar tablicy!
- {
- int x = coor.x;
- int y = coor.y;
- if(x == 0)
- {
- if(y == 0)
- {
- //left upper corner
- neighbourhood.add(new Coordinates(1, 0));
- neighbourhood.add(new Coordinates(0, 1));
- }
- if(y == sideOfSquare - 1)
- {
- //left lower corner
- neighbourhood.add(new Coordinates(0, sideOfSquare - 2));
- neighbourhood.add(new Coordinates(1, sideOfSquare - 1));
- }
- else
- {
- //left edge without corners
- neighbourhood.add(new Coordinates(x, y - 1));
- neighbourhood.add(new Coordinates(x + 1, y));
- neighbourhood.add(new Coordinates(x, y + 1));
- }
- }
- else if(x == sideOfSquare - 1)
- {
- if(y == sideOfSquare - 1)
- {
- //right upper corner
- neighbourhood.add(new Coordinates(sideOfSquare - 2, 0));
- neighbourhood.add(new Coordinates(sideOfSquare - 1, 1));
- }
- if(y == sideOfSquare - 1)
- {
- //right lower corner
- neighbourhood.add(new Coordinates(sideOfSquare - 1, sideOfSquare - 2));
- neighbourhood.add(new Coordinates(sideOfSquare - 2, sideOfSquare - 1));
- }
- else
- {
- //right edge without corners
- neighbourhood.add(new Coordinates(x, y - 1));
- neighbourhood.add(new Coordinates(x - 1, y));
- neighbourhood.add(new Coordinates(x, y + 1));
- }
- }
- else if(y == 0)
- {
- //upper edge without corners
- neighbourhood.add(new Coordinates(x, y + 1));
- neighbourhood.add(new Coordinates(x - 1, y));
- neighbourhood.add(new Coordinates(x, y + 1));
- }
- else if(y == sideOfSquare - 1)
- {
- //lower edge without corners
- neighbourhood.add(new Coordinates(x, y - 1));
- neighbourhood.add(new Coordinates(x - 1, y));
- neighbourhood.add(new Coordinates(x + 1, y));
- }
- else
- {
- //common nodes
- neighbourhood.add(new Coordinates(x, y - 1));
- neighbourhood.add(new Coordinates(x - 1, y));
- neighbourhood.add(new Coordinates(x + 1, y));
- neighbourhood.add(new Coordinates(x, y + 1));
- }
- }
- public Integer getColor()
- {
- return color;
- }
- public void setColor(Integer color)
- {
- this.color = color;
- }
- public int[] getDomain()
- {
- return domain;
- }
- public void setDomain(int[] domain)
- {
- this.domain = domain;
- }
- public ArrayList<Coordinates> getNeighbourhood()
- {
- return neighbourhood;
- }
- public void setNeighbourhood(ArrayList<Coordinates> neighbourhood)
- {
- this.neighbourhood = neighbourhood;
- }
- }