Back to project page android-tic-tac-toe.
The source code is released under:
MIT License
If you think the Android project android-tic-tac-toe listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.shaon.android.tictactoe.model; /* w ww .j a v a 2 s . com*/ import org.shaon.android.tictactoe.model.State.Combination; import org.shaon.android.tictactoe.model.State.Player; /** * Represents terminating condition of a game. * * @author fahad */ public class TerminatingCondition { private Player player; private Combination combination; public TerminatingCondition(Player player, Combination combination) { this.player = player; this.combination = combination; } public Player getPlayer() { return player; } public void setPlayer(Player player) { this.player = player; } public Combination getCombination() { return combination; } public void setCombination(Combination combination) { this.combination = combination; } /** * Checks if condition represents tie. * * @return True if condition is tie otherwise return false. */ public boolean isTie(){ return this.combination == Combination.TIE && this.player == null; } /** * Calculate utility of the terminating condition. * * @param maximizationPlayer Player for which we are maximizing * @return Utility value */ public int utility(Player maximizationPlayer){ if(isTie()){ return 0; } if(player.equals(maximizationPlayer)) { return 1; }else if(player.equals(maximizationPlayer.equals(Player.X) ? Player.O : Player.X)) { return -1; } throw new RuntimeException("Unexpected terminating condition."); } }