/* * ------------------------------------- * Player.java * * An abstract player for the game of Mancala. * The method makeMove must be implemented. * * @author John Paxton * @version 1.0 * -------------------------------------- */ public abstract class Player { /* * ----------------------------------------------------------- * Player (Constructor) * * @param b an instance of the Mancala board * @param name the player's name * @param playerNumber used to identify the player * @return an instance of the Player class * ------------------------------------------------------------ */ Player (Board b, int playerNumber) { mancalaBoard = b; this.playerNumber = playerNumber; if (playerNumber == Board.PLAYER_1) { startingPit = (Board.MANCALA_2 + 1) % Board.NUMBER_PITS; } else { startingPit = (Board.MANCALA_1 + 1) % Board.NUMBER_PITS; } } public abstract void makeMove (); /* * ---------------------------------- * getName (Reader) * * @return the name of the player * ---------------------------------- */ public String getName () { return name; } public void setName (String name) { this.name = name; } /* * ------------------------------------------------ * getMancala * * @return the location of the player's Mancala * ------------------------------------------------ */ public int getMancala () { if (playerNumber == Board.PLAYER_1) { return Board.MANCALA_1; } else { return Board.MANCALA_2; } } public boolean ownsPit (int whichPit) { return ((whichPit >= startingPit) && (whichPit < startingPit + Board.NUMBER_PITS / 2 - 1)); } // ------------ instance variables ------------------ protected static Board mancalaBoard;// shared mancala board protected String name; // name of player protected int playerNumber; // player number protected int startingPit; // leftmost pit player controls protected int lastMove; // last pit player moved from }