Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sokoban puzzles auto generator
- // https://dxdy.ru/post1541620.html#p1541620
- // 2021 dec B@R5uk
- public class CellVector {
- private static final CellVector [] neighbourShifts = {
- new CellVector (-1, 0),
- new CellVector ( 0, -1),
- new CellVector ( 1, 0),
- new CellVector ( 0, 1),
- new CellVector (-1, -1),
- new CellVector ( 1, -1),
- new CellVector (-1, 1),
- new CellVector ( 1, 1),
- };
- private static final char [] moveLetter = {'l', 'u', 'r', 'd'};
- private static final char [] moveUpperLetter = {'L', 'U', 'R', 'D'};
- private static final int [] rearIndex = {2, 3, 0, 1, 7, 6, 5, 4};
- private int x, y;
- public CellVector (int ax, int ay) {
- x = ax;
- y = ay;
- }
- public CellVector (int [] arg) {
- x = arg [0];
- y = arg [1];
- }
- public CellVector sumWith (CellVector arg) {
- return new CellVector (x + arg .x, y + arg .y);
- }
- public CellVector neighbour (int index) {
- return sumWith (neighbourShifts [index]);
- }
- public CellVector rearNeighbour (int index) {
- return sumWith (neighbourShifts [rearIndex [index]]);
- }
- public static char moveLetter (int index) {
- return moveLetter [index];
- }
- public static char moveUpperLetter (int index) {
- return moveUpperLetter [index];
- }
- public static int reverseMove (int index) {
- return rearIndex [index];
- }
- public static char reverseMoveLetter (int index) {
- return moveLetter [rearIndex [index]];
- }
- public static char reverseMoveUpperLetter (int index) {
- return moveUpperLetter [rearIndex [index]];
- }
- public int getCell (int [] [] array) {
- return array [y] [x];
- }
- public void setCell (int [] [] array, int value) {
- array [y] [x] = value;
- }
- public short getCell (short [] [] array) {
- return array [y] [x];
- }
- public void setCell (short [] [] array, short value) {
- array [y] [x] = value;
- }
- public boolean getCell (boolean [] [] array) {
- return array [y] [x];
- }
- public void setCell (boolean [] [] array, boolean value) {
- array [y] [x] = value;
- }
- public char getCell (char [] [] array) {
- return array [y] [x];
- }
- public void setCell (char [] [] array, char value) {
- array [y] [x] = value;
- }
- public int getX () {
- return x;
- }
- public int getY () {
- return y;
- }
- public boolean outOfBorder (CellVector border) {
- if (0 > x || 0 > y) {
- return true;
- }
- if (border .x <= x || border .y <= y) {
- return true;
- }
- return false;
- }
- public boolean equals (CellVector vector) {
- return x == vector .x && y == vector .y;
- }
- @Override
- public String toString () {
- return "(" + x + ", " + y + ")";
- }
- }
Add Comment
Please, Sign In to add comment