import java.util.Scanner; // Dr Nim video https://www.youtube.com/watch?v=9KABcmczPdg public class DrNim { private static Scanner kb; private int marblesLeft; public DrNim(int n) { marblesLeft = n; } /* * Returns a random number of marbles (1-3) to take * Precondition: nmarbles > 0 */ public int computerMove() { ///Your code here ____________________________ } public int humanMove(int nMarbles) { System.out.print("How many marbles do you take? "); int n = kb.nextInt(); while (n < 1 || n >3){ System.out.println("You are allowed to only take 1, 2, or 3 marbles"); n = kb.nextInt(); } return n; } public void play() { while (marblesLeft > 0) { System.out.println(); for(int i=0; i < marblesLeft; i++) System.out.print("O "); System.out.println("\n"+marblesLeft + " marble(s) left in the pile"); int n = -1; while (n < 0) n = humanMove(marblesLeft); marblesLeft -= n; System.out.println("You took " + n + " marble(s)"); if (marblesLeft == 0) { System.out.println("You won!"); } else { n = computerMove(); marblesLeft -= n; System.out.println("I take " + n + " marble(s)"); if (marblesLeft == 0) System.out.println("I won!"); } } } public static void main(String[] args) { kb = new Scanner(System.in); DrNim game = new DrNim(12); game.play(); kb.close(); } }