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;
- Block bestBlock = null;
- for(int i = 1; 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){
- 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");
- }
- }
- public static boolean checkAtTop(Board board){
- for (Point square : block.squares()) {
- if (square.i < 0 || square.i >= ROWS - 1 ||
- square.j < 0 || square.j >= COLS ||
- _bitmap[square.i][square.j] != 0)
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement