Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Nim{
  4. static boolean x = true;
  5. static Pile pileTrue = new Pile();
  6. static Pile pileFalse = new Pile();
  7. static int pile1, pile2;
  8. static int count1, count2;
  9. static int[] pileMain = {3, 3, 3};
  10.  
  11. public static void main(String[] args){
  12. Scanner input = new Scanner(System.in);
  13.  
  14. /*System.out.println(Arrays.toString(pileOne));
  15. System.out.println(Arrays.toString(pileTwo));
  16. System.out.println(Arrays.toString(pileThree));*/
  17.  
  18. while(x || !x){
  19. if(true){
  20. System.out.println("Player 1's turn:");
  21. display();
  22. System.out.println("Which pile would you like to choose from?");
  23. pile1 = input.nextInt();
  24.  
  25. System.out.println("How many stones would you like to take?");
  26. count1 = input.nextInt();
  27.  
  28. pileTrue.setPile(pile1);
  29. pileTrue.setCount(count1);
  30.  
  31. pileTrue.decrease(pileTrue);
  32. newValue();
  33. x = !x;
  34. }
  35. else if(false){
  36. System.out.println("Player 2's turn:");
  37. display();
  38. System.out.println("Which pile would you like to choose from?");
  39. pile2 = input.nextInt();
  40.  
  41. System.out.println("How many stones would you like to take?");
  42. count2 = input.nextInt();
  43.  
  44. pileFalse.setPile(pile2);
  45. pileFalse.setCount(count2);
  46.  
  47. pileFalse.decrease(pileFalse);
  48. newValue();
  49. x = !x;
  50. }
  51. }
  52. }
  53. public static void win(){
  54. if(pileMain[0] == 0 && pileMain[1] == 0 && pileMain[2] == 0){
  55. if(x){
  56. System.out.println("Game over. Player 1 wins!");
  57. }
  58. else if(!x){
  59. System.out.println("Game over. Player 2 wins!");
  60. }
  61. }
  62. }
  63.  
  64. public static void display(){
  65. System.out.println(pileMain[0] + " | " + pileMain[1] + " | " + pileMain[2]);
  66. }
  67.  
  68. public static void newValue(){
  69. if(pileTrue.getPile() == 1){
  70. pileMain[0] = pileTrue.getNewCount();
  71. }
  72. else if(pileTrue.getPile() == 2){
  73. pileMain[1] = pileTrue.getNewCount();
  74. }
  75. else if(pileTrue.getPile() == 3){
  76. pileMain[2] = pileTrue.getNewCount();
  77. }
  78. else if(pileFalse.getPile() == 1){
  79. pileMain[0] = pileFalse.getNewCount();
  80. }
  81. else if(pileFalse.getPile() == 2){
  82. pileMain[1] = pileFalse.getNewCount();
  83. }
  84. else if(pileFalse.getPile() == 3){
  85. pileMain[2] = pileFalse.getNewCount();
  86. }
  87.  
  88. //System.out.println(pileMain[0] + " " + pileMain[1] + " " + pileMain[2]);
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement