Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. public Set<Coordinates> validate() {
  2.         Set<Coordinates> fails = new HashSet<Coordinates>();
  3.         Set<Integer> alreadyThere = new HashSet<Integer>();
  4.         List<Integer> twoTimes = new ArrayList<Integer>();
  5.  
  6.         // check lines
  7.         for (int x = 0; x < board.length; x++) {
  8.             for (int y = 0; y < board.length; y++) {
  9.                 int value = board[x][y];
  10.                 if (value > 0 && value <= size && !alreadyThere.contains(value)) {
  11.                     alreadyThere.add(value);
  12.                 }
  13.                 else if(value != 0) {
  14.                     twoTimes.add(value);
  15.                 }
  16.             }
  17.             for (int i = 0; i < twoTimes.size(); i++) {
  18.                 int ban = twoTimes.get(i);
  19.                 for (int j = 0; j < board.length; j++) {
  20.                     if (board[x][j] == ban) {
  21.                         fails.add(new Coordinates(x, j));
  22.                     }
  23.                 }
  24.             }
  25.             alreadyThere.clear();
  26.         }
  27.         twoTimes.clear();
  28.  
  29.         // check columns
  30.         for (int y = 0; y < board.length; y++) {
  31.             for (int x = 0; x < board.length; x++) {
  32.                 int value = board[x][y];
  33.                 if (value > 0 && value <= size && !alreadyThere.contains(value)) {
  34.                     alreadyThere.add(value);
  35.                 }
  36.                 else if(value != 0) {
  37.                     twoTimes.add(value);
  38.                 }
  39.             }
  40.             for (int i = 0; i < twoTimes.size(); i++) {
  41.                 int ban = twoTimes.get(i);
  42.                 for (int j = 0; j < board.length; j++) {
  43.                     if (board[j][y] == ban) {
  44.                         fails.add(new Coordinates(j, y));
  45.                     }
  46.                 }
  47.             }
  48.             alreadyThere.clear();
  49.         }
  50.         return fails;
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement