Posted by: reverse_engineer July 28, 2008
Java help
Login in to Rate this Post:     0       ?        

quickly skimming your code, it looks alright to me... i am not too sure about your shoot algorithm though (everything else looks like its written well to fit the problem description), specifically this part:

double random_num = (double) (Math.random()*1);

 if (random_num <= accuracy)
 {
  targetAlive = false;
        number_alive--;
     }

So, this would mean you choose a random number between 0 and 1 and if it is equal to or less than the probability of the person's shooting odds, the target dies? I might be overlooking something here, but I can not quite understand that part...  Should it be random_num >=accuracy? Thats the only place where i can see yout code going wrong - and that would be more of an algorithm flaw than a coding mistake. What is the output youre getting?

Read Full Discussion Thread for this article