It seems like my java code is stuck in a loop somewhere -


import java.util.random; import java.lang.math; import java.lang.string; public class gameofnim {   private int min,max;   private int turn;   private int firstturn;   private int stupid;   private int smart;   private int computer;   private int user;   private int first;   private int pile;     public gameofnim(int min, int max ){     pile=(int)(math.random()*max+min);     smart=(int)(math.random()*100);     stupid=(int)(math.random()*100);     system.out.println("pile size "+pile);     firstturn=(int)(math.random()*100 + 1);     computer=0;     user=1;     if(firstturn>50)     {         firstturn=user;     }     else     {         firstturn=computer;     }     firstturn=turn;  }   public void play()  {      if(smart>50)         {             system.out.println("computer playing smart");         }         else         {             system.out.println("computer playing stupid");         }       if(firstturn==user)              {                  system.out.println("you go first");              }               else              {                  system.out.println("computer goes first");              }           turn = firstturn;      while(pile-1>0)      {          if(turn==user)          {              string take = "how many marbles want take away?";             system.out.println(take);             int take2 = integer.parseint(take);                while(take2>(int)(pile/2))             {               system.out.println("only take away half or less pile");               take = "how many marbles want take away?";               take2= integer.parseint(take);             }             pile= pile-take2;             system.out.println("there "+pile+" marbles left");             turn=computer;                 }             else           {               if(smart>50)               {                   pile -= smarttake();               }                 else               {                   pile -= stupidtake();               }                  turn = user;             }         }        }   private int smarttake()      {         int x = (int)(math.random())*2-1;         int smarbles= (int)math.pow(2,x);         while (smarbles > (.5 * pile) || smarbles==0)         {             x = (int)(math.random())*2-1;             smarbles = (int)math.pow(2,x);         }         system.out.println("the computer took away " + smarbles +" marbles");         return smarbles;     }      private int stupidtake(){         int stmarbles = pile/2;         while (stmarbles > (.5*pile) || pile==0)         {             stmarbles = pile/2;         }         system.out.println("the computer took away " + stmarbles +" marbles");         return stmarbles;     } } 

this game of nim class

public class project5 {     public static void main(string args[])      {       string k = "yes";       string str;          scanner console = new scanner(system.in);         system.out.print("enter minimum number of marbles in pile: ");         int min = console.nextint();          system.out.print("enter maximum number of marbles in pile: ");         int max= console.nextint();         gameofnim game = new gameofnim(min, max);          game.play();        system.out.println( " thank , bye!");     } } 

and driver class

for reason everytime run it goes way point says "computer goes first" nothing else happens. im assuming stuck in loop cant seem find out why. appreciated


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -