Advertisement
Guest User

CellVector.java

a guest
May 17th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.72 KB | None | 0 0
  1. //  Sokoban brute solver.
  2. //  2021, May, B@R5uk
  3. //  Discussion: https://dxdy.ru/topic144781.html
  4.  
  5. public class CellVector {
  6.    
  7.     private static final CellVector [] neighbourShifts = {
  8.             new CellVector (-1,  0),
  9.             new CellVector ( 0, -1),
  10.             new CellVector ( 1,  0),
  11.             new CellVector ( 0,  1),
  12.             new CellVector (-1, -1),
  13.             new CellVector ( 1, -1),
  14.             new CellVector (-1,  1),
  15.             new CellVector ( 1,  1),
  16.     };
  17.    
  18.     private static final char [] moveLetter = {'l', 'u', 'r', 'd'};
  19.    
  20.     private static final int [] rearIndex = {2, 3, 0, 1, 7, 6, 5, 4};
  21.    
  22.     private int x, y;
  23.    
  24.     public CellVector (int ax, int ay) {
  25.         x = ax;
  26.         y = ay;
  27.     }
  28.    
  29.     public CellVector (int [] arg) {
  30.         x = arg [0];
  31.         y = arg [1];
  32.     }
  33.    
  34.     public CellVector sumWith (CellVector arg) {
  35.         return new CellVector (x + arg .x, y + arg .y);
  36.     }
  37.    
  38.     public CellVector neighbour (int index) {
  39.         return sumWith (neighbourShifts [index]);
  40.     }
  41.    
  42.     public CellVector rearNeighbour (int index) {
  43.         return sumWith (neighbourShifts [rearIndex [index]]);
  44.     }
  45.    
  46.     public static char moveLetter (int index) {
  47.         return moveLetter [index];
  48.     }
  49.    
  50.     public static char rearMoveLetter (int index) {
  51.         return moveLetter [rearIndex [index]];
  52.     }
  53.    
  54.     public int getCell (int [] [] array) {
  55.         return array [y] [x];
  56.     }
  57.    
  58.     public void setCell (int [] [] array, int value) {
  59.         array [y] [x] = value;
  60.     }
  61.    
  62.     public short getCell (short [] [] array) {
  63.         return array [y] [x];
  64.     }
  65.    
  66.     public void setCell (short [] [] array, short value) {
  67.         array [y] [x] = value;
  68.     }
  69.    
  70.     public boolean getCell (boolean [] [] array) {
  71.         return array [y] [x];
  72.     }
  73.    
  74.     public void setCell (boolean [] [] array, boolean value) {
  75.         array [y] [x] = value;
  76.     }
  77.    
  78.     public char getCell (char [] [] array) {
  79.         return array [y] [x];
  80.     }
  81.    
  82.     public void setCell (char [] [] array, char value) {
  83.         array [y] [x] = value;
  84.     }
  85.    
  86.     public int getX () {
  87.         return x;
  88.     }
  89.    
  90.     public int getY () {
  91.         return y;
  92.     }
  93.    
  94.     public boolean outOfBorder (CellVector border) {
  95.         if (0 > x || 0 > y) {
  96.             return true;
  97.         }
  98.         if (border .x <= x || border .y <= y) {
  99.             return true;
  100.         }
  101.         return false;
  102.     }
  103.    
  104.     public boolean equals (CellVector vector) {
  105.         return x == vector .x && y == vector .y;
  106.     }
  107.    
  108.     public String toString () {
  109.         return "(" + x + ", " + y + ")";
  110.     }
  111. }
  112.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement