Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vector<int> backtrackLegalSolution(vector<int> board, int row){
- // Solution we want: {1, 3, 5, 7, 0, 0, 0, 0}
- if(row != 0){
- // Can only move to the right, trying other combinations to the left does not work, we are always moving towards the right.
- for(int col = findLastPosition(board)[1]; col < board.size() + 1; col++){
- cout << " this is the column : " << col << "\n";
- cout << "this is the row : " << row << "\n";
- vector<int> newBoard = board;
- newBoard[row] = col;
- if(isLegalPosition(newBoard)){
- cout << "This backtracking board is found!\n";
- printBoard(newBoard);
- return newBoard;
- }
- }
- // TODO: Need to figure out here what to do when there has been a path already traveled.
- vector<int> newBoard = board;
- newBoard[row] = 0;
- backtrackLegalSolution(newBoard, row - 1);
- }
- else{
- if(findLastPosition(board)[1] == board.size()){
- cout << "if the board is in the last one, no more, end it";
- cout << "stop the function, this is the base case???";
- return {0};
- }
- else{
- cout << "otherwise, the next position in the first row is the current position + 1, unless it is at the edge.";
- vector<int> newBoard = board;
- newBoard[0] = findLastPosition(board)[1] + 1;
- cout << "new board!";
- return newBoard;
- }
- }
- return {0};
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement