Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 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. int rotation = 0;
  6. Block bestBlock = null;
  7. for(int i = 0; i < 4; i++){
  8. // the following "AI" moves a piece as far left as possible
  9. while (board._block.checkedLeft(board)) {
  10. out.println("left");
  11. }
  12. boolean run = true;
  13. while(run){
  14. while(board._block.checkedDown(board)){
  15. out.println("down");
  16. }
  17. if(checkEdges(board) > max){
  18. rotation = i;
  19. max = checkEdges(board);
  20. bestBlock = board._block;
  21. }
  22. while(!board._block.checkedRight(board)){
  23. if(checkAtTop(board)){
  24. run = false;
  25. } else {
  26. out.println("up");
  27. }
  28. }
  29. if(board._block.checkedRight(board)){
  30. out.println("right");
  31. }
  32. }
  33. out.println("rotate");
  34. }
  35.  
  36. for(int i = 0; i < rotation; i++){
  37. out.println("rotate");
  38. }
  39.  
  40. while(board._block.checkedUp(board)){
  41. out.println("up");
  42. }
  43. while(board._block._center.j > bestBlock){
  44. out.println("left");
  45. }
  46. while(board._block._center.j < bestBlock){
  47. out.println("right");
  48. }
  49. while(board._block.checkedDown()){
  50. out.println("down");
  51. }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement