/** * This file contains starter code for the Nim game. We copied * over method names from the TwoPlayerGame interface and provided * just enough implementation so that the compiler can compile them * without producing any errors. These implementations are not * correct, so you should replace them with real implementations. * * We also added an empty constructor, which you should implement. * * A good place to start is by writing a main method... */ public class Nim implements TwoPlayerGame { /* we put state stored inside the class here */ // the board int[] board; // the current player int currentPlayer; /** * Initializes a new Nim board game. * * @param numPiles The number of matchstick piles. * @param minMatches The smallest number of matches per pile. * @param maxMatches The largest number of matches per pile. */ public Nim(int numPiles, int minMatches, int maxMatches) { // create a new board array board = new int[numPiles]; // initialize each pile on the board randomly (this is incomplete) for (int i = 0; i < board.length; i++) { // generate a random number representing the height of the pile // (a number between what and what? Look at the constructor parameters above for a hint.) board[i] = // ? } // set the initial player currentPlayer = 0; } /** * Returns the current value for a given resource. * * @param resource Describes the game element. * @returns The current value of the resource. */ public int getResource(int resource) { // TODO replace return -1; } /** * Sets the game state. Should not check whether the given * parameters are valid. isValidMove should be called before * calling this method to ensure that a move is legal. * * @param resource Which resource to alter (e.g., position, gamepiece, pile of matches, etc.) * @param updatedValue The updated value of the resource (e.g., how many matches remain, the updated position of a piece, etc.) */ public void setResource(int resource, int updatedValue) { // TODO } /** * Returns the number representing the current player. * * @returns The current player. */ public int getPlayer() { // TODO replace return 0; } /** * Changes the current player to the given player. * * @param player A player number. */ public void setPlayer(int player) { // TODO } /** * Returns true if the specification of a move describes a legal move * given all the rules of the game. Note: this does not check whether the * move is *good* move, only whether it is legal. * * @param resource Which resource to alter (e.g., position, gamepiece, pile of matches, etc.) * @param updatedValue The updated value of the resource (e.g., how many matches remain, the updated position of a piece, etc.) * @return True iff the move is valid. */ public boolean isValidMove(int resource, int updatedValue) { // TODO replace return false; } /** * Returns true if the game is over. * @returns True if the game is over, false otherwise. */ public boolean isGameOver() { // TODO replace return true; } /** * Displays the board on screen. */ public void displayBoard() { // TODO } /** * The entry point to the program. It currently ignores * the contents of the args array. * @param args */ public static void main(String[] args) { // System.out.println("This program does nothing."); // create a new Nim board Nim n = new Nim(5, 1, 7); // take turns until game is over while(!n.isGameOver()) { n.takeATurn(); // we don't have this yet, right? } // now what? } }