Advertisement
Guest User

Untitled

a guest
Aug 7th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. private final long EMPTY_BOARD = 0x0000000000000000;
  2.  
  3. public void foo() {
  4.         long board = 0x0000000000000000; //empty board
  5.         for(int x = 0; x < grid.length(); x++) { //the web applications sorts the grid by columns
  6.             JSONArray column = grid.getJSONArray(x);
  7.             for(int y = 0; y < column.length(); y++) {
  8.                 Object raw = column.opt(y);
  9.                 int pow = 0;
  10.                 if(raw != null && raw instanceof JSONObject) {
  11.                     JSONObject cell = (JSONObject) raw;
  12.                     pow = lb(cell.getInt("value"));
  13.  
  14.                     if(pow > 15) {
  15.                         //TODO: Handle overflow
  16.                         return "overflow";
  17.                     }
  18.                 }
  19.  
  20.                 int value = Integer.valueOf(Integer.toHexString(pow), 16);
  21.                 int position = x * 4 + y;
  22.  
  23.                 board = board & ((EMPTY_BOARD & value) >> position);
  24.  
  25.             }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement