Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

SgTimeRecord Class Reference

#include <SgTimeRecord.h>

List of all members.


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 47 of file SgTimeRecord.h.

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.


Constructor & Destructor Documentation

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

Definition at line 23 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 39 of file SgTimeRecord.cpp.

References SG_ASSERT, and SG_DEBUG_ONLY.

SgTimeRecord::~SgTimeRecord (  ) 

Definition at line 224 of file SgTimeRecord.h.


Member Function Documentation

bool SgTimeRecord::ClockIsRunning (  )  const

Definition at line 228 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 161 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 76 of file SgTimeRecord.cpp.

References m_clockIsOn, m_suspended, SG_CLOCK_OFF, SG_CLOCK_RUNNING, and SG_CLOCK_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 66 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 56 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 233 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 238 of file SgTimeRecord.h.

References m_movesLeft.

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

int SgTimeRecord::OTNumMoves (  )  const

Definition at line 243 of file SgTimeRecord.h.

References m_overtimeNumMoves.

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

double SgTimeRecord::OTPeriod (  )  const

Definition at line 248 of file SgTimeRecord.h.

References m_overtimePeriod.

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

double SgTimeRecord::Overhead (  )  const

Definition at line 253 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 175 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 120 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 258 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 263 of file SgTimeRecord.h.

References m_movesLeft, and SG_ASSERT.

void SgTimeRecord::SetOTNumMoves ( int  numMoves  ) 

Definition at line 268 of file SgTimeRecord.h.

References m_overtimeNumMoves.

Referenced by SgNodeUtil::UpdateTime().

void SgTimeRecord::SetOTPeriod ( double  period  ) 

Definition at line 273 of file SgTimeRecord.h.

References m_overtimePeriod.

Referenced by SgNodeUtil::UpdateTime().

void SgTimeRecord::SetOverhead ( double  overhead  ) 

Definition at line 278 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 92 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 283 of file SgTimeRecord.h.

References m_timeLeft.

void SgTimeRecord::SuspendClock (  ) 

Set the clock into suspended state.

Definition at line 111 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 86 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 98 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 133 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

Definition at line 288 of file SgTimeRecord.h.

References m_overtimeNumMoves.

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


Friends And Related Function Documentation

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

Output SgTimeRecord to stream.

Definition at line 206 of file SgTimeRecord.cpp.


Member Data Documentation

SgNode* SgTimeRecord::m_atNode [private]

The current node at which the time is running.

Definition at line 207 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 199 of file SgTimeRecord.h.

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

bool SgTimeRecord::m_loseOnTime [private]

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

Definition at line 191 of file SgTimeRecord.h.

Referenced by LoseOnTime(), and SetLoseOnTime().

SgBWArray<int> SgTimeRecord::m_movesLeft [private]

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

This is zero if game is in main time.

Definition at line 218 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 188 of file SgTimeRecord.h.

Referenced by Overhead(), and SetOverhead().

int SgTimeRecord::m_overtimeNumMoves [private]

How many moves to play in one overtime period.

zero if there is no overtime.

Definition at line 180 of file SgTimeRecord.h.

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

double SgTimeRecord::m_overtimePeriod [private]

The length of one overtime period.

Definition at line 183 of file SgTimeRecord.h.

Referenced by OTPeriod(), and SetOTPeriod().

SgBlackWhite SgTimeRecord::m_player [private]

The player whose clock is running.

Only relevant if the clock is running.

Definition at line 196 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 204 of file SgTimeRecord.h.

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

SgBWArray<double> SgTimeRecord::m_timeLeft [private]

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 213 of file SgTimeRecord.h.

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

double SgTimeRecord::m_timeOfLastUpdate [private]

The time at which fTimeLeft was last updated.

Definition at line 221 of file SgTimeRecord.h.

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


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


17 Jun 2010 Doxygen 1.4.7