// Chips.java // Sample solution to Lab #1. Written by THC. // Plays the game of chips. Originally there are 99 chips in a pile, but // in fact we allow the players to enter the number. The first player removes // any number of chips from the pile, leaving at least half of them. From then // on, the players alternate removing chips from the pile until it is empty. // The number of chips removed in each turn must be at least 1 and at most // twice the number removed by the other player in the previous turn. // At the end of the game, the player with an even number of chips is the // winner. import java.util.Scanner; public class Chips { public static void main(String[] args) { String response; Scanner input = new Scanner(System.in); do { playAGame(); System.out.print("\n\nPlay another game? (y/n) "); response = input.next(); } while ((response.toLowerCase()).charAt(0) == 'y'); } private static void playAGame() { Referee official = new Referee(); // Make a new game and initialize it. int move; // Number of chips removed in a turn // The main loop makes moves until the game is over. while (!official.saysGameIsOver()) { official.describeState(); move = official.getLegalMove(); official.updateState(move); } // All done, so announce the winner. official.announceWinner(); } }