Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool move(int tile)
- {
- // int temp;
- int blankrow;
- int blankcol;
- int tilerow;
- int tilecol;
- for (int row = 0; row < d; row++){
- for (int col = 0; col < d; col++){
- // determine pos of blank tile
- if (board[row][col] == 0){
- blankrow = row;
- blankcol = col;
- // determine if blank tile is out of bounds
- if (blankrow + 1 > d-1 || blankcol + 1 > d-1 || blankrow -1 > d-1 || blankcol - 1 > d-1){
- return false;
- }
- }
- // determine pos of user tile
- if (board[row][col] == tile) {
- tilerow = row;
- tilecol = col;
- // determine if tile move is out of bounds
- if (tilerow + 1 > d-1 || tilecol + 1 > d-1 || tilerow - 1 > d-1 || tilecol - 1 > d-1){
- return false;
- }
- else if ((tilerow == blankrow) && (tilecol == blankcol +1 || tilecol == blankcol-1)) || ((tilecol == blankcol) && (tilerow == blankcol +1 || tilerow == blankcol-1)){
- // legal move is permitted...blankrow and col must be updated once swap takes places
- temp = board[row][col];
- board[row][col] = tile;
- tile = temp;
- return true;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement