Sliding puzzle works fine, but it need some addings, Other puzzles will
[puzzles.git] / src / com / github / puzzles / core / AbstractRectangularPuzzle.java
blobea455c0c5c944a229f4286707a7c5ae19c692786
1 /**
2 * Rectangular puzzles should inherit this class.
3 */
5 package com.github.puzzles.core;
7 import java.util.Arrays;
9 import com.github.puzzles.util.Matrices;
11 public abstract class AbstractRectangularPuzzle<T> extends AbstractPuzzle {
13 private int width;
14 private int height;
15 T puzzle[][];
17 protected AbstractRectangularPuzzle(T[][] puzzle, int width, int height, Difficulty difficulty) {
18 super(width * height, 0, difficulty);
19 this.width = width;
20 this.height = height;
21 this.puzzle = puzzle;
24 /**
25 * Getter.
26 * @return the width of the puzzle.
28 public final int getWidth() {
29 return width;
32 /**
33 * Getter.
34 * @return the height of the puzzle.
36 public final int getHeight() {
37 return height;
40 /**
41 * Getter.
42 * @return the puzzle matrix.
44 public final T[][] getPuzzle() {
45 return Matrices.copyOf(puzzle);
46 //return puzzle;
49 /* (non-Javadoc)
50 * @see java.lang.Object#hashCode()
52 @Override
53 public int hashCode() {
54 final int prime = 31;
55 int result = super.hashCode();
56 result = prime * result + height;
57 result = prime * result + Arrays.hashCode(puzzle);
58 result = prime * result + width;
59 return result;
62 /* (non-Javadoc)
63 * @see java.lang.Object#equals(java.lang.Object)
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj)
68 return true;
69 if (!super.equals(obj))
70 return false;
71 if (getClass() != obj.getClass())
72 return false;
73 AbstractRectangularPuzzle other = (AbstractRectangularPuzzle) obj;
74 if (height != other.height)
75 return false;
76 if (!Arrays.deepEquals(puzzle, other.puzzle))
77 return false;
78 if (width != other.width)
79 return false;
80 return true;