Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that plays the ancient Chinese game of NIM. Actually, this is a

ID: 3620203 • Letter: W

Question

Write a program that plays the ancient Chinese game of NIM. Actually, this is a simplified version of the game. Each game
starts with the user choosing how many stones to put into a pile. The user and the computer take turns removing either one
or two stones from the pile. The player who takes the last stone loses. Your program should have the computer use the
optimal playing strategy. The optimal strategy is as follows:
Divide the remaining number of stones by three. If the remainder is zero, then two stones are removed, or else one stone is
removed. For example, if the remaining number of stones is nine or fifteen, then two stones are removed; if the remaining
number of stones is eight or ten, then one stone is removed.
a) [after

Explanation / Answer

import java.util.Scanner; public class Game { static int numOfStone; static int value; static String choice; static char continueChoice; public static void main(String[] args) { int chance = -1; System.out.println("THE GAME OF NIM"); do { Scanner input = new Scanner(System.in); System.out.println("Enter the number of starting stones:"); numOfStone = input.nextInt(); System.out.println("Would you like to go first? (y/n):"); Scanner input1 = new Scanner(System.in); choice = input1.nextLine(); String str = choice.toLowerCase(); while (numOfStone > 0) { if (str.equals("yes")) { System.out .println("How many would you like to remove

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote