Advertisement
Guest User

Seth Simon Nim

a guest
Oct 20th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.50 KB | None | 0 0
  1. //Seth Simon
  2. public class Nim
  3. {
  4.  
  5.   public int play(int pieces)
  6.   {
  7.     int take = 0; //intializes take
  8.     int set = pieces % 3;//three is an importnat #
  9.     if(set == 0) // if divisible by 3 take 2
  10.   {
  11.     take = 2;
  12.   }
  13.   if(set == 2) // if remander of 2 when you divide by three take 1
  14.   {
  15.     take = 1;
  16.   }
  17.   if(set == 1)// because if you get stuck with a number that has a remander of 1 you already lost in a perfect game
  18.   {
  19.     take = (int)(Math.random()*2)+1;
  20.   }
  21.   return take;
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement