org.dartra.standard
Class BestOfMatch

java.lang.Object
  extended byorg.dartra.standard.PersistentObject
      extended byorg.dartra.standard.StandardGame
          extended byorg.dartra.standard.StandardMatch
              extended byorg.dartra.standard.BestOfMatch
All Implemented Interfaces:
Game, Match, Persistent
Direct Known Subclasses:
CricketMatch, X01Match, X01Set

public abstract class BestOfMatch
extends StandardMatch

A match which has as winner the player that won more than half of the number of games played. The 'best-of' (the maximum number of games played) needs to be uneven.

A subclass of this class implementing a standard "best-of" match will simply have to override the createNewGame() method.

Author:
Erwin Vervaet, Bieke Meeussen

Constructor Summary
BestOfMatch(java.lang.String name, Board board, int bestOf, boolean determineFirstPlayer)
           
BestOfMatch(java.lang.String name, Board board, Player[] players, int bestOf, boolean determineFirstPlayer)
           
BestOfMatch(java.lang.String name, Board board, Player[] players, StringProperties props)
           
BestOfMatch(java.lang.String name, Board board, StringProperties props)
           
 
Method Summary
protected  void checkMatchWinner()
          Checks if this match has a winner: goes through the games that have been played, and checks if one player has won more than half of the games of this match.
protected  int countGamesWon(Player player)
          Counts the number of games the given player has won so far in this match.
protected abstract  Game createNewGame()
          Subclasses should define this method appropriately.
 int getBestOf()
          Returns the best-of (the maximum number of games) for this match.
protected  Player[] getPlayerArray()
          Returns the array with the players of this match.
 Score getPlayerScore(Player player)
          Returns the player score for this match, this is the number of games the given player has won in this match.
 StringProperties getProperties()
          Subclasses should implement this to properly return their game specific properties (for instance the "start score" for an x01 game).
 void start()
          Starts the best-of match.
protected  void startNewGame()
          Starts a new game in this match.
 java.lang.String toString()
           
 
Methods inherited from class org.dartra.standard.StandardMatch
accept, addGame, addTurn, getCurrentGame, getCurrentPlayer, getCurrentTurn, getGame, getGames, getObjective, registerHit, undoHit
 
Methods inherited from class org.dartra.standard.StandardGame
addGameEventListener, getBoard, getEndTime, getFirstPlayer, getGameEventListeners, getName, getPlayer, getPlayers, getPlayerTurn, getPlayerTurnHistory, getStartTime, getTurn, getTurnHistory, getWinner, removeGameEventListener, setEndTime, setFirstPlayer, setPlayers, setStartTime, setWinner
 
Methods inherited from class org.dartra.standard.PersistentObject
getId, setId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.dartra.framework.Game
addGameEventListener, getBoard, getEndTime, getFirstPlayer, getGameEventListeners, getName, getPlayer, getPlayers, getPlayerTurn, getPlayerTurnHistory, getStartTime, getTurn, getTurnHistory, getWinner, removeGameEventListener, setFirstPlayer, setWinner
 
Methods inherited from interface org.dartra.framework.Persistent
getId, setId
 

Constructor Detail

BestOfMatch

public BestOfMatch(java.lang.String name,
                   Board board,
                   StringProperties props)

BestOfMatch

public BestOfMatch(java.lang.String name,
                   Board board,
                   int bestOf,
                   boolean determineFirstPlayer)

BestOfMatch

public BestOfMatch(java.lang.String name,
                   Board board,
                   Player[] players,
                   StringProperties props)

BestOfMatch

public BestOfMatch(java.lang.String name,
                   Board board,
                   Player[] players,
                   int bestOf,
                   boolean determineFirstPlayer)
Method Detail

createNewGame

protected abstract Game createNewGame()

Subclasses should define this method appropriately.


start

public void start()

Starts the best-of match. Sets the starting time, and starts a closest-to-zone game first, if required to do so.

Specified by:
start in interface Game
Specified by:
start in class StandardMatch

startNewGame

protected void startNewGame()

Starts a new game in this match.


getPlayerScore

public Score getPlayerScore(Player player)

Returns the player score for this match, this is the number of games the given player has won in this match.


checkMatchWinner

protected void checkMatchWinner()

Checks if this match has a winner: goes through the games that have been played, and checks if one player has won more than half of the games of this match.

If a match winner is found, it will be set using setWinner().


countGamesWon

protected int countGamesWon(Player player)

Counts the number of games the given player has won so far in this match.


getPlayerArray

protected Player[] getPlayerArray()

Returns the array with the players of this match.


getBestOf

public int getBestOf()

Returns the best-of (the maximum number of games) for this match.


toString

public java.lang.String toString()
Overrides:
toString in class StandardGame

getProperties

public StringProperties getProperties()
Description copied from class: StandardGame

Subclasses should implement this to properly return their game specific properties (for instance the "start score" for an x01 game).

It is legal to return null if there are no game specific properties.

Specified by:
getProperties in class StandardGame