Advertisement
ithortureu

Untitled

Aug 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. bool move(int tile)
  2. {
  3. for (int row = 0; row <= d-1; row++) {
  4. for (int column = 0; column <= d-1; column++) {
  5. if (board[row][column] == 0)
  6. {
  7. if (board[row-1][column] == tile) // valid move swap with up
  8. {
  9. board[row][column] = tile;
  10. board[row-1][column] = 0;
  11. return true;
  12. } else if (board[row+1][column] == tile) // valid move swap with down
  13. {
  14. board[row][column] = tile;
  15. board[row+1][column] = 0;
  16. return true;
  17. } else if (board[row][column-1] == tile) // valid move swap with left
  18. {
  19. board[row][column] = tile;
  20. board[row][column-1] = 0;
  21. return true;
  22. } else if (board[row][column+1] == tile) // valid move swap with right
  23. {
  24. board[row][column] = tile;
  25. board[row][column+1] = 0;
  26. return true;
  27. }
  28.  
  29. }
  30. }
  31. }
  32. return true;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement