Advertisement
ithortureu

Untitled

Aug 25th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. void draw(void)
  2. {
  3. int count = 0;
  4. for (int i = 0; i < d; i++) {
  5. for (int j = 0; j < d; j++) {
  6. if (board[i][j] == 0) {
  7. printf(" _ ");
  8. count++;
  9. }
  10. else {
  11. if (board[i][j] < 10) {
  12. printf(" %i ", board[i][j]);
  13. count++;
  14. }
  15. else {
  16. printf("%i ", board[i][j]);
  17. count++;
  18. }
  19. if (count % d == 0) {
  20. printf("\n\n");
  21.  
  22.  
  23. }
  24. }
  25. }
  26. }
  27. printf("\n");
  28. }
  29.  
  30. /**
  31. * If tile borders empty space, moves tile and returns true, else
  32. * returns false.
  33. */
  34. /*bool move(int tile)
  35. {
  36. for (int i = 0; i <= d-1; i++) {
  37. for (int j = 0; j <= d-1; j++) {
  38. if (board[i][j] == tile) {
  39. int tile = board[i][j];
  40. if (tile == board[blank_col][blank_row-1]) {
  41. int temp = board[i][j];
  42. board[i][j] = board[blank_col][blank_row];
  43. board[blank_col][blank_row] = temp;
  44. }
  45. }
  46. }
  47. }
  48. return true;
  49. }*/
  50.  
  51. bool move(int tile)
  52. {
  53. for (int row = 0; row <= d-1; row++) {
  54. for (int column = 0; column <= d-1; column++) {
  55. if (board[row][column] == 0)
  56. {
  57. if (board[row-1][column] == tile) // valid move swap with up
  58. {
  59. board[row][column] = tile;
  60. board[row-1][column] = 0;
  61. return true;
  62. } else if (board[row+1][column] == tile) // valid move swap with down
  63. {
  64. board[row][column] = tile;
  65. board[row+1][column] = 0;
  66. return true;
  67. } else if (board[row][column-1] == tile) // valid move swap with left
  68. {
  69. board[row][column] = tile;
  70. board[row][column-1] = 0;
  71. return true;
  72. } else if (board[row][column+1] == tile) // valid move swap with right
  73. {
  74. board[row][column] = tile;
  75. board[row][column+1] = 0;
  76. return true;
  77. }
  78.  
  79. }
  80. }
  81. }
  82. return true;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement