Advertisement
Guest User

nim

a guest
Oct 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class NimGame {
  3. public static void main(String[] args) {
  4. Scanner scan = new Scanner(System.in);
  5. // System.out.println("Who starts 1 or 2");
  6. // int x = scan.nextInt();
  7. // if (x==1){
  8. int matches = 21;
  9. while (matches>=0){
  10. System.out.println("p1 how many would you like to take?");
  11. int take = scan.nextInt();
  12. while(take>3 || take<1){
  13. System.out.println("p1 how many would you like to take this time not more then 3?");
  14. take = scan.nextInt();
  15. }
  16. matches= matches-take;
  17. System.out.println(matches+" matches left");
  18. if(matches==0){
  19. System.out.println("p1 win");
  20. break;
  21. }
  22.  
  23. System.out.println("p2 how many would you like to take?");
  24. int take1 = scan.nextInt();
  25. while(take1>3 || take1<1){
  26. System.out.println("p2 how many would you like to take this time not more then 3?");
  27. take1 = scan.nextInt();
  28.  
  29. }
  30. matches= matches-take1;
  31. System.out.println(matches+" matches left");
  32.  
  33.  
  34. if(matches==0){
  35. System.out.println("p2 win");
  36. break;
  37.  
  38. }
  39. }
  40.  
  41.  
  42. }
  43.  
  44. // else {
  45. // int matches1=21;
  46. // while (matches1>=0){
  47. // System.out.println("p2 how many would you like to take? ");
  48. // int take = scan.nextInt();
  49. // matches1= matches1-take;
  50. // System.out.println(matches1+" matches left");
  51. // if(matches1==0){
  52. // System.out.println("p2 win");
  53. // break;
  54. // }
  55.  
  56. // System.out.println("p1 how many would you like to take? ");
  57. // int take1 = scan.nextInt();
  58. // matches1= matches1-take1;
  59. // System.out.println(matches1+" matches left");
  60.  
  61. // if(matches1==0){
  62. // System.out.println("p1 win");
  63. // break;
  64.  
  65. // }
  66. // }
  67.  
  68. // }
  69. // }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement