/** * Compute score recursively for current board(starting from the leafs) using MINIMAX technique. * (If current player is X, return the MAX of its children's score; otherwise, return the MIN of * its children's score.) * * @return the score for the current board configuration. */ public int computeScore() { int score; if (this.currPlayer == 1) { score = -1000000000; ArrayList<GameBoard> possibleMoves = this.getNextMoves(); for (GameBoard A : possibleMoves) { if (A.noMoreMoves) score = Math.max(score, A.getScore()); else score = Math.max(score, A.computeScore()); } this.setScore(score); return score; } else { score = +1000000000; ArrayList<GameBoard> possibleMoves = this.getNextMoves(); for (GameBoard A : possibleMoves) { if (A.noMoreMoves) score = Math.min(score, A.getScore()); else score = Math.min(score, A.computeScore()); } this.setScore(score); return score; } }