Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. void GameBoard::calculateMoves(unsigned& y, unsigned& x, std::vector<GameBoard::position>& pos)
  2. {
  3. position temp = {0, 0};
  4.  
  5. // position 1
  6. if((y - 1) >= 0 && (x + 2) < columns_))
  7. {
  8. temp.x = x + 2;
  9. temp.y = y - 1;
  10. if(board[temp.y * columns_ + temp.x] == 0)
  11. pos.push_back(temp);
  12. }
  13.  
  14. // position 2
  15. if((y - 2) >= 0 && (x + 1) < columns_)
  16. {
  17. temp.x = x + 1;
  18. temp.y = y - 2;
  19. if(board[temp.y * columns_ + temp.x] == 0)
  20. pos.push_back(temp);
  21. }
  22.  
  23. // position 3
  24. if((y - 2) >= 0 && (x - 1) >= 0)
  25. {
  26. temp.x = x - 1;
  27. temp.y = y - 2;
  28. if(board[temp.y * columns_ + temp.x] == 0)
  29. pos.push_back(temp);
  30. }
  31.  
  32. // position 4
  33. if((y - 1) >= 0 && (x - 2) >= 0)
  34. {
  35. temp.x = x - 2;
  36. temp.y = y - 1;
  37. if(board[temp.y * columns_ + temp.x] == 0)
  38. pos.push_back(temp);
  39. }
  40.  
  41. // position 5
  42. if((y + 1) < rows_ && (x - 2) >= 0)
  43. {
  44. temp.x = x - 2;
  45. temp.y = y + 1;
  46. if(board[temp.y * columns_ + temp.x] == 0)
  47. pos.push_back(temp);
  48. }
  49.  
  50. // position 6
  51. if((y + 2) < rows_ && (x - 1) >= 0)
  52. {
  53. temp.x = x - 1;
  54. temp.y = y + 2;
  55. if(board[temp.y * columns_ + temp.x] == 0)
  56. pos.push_back(temp);
  57. }
  58.  
  59. // position 7
  60. if((y + 2) < rows_ && (x + 1) < columns_)
  61. {
  62. temp.x = x + 1;
  63. temp.y = y + 2;
  64. if(board[temp.y * columns_ + temp.x] == 0)
  65. pos.push_back(temp);
  66. }
  67.  
  68. // position 8
  69. if((y + 1) < rows_ && (x + 2) < columns_)
  70. {
  71. temp.x = x + 2;
  72. temp.y = y + 1;
  73. if(board[temp.y * columns_ + temp.x] == 0)
  74. pos.push_back(temp);
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement