The reason developing the Nim Game was quite difficult was because I initially had no idea, how the game is played. However, I was able to write an algorithm that worked well in trying to make sure the human player loses the game to the computer.
The algorithm being that:
- Examines all possible plays from the current position, and recursively looks at each resulting position to determine whether there is a winning play from that position.
- If not, then the play that led to that position is a winning play.
- If all plays result in positions from which there is a winning play, then there is no winning play from the root position.