A time record contains time-related information. More...
#include <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. | |
SgNode * | m_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. |
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.
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.
bool SgTimeRecord::ClockIsRunning | ( | ) | const |
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<<().
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().
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 |
Definition at line 225 of file SgTimeRecord.h.
References m_overtimeNumMoves.
Referenced by operator<<(), PlayedMove(), SetClock(), SgDefaultTimeControl::TimeForCurrentMove(), and UpdateTimeLeft().
double SgTimeRecord::OTPeriod | ( | ) | const |
Definition at line 230 of file SgTimeRecord.h.
References m_overtimePeriod.
Referenced by operator<<(), PlayedMove(), SetClock(), SgDefaultTimeControl::TimeForCurrentMove(), and UpdateTimeLeft().
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().
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.
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 |
Definition at line 270 of file SgTimeRecord.h.
References m_overtimeNumMoves.
Referenced by operator<<(), PlayedMove(), SgDefaultTimeControl::TimeForCurrentMove(), and UpdateTimeLeft().
std::ostream & operator<< | ( | std::ostream & | out, | |
const SgTimeRecord & | time | |||
) | [related] |
Output SgTimeRecord to stream.
Definition at line 205 of file SgTimeRecord.cpp.
SgNode* SgTimeRecord::m_atNode [private] |
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().
bool SgTimeRecord::m_loseOnTime [private] |
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().
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 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().
int SgTimeRecord::m_overtimeNumMoves [private] |
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().
double SgTimeRecord::m_overtimePeriod [private] |
The length of one overtime period.
Definition at line 170 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 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().
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 196 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 203 of file SgTimeRecord.h.
Referenced by SetClock(), TurnClockOn(), and UpdateTimeLeft().