Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void draw(void)
- {
- int count = 0;
- for (int i = 0; i < d; i++) {
- for (int j = 0; j < d; j++) {
- if (board[i][j] == 0) {
- printf(" _ ");
- count++;
- }
- else {
- if (board[i][j] < 10) {
- printf(" %i ", board[i][j]);
- count++;
- }
- else {
- printf("%i ", board[i][j]);
- count++;
- }
- if (count % d == 0) {
- printf("\n\n");
- }
- }
- }
- }
- printf("\n");
- }
- /**
- * If tile borders empty space, moves tile and returns true, else
- * returns false.
- */
- /*bool move(int tile)
- {
- for (int i = 0; i <= d-1; i++) {
- for (int j = 0; j <= d-1; j++) {
- if (board[i][j] == tile) {
- int tile = board[i][j];
- if (tile == board[blank_col][blank_row-1]) {
- int temp = board[i][j];
- board[i][j] = board[blank_col][blank_row];
- board[blank_col][blank_row] = temp;
- }
- }
- }
- }
- return true;
- }*/
- bool move(int tile)
- {
- for (int row = 0; row <= d-1; row++) {
- for (int column = 0; column <= d-1; column++) {
- if (board[row][column] == 0)
- {
- if (board[row-1][column] == tile) // valid move swap with up
- {
- board[row][column] = tile;
- board[row-1][column] = 0;
- return true;
- } else if (board[row+1][column] == tile) // valid move swap with down
- {
- board[row][column] = tile;
- board[row+1][column] = 0;
- return true;
- } else if (board[row][column-1] == tile) // valid move swap with left
- {
- board[row][column] = tile;
- board[row][column-1] = 0;
- return true;
- } else if (board[row][column+1] == tile) // valid move swap with right
- {
- board[row][column] = tile;
- board[row][column+1] = 0;
- return true;
- }
- }
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement