Android Open Source - android-tic-tac-toe Terminating Condition






From Project

Back to project page android-tic-tac-toe.

License

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.

Java Source Code

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.");
  }
  
  
  
}




Java Source Code List

org.shaon.android.tictactoe.TicTacToeApplication.java
org.shaon.android.tictactoe.activity.SettingsActivity.java
org.shaon.android.tictactoe.activity.TicTacToeActivity.java
org.shaon.android.tictactoe.board.Board.java
org.shaon.android.tictactoe.board.Cell.java
org.shaon.android.tictactoe.exception.InvalidTurn.java
org.shaon.android.tictactoe.model.ActionState.java
org.shaon.android.tictactoe.model.Action.java
org.shaon.android.tictactoe.model.AlphaBetaSearch.java
org.shaon.android.tictactoe.model.MinMax.java
org.shaon.android.tictactoe.model.PlayerConfig.java
org.shaon.android.tictactoe.model.SearchAlgorithm.java
org.shaon.android.tictactoe.model.State.java
org.shaon.android.tictactoe.model.TerminatingCondition.java
org.shaon.android.tictactoe.model.WinningCombination.java