Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sokoban state space explorer.
- // Discussion: https://dxdy.ru/topic144781.html
- 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 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 char moveLetter (int index) {
- return moveLetter [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 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;
- }
- public String toString () {
- return "(" + x + ", " + y + ")";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement