Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using Mutual Recursion in Java to write the game Nim

807599Apr 26 2007 — edited Apr 27 2007
I am having trouble with this project for my Comp Sci class. We're supposed to make an intelligent opponent using mutual recursion for the game Nim. In this variation there are 3 stacks of sticks. During a turn a player must pick up at least one stick from one pile. If it is so desired a player may take the whole stack. The player who takes the very last stick loses.

The professor wrote the main method and we're supposed to implement winningPosition and losingPosition. A winning position is a position in which there is a move that could lead to a losing position. A losing position is a move in which every move will result in a winning position for the other player.

I believe my main problem is defining losingPosition, when I set up the computer player to win, it usually makes a wrong move.

Location of the file http://wretchednale.com/Nim.java
The program takes 3 arguments to start (i.e. java Nim 1 4 0 where 1, 4, and 0 are the size of the piles 1, 2, and 3 respectively.


Solved
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 24 2007
Added on Apr 26 2007
0 comments
274 views