Before you figure out why your backtracking doesn't work, you need to analyze your code and understand what you are telling the computer to do. I'm not sure you have things quite correct.
First of all, decide if you are going to use the terminology wolf-sheep-rice or wolf-goat-cabbage. It's the same problem, but mixing terminology can confuse things.
Next, you should create an enum for each of these players. It should be
enum Player {MAN, WOLF, GOAT, CABBAGE, NUM_PLAYERS};
. (If you end up needing a value indicating "empty", add "NONE" to the beginning of the enum values, but that's not how I see this problem working itself out.)
Look at how you defined your data structures in lines 69 and 70. Line 69 is basically saying "I've got 3 spots in the river, and they currently are occupied by the cabbage, goat and wolf. That's not actually what you want. What you were trying to do here was create a boolean value indicating that the player in question is on the river. So line 69 should be
bool river[NUM_PLAYERS]
.
I think even better would be to create a second enum:
enum Location{ORIG_BANK, RIVER, FINAL_BANK};
and then declare an array of the locations of each of the players as such:
1 2 3 4 5
|
Location currentLocation[NUM_PLAYERS];
for (int i = 0; i < NUM_PLAYERS; ++i)
{
currentLocation[i] = ORIG_BANK;
}
|
Then your check function only needs to determine if 2 adjacent players are in the same location and the man is not there.
You need to realize that each trip across the river is 2 step. In the first, the man and 0 or 1 other players are on ther river. In the second, the man and the other player are on the other bank.
When you get that logic worked through, you can tackle the backtracking part of the problem. Unfortunately, I've got to get back to work, so that's all I have time to help you with today.