Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void run(JSONObject jsonObj, PrintStream out)
- {
- Board board = Board.initializeBoardFromJSON(jsonObj);
- int max = 0;
- int rotation = 0;
- Block bestBlock = null;
- for(int i = 0; i < 4; i++){
- // the following "AI" moves a piece as far left as possible
- while (board._block.checkedLeft(board)) {
- out.println("left");
- }
- boolean run = true;
- while(run){
- while(board._block.checkedDown(board)){
- out.println("down");
- }
- if(checkEdges(board) > max){
- rotation = i;
- max = checkEdges(board);
- bestBlock = board._block;
- }
- while(!board._block.checkedRight(board)){
- if(checkAtTop(board)){
- run = false;
- } else {
- out.println("up");
- }
- }
- if(board._block.checkedRight(board)){
- out.println("right");
- }
- }
- out.println("rotate");
- }
- for(int i = 0; i < rotation; i++){
- out.println("rotate");
- }
- while(board._block.checkedUp(board)){
- out.println("up");
- }
- while(board._block._center.j > bestBlock){
- out.println("left");
- }
- while(board._block._center.j < bestBlock){
- out.println("right");
- }
- while(board._block.checkedDown()){
- out.println("down");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement