Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Set<Coordinates> validate() {
- Set<Coordinates> fails = new HashSet<Coordinates>();
- Set<Integer> alreadyThere = new HashSet<Integer>();
- List<Integer> twoTimes = new ArrayList<Integer>();
- // check lines
- for (int x = 0; x < board.length; x++) {
- for (int y = 0; y < board.length; y++) {
- int value = board[x][y];
- if (value > 0 && value <= size && !alreadyThere.contains(value)) {
- alreadyThere.add(value);
- }
- else if(value != 0) {
- twoTimes.add(value);
- }
- }
- for (int i = 0; i < twoTimes.size(); i++) {
- int ban = twoTimes.get(i);
- for (int j = 0; j < board.length; j++) {
- if (board[x][j] == ban) {
- fails.add(new Coordinates(x, j));
- }
- }
- }
- alreadyThere.clear();
- }
- twoTimes.clear();
- // check columns
- for (int y = 0; y < board.length; y++) {
- for (int x = 0; x < board.length; x++) {
- int value = board[x][y];
- if (value > 0 && value <= size && !alreadyThere.contains(value)) {
- alreadyThere.add(value);
- }
- else if(value != 0) {
- twoTimes.add(value);
- }
- }
- for (int i = 0; i < twoTimes.size(); i++) {
- int ban = twoTimes.get(i);
- for (int j = 0; j < board.length; j++) {
- if (board[j][y] == ban) {
- fails.add(new Coordinates(j, y));
- }
- }
- }
- alreadyThere.clear();
- }
- return fails;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement