Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Seth Simon
- public class Nim
- {
- public int play(int pieces)
- {
- int take = 0; //intializes take
- int set = pieces % 3;//three is an importnat #
- if(set == 0) // if divisible by 3 take 2
- {
- take = 2;
- }
- if(set == 2) // if remander of 2 when you divide by three take 1
- {
- take = 1;
- }
- if(set == 1)// because if you get stuck with a number that has a remander of 1 you already lost in a perfect game
- {
- take = (int)(Math.random()*2)+1;
- }
- return take;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement