import java.lang.*; class Mancala implements Cloneable /* * * bin number: 0 1 2 3 4 5 * --------------------------- * player 1 | |4 |4 |4 |4 |4 |4 | | * | 0 |-----------------| 0 | <- player 0's mancala * player 0 | |4 |4 |4 |4 |4 |4 | | * --------------------------- * bin number: 5 4 3 2 1 0 * */ { private int NUM_BINS = 3; private int NUM_STONES = 4; private int[] mancalas; private int[][] bins; //Constructor// public Mancala() { this.bins = new int[2][this.NUM_BINS]; for (int i=0; i<2; ++i) for(int j=0; j 0) { //decrement current bin --currBin; if (currBin<0) //check if we're out of bins { if (currSide==player) //check if we're at the player's mancala { ++this.mancalas[player]; //put a stone in the mancala --numStones; if (numStones==0) return false; } currSide = -currSide+1; //switch sides currBin = this.NUM_BINS-1; //reset bin number } //put a stone in the bun ++this.bins[currSide][currBin]; --numStones; } //Capture stones int captureStones = this.bins[-currSide+1][this.NUM_BINS-currBin-1]; if (currSide==player&&this.bins[currSide][currBin]==1&&captureStones!=0) { this.mancalas[player]+=captureStones+1; this.bins[currSide][currBin] = 0; this.bins[-currSide+1][this.NUM_BINS-currBin-1] = 0; } return true; } public boolean validMove(int player, int bin) { if (bin < 0 || bin > this.NUM_BINS-1) return false; return this.bins[player][bin]!=0; } public boolean hasMove(int player) { if (this.remainingStones(player) > 0) return true; return false; } public int remainingStones(int player) { int numStones = 0; for (int i=0; i=0; --i) { int curr = this.bins[0][i]; if (curr<10) System.out.print(curr+" |"); else System.out.print(curr+"|"); //System.out.print(this.bins[0][i]+" |"); } System.out.println(" |"); System.out.println(line1+line2); } }