Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void GameBoard::calculateMoves(unsigned& y, unsigned& x, std::vector<GameBoard::position>& pos)
- {
- position temp = {0, 0};
- // position 1
- if((y - 1) >= 0 && (x + 2) < columns_))
- {
- temp.x = x + 2;
- temp.y = y - 1;
- if(board[temp.y * columns_ + temp.x] == 0)
- pos.push_back(temp);
- }
- // position 2
- if((y - 2) >= 0 && (x + 1) < columns_)
- {
- temp.x = x + 1;
- temp.y = y - 2;
- if(board[temp.y * columns_ + temp.x] == 0)
- pos.push_back(temp);
- }
- // position 3
- if((y - 2) >= 0 && (x - 1) >= 0)
- {
- temp.x = x - 1;
- temp.y = y - 2;
- if(board[temp.y * columns_ + temp.x] == 0)
- pos.push_back(temp);
- }
- // position 4
- if((y - 1) >= 0 && (x - 2) >= 0)
- {
- temp.x = x - 2;
- temp.y = y - 1;
- if(board[temp.y * columns_ + temp.x] == 0)
- pos.push_back(temp);
- }
- // position 5
- if((y + 1) < rows_ && (x - 2) >= 0)
- {
- temp.x = x - 2;
- temp.y = y + 1;
- if(board[temp.y * columns_ + temp.x] == 0)
- pos.push_back(temp);
- }
- // position 6
- if((y + 2) < rows_ && (x - 1) >= 0)
- {
- temp.x = x - 1;
- temp.y = y + 2;
- if(board[temp.y * columns_ + temp.x] == 0)
- pos.push_back(temp);
- }
- // position 7
- if((y + 2) < rows_ && (x + 1) < columns_)
- {
- temp.x = x + 1;
- temp.y = y + 2;
- if(board[temp.y * columns_ + temp.x] == 0)
- pos.push_back(temp);
- }
- // position 8
- if((y + 1) < rows_ && (x + 2) < columns_)
- {
- temp.x = x + 2;
- temp.y = y + 1;
- if(board[temp.y * columns_ + temp.x] == 0)
- pos.push_back(temp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement