Advertisement
Guest User

Code

a guest
Feb 5th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. public static void run(JSONObject jsonObj, PrintStream out)
  2. {
  3. Board board = Board.initializeBoardFromJSON(jsonObj);
  4. int max = 0;
  5. Block bestBlock = null;
  6. for(int i = 1; i < 4; i++){
  7. // the following "AI" moves a piece as far left as possible
  8. while (board._block.checkedLeft(board)) {
  9. out.println("left");
  10. }
  11. boolean run = true;
  12. while(run){
  13. while(board._block.checkedDown(board)){
  14. out.println("down");
  15. }
  16. if(checkEdges(board) > max){
  17. max = checkEdges(board);
  18. bestBlock = board._block;
  19. }
  20. while(!board._block.checkedRight(board)){
  21. if(checkAtTop(board)){
  22. run = false;
  23. } else {
  24. out.println("up");
  25. }
  26. }
  27. if(board._block.checkedRight(board)){
  28. out.println("right");
  29. }
  30. }
  31. out.println("rotate");
  32. }
  33. }
  34. public static boolean checkAtTop(Board board){
  35. for (Point square : block.squares()) {
  36. if (square.i < 0 || square.i >= ROWS - 1 ||
  37. square.j < 0 || square.j >= COLS ||
  38. _bitmap[square.i][square.j] != 0)
  39. return false;
  40. }
  41. return true;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement