0

Hey Guys, I am writing a Recursive Function which picks the best move for Computer(sort of A.I.) i have done all the base cases however couldn't figure out how to deal with the last part.

Given n stones the player can remove 1, 2 or 3 stones per move. The player to remove the last stone loses. If a guaranteed win is possible, the function sets move to the winning move and returns true. If a win is not possible, the function returns false and sets move to 1 (a delaying tactic).

```
bool bestMove(int stonesLeft, int & move) {
if (stonesLeft <= 4 && stonesLeft > 1) {
move = stonesLeft - 1;
return true;
}
if (stonesLeft > 5) {
return false;
move =1;
}
if (stonesLeft == 1) {
move =1;
return false;
}
bestMove(stonesLeft -1, move);
}
```