Skip to content
Snippets Groups Projects
Select Git revision
  • 68f9954e0d867c3fd8991bed68ce5508bdfa8b09
  • main default protected
  • variant
3 results

Virus.java

Blame
  • Forked from LABOUREL Arnaud / Firefighter template
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Coordinate.java 1.17 KiB
    package datastruct;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public record Coordinate(int x, int y) {
    
        public static Coordinate of(int x, int y) {
            return new Coordinate(x,y);
        }
    
        public Coordinate left() {
            return new Coordinate(x-1,y);
        }
    
        public Coordinate right() {
            return new Coordinate(x+1,y);
        }
    
        public Coordinate above() {
            return new Coordinate(x,y+1);
        }
    
        public Coordinate below() {
            return new Coordinate(x, y-1);
        }
    
        public List<Coordinate> orthogonalNeighbours() {
            return List.of(
                    this.right(),
                    this.left(),
                    this.above(),
                    this.below()
            );
        }
    
        public List<Coordinate> diagonalNeighbours() {
            return List.of(
                    this.right().above(),
                    this.left().above(),
                    this.left().below(),
                    this.right().below()
            );
        }
    
        public List<Coordinate> orthodiagonalNeighbours() {
            List<Coordinate> neighbours = new ArrayList<>(this.orthogonalNeighbours());
            neighbours.addAll(this.diagonalNeighbours());
            return neighbours;
        }
    }