public MancalaBoard makeACopy() { MancalaBoard newBoard = new MancalaBoard(); for (int pitNum = 0; pitNum < totalPits; pitNum++) { newBoard.pits[pitNum].addStones(this. pits[pitNum].getStones()); } return(newBoard); }
public MancalaGame(String name0, String name1, int level, int stonesNumber, bool towPlayer) { board = new MancalaBoard(); board.stonesNumber = stonesNumber; board.setUpForPlay(); players = new Player[2]; players[0] = new Player(name0, 0); players[1] = new Player(name1, 1); currentPlayer = 0; this.towPlayer = towPlayer; this.level = level; }
public bool computerPlay() { if (!board.gameOver()) { List <MancalaBoard> next = board.getNextPossibleBoard(1); int max = int.MinValue; foreach (MancalaBoard b in next) { int max_min = minMax(b, this.level); if (max < max_min) { max = max_min; board = b; } } } return(board.repeated); }
public List <MancalaBoard> getNextPossibleBoard(int playerNum) { List <MancalaBoard> nextBoards = new List <MancalaBoard>(); int pitNum = playerNum * (playingPits + 1) + 1; for (int i = 0; i < playingPits; i++) { int currentPit = i + pitNum; if (pits[currentPit].stones > 0) { MancalaBoard board = this.makeACopy(); board.lastMove = currentPit; board.repeated = board.doTheMove(playerNum, i + 1, false); nextBoards.Add(board); } } return(nextBoards); }
public int maxMin(MancalaBoard board, int level) { if (board.gameOver() || level == 0) { return(board.evaluate(1)); } else { List <MancalaBoard> next = board.getNextPossibleBoard(1); int max = int.MinValue; foreach (MancalaBoard b in next) { // if (b.repeated) // max = Integer.max(max, minMax(b, level)); // else max = Math.Max(max, minMax(b, level - 1)); } return(max); } }