Guest User

Untitled

a guest
Feb 20th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. private int colHeight(boolean[][] board, int col) {
  2. for (int row = 0; row <= MAXROW; row++) {
  3. if (board[row][col]) return row + 1;
  4. }
  5. return MAXROW;
  6. }
  7.  
  8. private Piece ORules(Piece p, boolean[][] board) {
  9.  
  10. int destCol = -1;
  11. int curColHeight = -1;
  12. int minColHeight = -1;
  13.  
  14. // gets the destination column
  15. for (int col = 0; col < MAXCOL; col++) {
  16. curColHeight = colHeight(board, col);
  17. if (curColHeight == colHeight(board, col + 1) && curColHeight > minColHeight) {
  18. destCol = col + 1;
  19. minColHeight = curColHeight;
  20. }
  21. }
  22.  
  23. // no suitable place for 2x2 piece //EDIT!
  24. if (destCol == -1) {
  25. p = p.drop();
  26. return p;
  27. }
  28.  
  29. // move left or right to reach the destination column
  30. p = moveTo(p, destCol);
  31. return p;
  32. }
  33.  
  34. private Piece IRules(Piece p, boolean[][] board) {
  35. int destCol = -1;
  36. int curColHeight = -1;
  37.  
  38. // check for big gaps on edges
  39. if (colHeight(board, 0) - 2 <= colHeight(board, 1)) {
  40. if (p.getOrientation() == 0) p = p.clockwise();
  41. p = moveTo(p, 0);
  42. return p;
  43. }
  44. if (colHeight(board, MAXCOL) - 2 <= colHeight(board, MAXCOL - 1)) {
  45. if (p.getOrientation() == 0) p = p.clockwise();
  46. p = moveTo(p, MAXCOL);
  47. return p;
  48. }
  49.  
  50. // check for big gaps in the middle
  51. for (int col = 1; col < MAXCOL; col++) {
  52. curColHeight = colHeight(board, col);
  53. if (curColHeight - 2 <= colHeight(board, col -1) && curColHeight - 2 <= colHeight(board, col + 1)) {
  54. // currently just goes to the first one; implement options
  55. if (p.getOrientation() == 0) p = p.clockwise();
  56. p = moveTo(p, col);
  57. return p;
  58. }
  59. }
  60.  
  61. // try horizontal
  62. for (int col = 0; col < MAXCOL - 2; col++) {
  63. curColHeight = colHeight(board, col);
  64. if (curColHeight == colHeight(board, col + 1) &&
  65. curColHeight == colHeight(board, col + 2) &&
  66. curColHeight == colHeight(board, col + 3)) {
  67. destCol = col + 2;
  68. }
  69. }
  70. if (destCol != -1) {
  71. if (p.getOrientation() != 0) p = p.clockwise();
  72. p = moveTo(p, destCol);
  73. return p;
  74. }
  75.  
  76. // side or biggest gap? lowest height? currently just moves to the side
  77. if (p.getOrientation() == 0) p = p.clockwise();
  78. p = moveTo(p, MAXCOL);
  79. p = p.drop();
  80. return p;
  81. }
Add Comment
Please, Sign In to add comment