Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Nim{
- static boolean x = true;
- static Pile pileTrue = new Pile();
- static Pile pileFalse = new Pile();
- static int pile1, pile2;
- static int count1, count2;
- static int[] pileMain = {3, 3, 3};
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- /*System.out.println(Arrays.toString(pileOne));
- System.out.println(Arrays.toString(pileTwo));
- System.out.println(Arrays.toString(pileThree));*/
- while(x || !x){
- if(true){
- System.out.println("Player 1's turn:");
- display();
- System.out.println("Which pile would you like to choose from?");
- pile1 = input.nextInt();
- System.out.println("How many stones would you like to take?");
- count1 = input.nextInt();
- pileTrue.setPile(pile1);
- pileTrue.setCount(count1);
- pileTrue.decrease(pileTrue);
- newValue();
- x = !x;
- }
- else if(false){
- System.out.println("Player 2's turn:");
- display();
- System.out.println("Which pile would you like to choose from?");
- pile2 = input.nextInt();
- System.out.println("How many stones would you like to take?");
- count2 = input.nextInt();
- pileFalse.setPile(pile2);
- pileFalse.setCount(count2);
- pileFalse.decrease(pileFalse);
- newValue();
- x = !x;
- }
- }
- }
- public static void win(){
- if(pileMain[0] == 0 && pileMain[1] == 0 && pileMain[2] == 0){
- if(x){
- System.out.println("Game over. Player 1 wins!");
- }
- else if(!x){
- System.out.println("Game over. Player 2 wins!");
- }
- }
- }
- public static void display(){
- System.out.println(pileMain[0] + " | " + pileMain[1] + " | " + pileMain[2]);
- }
- public static void newValue(){
- if(pileTrue.getPile() == 1){
- pileMain[0] = pileTrue.getNewCount();
- }
- else if(pileTrue.getPile() == 2){
- pileMain[1] = pileTrue.getNewCount();
- }
- else if(pileTrue.getPile() == 3){
- pileMain[2] = pileTrue.getNewCount();
- }
- else if(pileFalse.getPile() == 1){
- pileMain[0] = pileFalse.getNewCount();
- }
- else if(pileFalse.getPile() == 2){
- pileMain[1] = pileFalse.getNewCount();
- }
- else if(pileFalse.getPile() == 3){
- pileMain[2] = pileFalse.getNewCount();
- }
- //System.out.println(pileMain[0] + " " + pileMain[1] + " " + pileMain[2]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement