// the AiPlayer uses an algorithm to decide if it should roll or stay public class AiPlayer extends PigPlayer { @Override public boolean rollOrStay(int ourScore, int opponentScore, int roundScore) { // choose a goal points based on some factors int goal; // if the goal is within reach, go for it if (ourScore > 85 ) { goal = 100 - ourScore; } else { // if we're ahead, be more conservative. if behind, agressive if (ourScore > opponentScore) { goal = 8; } else { goal = 15; } } // roll if we are not at goal if (roundScore < goal) { return true; } else { return false; } } @Override public String getName() { return "Computer"; } }