Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  
Public Member Functions | Private Attributes | Related Functions

SgTimeRecord Class Reference

A time record contains time-related information. More...

#include <SgTimeRecord.h>

List of all members.

Public Member Functions

 SgTimeRecord (int numMoves=0, double period=0, double overhead=0, bool loseOnTime=false)
 SgTimeRecord (bool oneMoveOnly, double timeForMove)
 Constructor.
 ~SgTimeRecord ()
Time settings for the game

bool UseOvertime () const
int OTNumMoves () const
double OTPeriod () const
double Overhead () const
bool LoseOnTime () const
void SetOTNumMoves (int numMoves)
void SetOTPeriod (double period)
void SetOverhead (double overhead)
void SetLoseOnTime (bool lose)
Clock state

SgClockState GetClockState () const
 Return the state of the clock: stopped, running, or suspended.
bool ClockIsRunning () const
double TimeLeft (SgBlackWhite player) const
 Returns the current time left.
int MovesLeft (SgBlackWhite color) const
 The number of moves left to play in this overtime period.
void SetTimeLeft (SgBlackWhite color, double timeLeft)
void TurnClockOn (bool turnOn)
 Turn the clock on or off.
void SetMovesLeft (SgBlackWhite color, int moves)
 Set number of moves left to play in this overtime period.
void SuspendClock ()
 Set the clock into suspended state.
void UpdateTimeLeft ()
 Update the internal m_timeLeft.
Functions for using the clock in a game

void EnterNode (SgNode &node, SgBlackWhite player)
 Called by GoGame to react to user events.
void PlayedMove (SgNode &node, SgBlackWhite player)
 Called by GoGame to react to user events.
void SetClock (SgNode &node, SgBlackWhite player, double time)
 Set time left and store it as a property in the tree.

Static Public Member Functions

Utility functions

static SgBWArray< double > GetTimeFromTree (SgNode &node)
 Returns the time stored at the given node or its most recent ancestor.
static SgBWArray< int > GetOTMovesFromTree (SgNode &node)
 Returns the number of moves left to play in overtime as determined by the given node or an ancestor with that property.
static void SetTimeInTree (SgNode &node, SgBWArray< double > time)
 Sets the time property at the given node for both players.

Private Attributes

int m_overtimeNumMoves
 How many moves to play in one overtime period.
double m_overtimePeriod
 The length of one overtime period.
double m_overhead
 How much time to subtract for each move due to time used by the operator of the program (move entry, etc.
bool m_loseOnTime
 Whether to end the game when a player has negative time left.
SgBlackWhite m_player
 The player whose clock is running.
bool m_clockIsOn
 Whether the clock is turned on and running.
bool m_suspended
 Whether the clock is suspended.
SgNodem_atNode
 The current node at which the time is running.
SgBWArray< double > m_timeLeft
 The time left for both players.
SgBWArray< int > m_movesLeft
 The number of moves left to play in this overtime period.
double m_timeOfLastUpdate
 The time at which fTimeLeft was last updated.

Related Functions

(Note that these are not member functions.)



std::ostream & operator<< (std::ostream &out, const SgTimeRecord &time)
 Output SgTimeRecord to stream.

Detailed Description

A time record contains time-related information.

How much time each player has left, how overtime is regulated, and how many moves there are left in this overtime period. This information is updated when replaying a game depending on time-related properties stored in the game tree.

A time contest: dynamic time record of an ongoing game. The time left at each point in the game is stored as properties in the tree. The time stored is the time left when entering a new node; the time left while the clock is running at a node is not stored anywhere except in the TimeContest object. Thus leaving a node and returning to it later will restore the time left when first entering the node, not when leaving the node.

Definition at line 45 of file SgTimeRecord.h.


Constructor & Destructor Documentation

SgTimeRecord::SgTimeRecord ( int  numMoves = 0,
double  period = 0,
double  overhead = 0,
bool  loseOnTime = false 
) [explicit]

Definition at line 22 of file SgTimeRecord.cpp.

SgTimeRecord::SgTimeRecord ( bool  oneMoveOnly,
double  timeForMove 
)

Constructor.

'oneMoveOnly' must be true for the second constructor (just to distinguish the two constructors). The second one creates a time record that can be used to set a specific time period for one move only.

Definition at line 38 of file SgTimeRecord.cpp.

References SG_ASSERT, and SG_DEBUG_ONLY.

SgTimeRecord::~SgTimeRecord (  ) 

Definition at line 206 of file SgTimeRecord.h.


Member Function Documentation

bool SgTimeRecord::ClockIsRunning (  )  const

Definition at line 210 of file SgTimeRecord.h.

References m_clockIsOn.

Referenced by operator<<().

void SgTimeRecord::EnterNode ( SgNode node,
SgBlackWhite  player 
)

Called by GoGame to react to user events.

Called when a node is entered after moving in the tree or just to refresh the current state If the clock is on and the node is not m_atNode, the clock is suspended. m_player is set to the given player, and m_timeLeft is set to reflect the time left at that node.

Definition at line 160 of file SgTimeRecord.cpp.

References GetOTMovesFromTree(), GetTimeFromTree(), m_atNode, m_clockIsOn, m_movesLeft, m_player, m_timeLeft, and SuspendClock().

SgClockState SgTimeRecord::GetClockState (  )  const

Return the state of the clock: stopped, running, or suspended.

Definition at line 75 of file SgTimeRecord.cpp.

References m_clockIsOn, and m_suspended.

Referenced by operator<<().

SgBWArray< int > SgTimeRecord::GetOTMovesFromTree ( SgNode node  )  [static]

Returns the number of moves left to play in overtime as determined by the given node or an ancestor with that property.

Definition at line 65 of file SgTimeRecord.cpp.

References SgNode::GetIntProp(), SG_BLACK, SG_PROP_OT_BLACK, SG_PROP_OT_WHITE, SG_WHITE, and SgNode::TopProp().

Referenced by EnterNode().

SgBWArray< double > SgTimeRecord::GetTimeFromTree ( SgNode node  )  [static]

Returns the time stored at the given node or its most recent ancestor.

Definition at line 55 of file SgTimeRecord.cpp.

References SgNode::GetRealProp(), SG_BLACK, SG_PROP_TIME_BLACK, SG_PROP_TIME_WHITE, SG_WHITE, and SgNode::TopProp().

Referenced by EnterNode().

bool SgTimeRecord::LoseOnTime (  )  const

Definition at line 215 of file SgTimeRecord.h.

References m_loseOnTime.

Referenced by operator<<(), and UpdateTimeLeft().

int SgTimeRecord::MovesLeft ( SgBlackWhite  color  )  const

The number of moves left to play in this overtime period.

This is zero if the game is in main time.

Definition at line 220 of file SgTimeRecord.h.

References m_movesLeft.

Referenced by operator<<(), and SgDefaultTimeControl::TimeForCurrentMove().

int SgTimeRecord::OTNumMoves (  )  const
double SgTimeRecord::OTPeriod (  )  const
double SgTimeRecord::Overhead (  )  const

Definition at line 235 of file SgTimeRecord.h.

References m_overhead.

Referenced by operator<<(), PlayedMove(), and SgDefaultTimeControl::TimeForCurrentMove().

void SgTimeRecord::PlayedMove ( SgNode node,
SgBlackWhite  player 
)

Called by GoGame to react to user events.

Called when a move was played on the board. If the clock was suspended, the clock is turned back on. Otherwise, if the clock was running, the time left is stored as properties in the new node.

Definition at line 174 of file SgTimeRecord.cpp.

References SgNode::HasSon(), m_atNode, m_clockIsOn, m_movesLeft, m_suspended, m_timeLeft, OTNumMoves(), OTPeriod(), Overhead(), SgProp::PlayerProp(), SgNode::SetIntProp(), SgNode::SetRealProp(), SG_PROP_OT_BLACK, SG_PROP_TIME_BLACK, SgDebug(), TurnClockOn(), UpdateTimeLeft(), and UseOvertime().

void SgTimeRecord::SetClock ( SgNode node,
SgBlackWhite  player,
double  time 
)

Set time left and store it as a property in the tree.

If time is <= 0, puts it into overtime.

Definition at line 119 of file SgTimeRecord.cpp.

References SgTime::Get(), m_movesLeft, m_player, m_timeLeft, m_timeOfLastUpdate, OTNumMoves(), OTPeriod(), SgProp::PlayerProp(), SgNode::SetRealProp(), and SG_PROP_TIME_BLACK.

void SgTimeRecord::SetLoseOnTime ( bool  lose  ) 

Definition at line 240 of file SgTimeRecord.h.

References m_loseOnTime.

Referenced by SgNodeUtil::UpdateTime().

void SgTimeRecord::SetMovesLeft ( SgBlackWhite  color,
int  moves 
)

Set number of moves left to play in this overtime period.

This is zero if the game is in main time.

Definition at line 245 of file SgTimeRecord.h.

References m_movesLeft, and SG_ASSERT.

void SgTimeRecord::SetOTNumMoves ( int  numMoves  ) 

Definition at line 250 of file SgTimeRecord.h.

References m_overtimeNumMoves.

Referenced by SgNodeUtil::UpdateTime().

void SgTimeRecord::SetOTPeriod ( double  period  ) 

Definition at line 255 of file SgTimeRecord.h.

References m_overtimePeriod.

Referenced by SgNodeUtil::UpdateTime().

void SgTimeRecord::SetOverhead ( double  overhead  ) 

Definition at line 260 of file SgTimeRecord.h.

References m_overhead.

Referenced by SgNodeUtil::UpdateTime().

void SgTimeRecord::SetTimeInTree ( SgNode node,
SgBWArray< double >  time 
) [static]

Sets the time property at the given node for both players.

Definition at line 91 of file SgTimeRecord.cpp.

References SgNode::SetRealProp(), SG_BLACK, SG_PROP_TIME_BLACK, SG_PROP_TIME_WHITE, and SG_WHITE.

void SgTimeRecord::SetTimeLeft ( SgBlackWhite  color,
double  timeLeft 
)

Definition at line 265 of file SgTimeRecord.h.

References m_timeLeft.

void SgTimeRecord::SuspendClock (  ) 

Set the clock into suspended state.

Definition at line 110 of file SgTimeRecord.cpp.

References m_clockIsOn, and m_suspended.

Referenced by EnterNode(), and UpdateTimeLeft().

double SgTimeRecord::TimeLeft ( SgBlackWhite  player  )  const

Returns the current time left.

Call UpdateTimeLeft first to get the newest information.

Definition at line 85 of file SgTimeRecord.cpp.

References m_timeLeft, and SG_ASSERT_BW.

Referenced by operator<<(), and SgDefaultTimeControl::TimeForCurrentMove().

void SgTimeRecord::TurnClockOn ( bool  turnOn  ) 

Turn the clock on or off.

Todo:
Set gUserAbort if the time is turned off, so that for example a search is aborted.

Definition at line 97 of file SgTimeRecord.cpp.

References SgTime::Get(), m_clockIsOn, m_suspended, m_timeOfLastUpdate, and UpdateTimeLeft().

Referenced by PlayedMove().

void SgTimeRecord::UpdateTimeLeft (  ) 

Update the internal m_timeLeft.

If the time left is negative, m_movesLeft is set if overtime is starting, or a "lost on time" is shown if m_loseOnTime is true.

Definition at line 132 of file SgTimeRecord.cpp.

References SgTime::Get(), LoseOnTime(), m_clockIsOn, m_movesLeft, m_player, m_timeLeft, m_timeOfLastUpdate, OTNumMoves(), OTPeriod(), SgDebug(), SuspendClock(), and UseOvertime().

Referenced by PlayedMove(), and TurnClockOn().

bool SgTimeRecord::UseOvertime (  )  const

Friends And Related Function Documentation

std::ostream & operator<< ( std::ostream &  out,
const SgTimeRecord time 
) [related]

Output SgTimeRecord to stream.

Definition at line 205 of file SgTimeRecord.cpp.


Member Data Documentation

The current node at which the time is running.

Definition at line 191 of file SgTimeRecord.h.

Referenced by EnterNode(), and PlayedMove().

bool SgTimeRecord::m_clockIsOn [private]

Whether the clock is turned on and running.

Definition at line 184 of file SgTimeRecord.h.

Referenced by ClockIsRunning(), EnterNode(), GetClockState(), PlayedMove(), SuspendClock(), TurnClockOn(), and UpdateTimeLeft().

Whether to end the game when a player has negative time left.

Definition at line 177 of file SgTimeRecord.h.

Referenced by LoseOnTime(), and SetLoseOnTime().

The number of moves left to play in this overtime period.

This is zero if game is in main time.

Definition at line 200 of file SgTimeRecord.h.

Referenced by EnterNode(), MovesLeft(), PlayedMove(), SetClock(), SetMovesLeft(), and UpdateTimeLeft().

double SgTimeRecord::m_overhead [private]

How much time to subtract for each move due to time used by the operator of the program (move entry, etc.

).

Definition at line 174 of file SgTimeRecord.h.

Referenced by Overhead(), and SetOverhead().

How many moves to play in one overtime period.

zero if there is no overtime.

Definition at line 167 of file SgTimeRecord.h.

Referenced by OTNumMoves(), SetOTNumMoves(), and UseOvertime().

The length of one overtime period.

Definition at line 170 of file SgTimeRecord.h.

Referenced by OTPeriod(), and SetOTPeriod().

The player whose clock is running.

Only relevant if the clock is running.

Definition at line 181 of file SgTimeRecord.h.

Referenced by EnterNode(), SetClock(), and UpdateTimeLeft().

bool SgTimeRecord::m_suspended [private]

Whether the clock is suspended.

Note: m_clockIsOn and m_suspended cannot both be true.

Definition at line 188 of file SgTimeRecord.h.

Referenced by GetClockState(), PlayedMove(), SuspendClock(), and TurnClockOn().

The time left for both players.

This is updated frequently, reflecting the time stored in fAtNode minus the time spent at that node.

Definition at line 196 of file SgTimeRecord.h.

Referenced by EnterNode(), PlayedMove(), SetClock(), SetTimeLeft(), TimeLeft(), and UpdateTimeLeft().

The time at which fTimeLeft was last updated.

Definition at line 203 of file SgTimeRecord.h.

Referenced by SetClock(), TurnClockOn(), and UpdateTimeLeft().


The documentation for this class was generated from the following files:


Sun Mar 13 2011 Doxygen 1.7.1