Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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