TheChess
Public Types | Public Member Functions | Static Public Member Functions

thechess::model::Game Class Reference

Dbo-model that represents one game beetween two users. More...

#include "model/Game.hpp"

Inheritance diagram for thechess::model::Game:
Inheritance graph
[legend]
Collaboration diagram for thechess::model::Game:
Collaboration graph
[legend]

List of all members.

Public Types

enum  State {
  proposed = 0, confirmed = 10, active = 20, pause = 30,
  draw_stalemate = 50, draw_agreed = 51, draw_50 = 52, draw_3 = 53,
  draw_2_kings = 54, surrendered = 61, timeout = 62, cancelled = 63,
  mate = 64, no_draw_stalemate = 65
}

Public Member Functions

void pgn (std::ostream &out, bool reduced=false) const
 Write PGN representation of game to stream.
Creation of game
 Game (bool)
 Create new game to be added to database.
void propose_game (UserPtr init, UserPtr u, chess::Color c)
 Turn this game into game proposed by one user to another.
void propose_challenge (UserPtr init, chess::Color c)
 Turn this game into challenge by one user.
void make_competition_game (UserPtr white, UserPtr black, CompetitionPtr competition, int competition_stage=-1, bool random=false)
 Turn this game into competition game.
Checking
void check (Objects &objects)
 Run self-checks for planned action.
Wt::WDateTime next_check () const
 Return the datetime of next expected check.
Methods of pre-started state
bool is_challenge () const
 Return if the game is a challenge.
bool is_creation () const
 Return if the game is a creation.
bool can_join (UserPtr user) const
 Return if the user can join the game.
void join (UserPtr user)
 Try to join the user.
bool can_confirm (UserPtr user) const
 Return if user can confirm the game.
void confirm (UserPtr user)
 The user tries to confirm the game.
bool can_cancel (UserPtr user) const
 Return if user can cancel the game.
void cancel (UserPtr user)
 The user tries to cancel the game.
Pause management
bool can_pause_propose (const UserPtr user) const
 Return if user can propose a pause.
bool can_pause_propose (const UserPtr user, const Td &td) const
 Return if user can propose the pause for specified time.
void pause_propose (const UserPtr user, const Td &td)
 The user tries to propose the pause.
bool is_pause_proposed () const
 Return if the pause has been proposed.
const UserPtr pause_proposer () const
 Return the user proposed the pause.
Td pause_limit () const
 Return unused time that can be used for paused.
Td pause_proposed_td () const
 Return duration of the proposed pause.
const Wt::WDateTime & pause_until () const
 Return datetime when pause will be finished.
Wt::WDateTime pause_started () const
 Return datetime when pause has been started.
bool can_pause_agree (const UserPtr user) const
 Return if the user can agree with proposed pause.
void pause_agree (const UserPtr user)
 The user tries to agree with proposed pause.
bool can_pause_discard (const UserPtr user) const
 Return if the user can discard proposed pause.
void pause_discard (const UserPtr user)
 The user tries to discard proposed pause.
Mistake and rollback management
bool can_mistake_propose (const UserPtr user) const
 Return if the user can propose to rollback mistake.
bool can_mistake_propose (const UserPtr user, int mistake_move) const
 Return if the user can propose to rollback mistake at given move.
void mistake_propose (const UserPtr user, int mistake_move)
 The user tries to propose to rollback mistake.
bool is_mistake_proposed () const
 Return if the mistake is proposed to be rollbacked.
const UserPtr mistake_proposer () const
 Return the user proposed to rollback the mistake.
int mistake_move () const
 Return the move which is proposed to be rollbacked.
bool can_mistake_agree (const UserPtr user) const
 Return if the user can agree to rollback the mistake.
void mistake_agree (const UserPtr user)
 The user tries to agree to rollback mistake.
bool can_mistake_discard (const UserPtr user) const
 Return if the user can discard rollback the mistake.
void mistake_discard (const UserPtr user)
 The user tries to discard rollback mistake.
Draw by agreement
bool can_draw_propose (const UserPtr user) const
 Return if the user can propose a draw by agreement.
void draw_propose (const UserPtr user)
 The user tries to propose a draw by agreement.
const UserPtr draw_proposer () const
 Return the user proposed draw by agreement.
bool is_draw_proposed () const
 Return if the user has proposed the draw by agreement.
bool can_draw_agree (const UserPtr user) const
 Return if the user can agree with the draw by agreement.
void draw_agree (const UserPtr user)
 The user tries to agree with draw by agreement.
bool can_draw_discard (const UserPtr user) const
 Return if the user can discard the draw by agreement.
void draw_discard (const UserPtr user)
 The user tries to discard the draw by agreement.
Information about members
chess::Color order_color () const
 Return the active color.
UserPtr order_user () const
 Return the active user.
UserPtr init () const
 Return the user created the game.
UserPtr white () const
 Return the user playing white pieces.
UserPtr black () const
 Return the user playing black pieces.
UserPtr winner () const
 Return the winner.
chess::Color color_of (const UserPtr user) const
 Return the pieces color of given user.
bool is_member (const UserPtr user) const
 Return if the user is member of the game (black, white or init)
UserPtr user_of (chess::Color color) const
 Return the user playing pieces of given color.
UserPtr other_user (const UserPtr user) const
 Return another member of the game.
Information about game
int size () const
 Return the number of half-moves of the game.
int size_without_init () const
 Return the number of non-predetermined half-moves.
bool meet_first_draw () const
 Return if the game reached size, required for draw by agreement.
bool real_rating () const
 Return if the game is affecting rating of users.
int human_size () const
 Return the number of moves of the game.
bool is_ended () const
 Return if the game is ended, ie is a win, draw or cancelled.
bool is_draw () const
 Return if the game is a draw.
bool is_win () const
 Return if the game is a win.
Wt::WString str_state () const
 Return string representation of state.
State state () const
 Return state.
bool colors_random () const
 Return if pieces colors were distributed randomly.
int rating_after (chess::Color color) const
 Return elo rating of the user after the game if changed or -1.
Making a move
bool can_move (UserPtr user) const
 Return if given user can add a move to this game.
void add_move (const chess::Move &move, const chess::Board &board_after)
 Add move to game.
Datetimes and time durations
Td limit_private (chess::Color color) const
 Return private time limit of user of given color.
Td limit_private (UserPtr user) const
 Return private time limit of given user.
Td limit_private () const
 Return private time limit of active user.
const Wt::WDateTime & created () const
 Return datetime when game was created.
const Wt::WDateTime & when_confirmed () const
 Return datetime when game was confirmed.
const Wt::WDateTime & started () const
 Return datetime when game was started.
const Wt::WDateTime & lastmove () const
 Return (virtual) datetime of last move.
const Wt::WDateTime & ended () const
 Return datetime when game was started.
Td spent_time () const
 Return td that would be subtracted from limit of the active user.
Td spent_time (UserPtr user) const
 Return td that would be subtracted from limit of the given user.
Td total_limit (UserPtr user) const
 Return sum of limits of given user.
Td total_limit_now (UserPtr user) const
 Return sum of limits of given user taking spent time into account.
Td limit_private_now (UserPtr user) const
 Return private time limit taking spent time into account.
Td limit_std_now (UserPtr user) const
 Return standard time limit taking spent time into account.
Comment-related methods
const Wt::WString & comment () const
 Return text of comment of this game by members of game.
bool can_comment (const UserPtr user) const
 Return if the user can change the comment of the game.
void set_comment (const UserPtr user, const Wt::WString &t)
 The user tries to set the comment.
Competition-related methods
CompetitionPtr competition () const
 Return the competition to which the game is attributed.
int competition_stage () const
 Return stage of the competition if attributed else -1.
bool has_competition_confirmed (UserPtr user) const
 Return if user has confimed the competition game.
bool can_competition_confirm (UserPtr user) const
 Return if user can confime the competition game.
void competition_confirm (UserPtr user)
 The user tries to confirm the game.
bool can_competition_discard (UserPtr user) const
 Return if user can discard previously confimed competition game.
void competition_discard (UserPtr user)
 The user tries to discard previously confirmed competition game.
void confirm_by_competition ()
 Method should be called only from competition processing code.

Static Public Member Functions

static const char * state2str_id (State state)
 Convert given state to i18n id.

Detailed Description

Dbo-model that represents one game beetween two users.

How to add new game to database:

GamePtr game = session.add(new Game(true));

Member Enumeration Documentation

Enumerator:
proposed 

was proposed by user or planned by competition

confirmed 

is to be started when both users are online

active 

is running, clock is ticking

pause 

is paused until predefined time, clock is also paused

draw_stalemate 

ended with stalemate

draw_agreed 

ended with draw by agreement

draw_50 

ended because of 50 without pawn or takes

draw_3 

ended because same position repeated thrice

draw_2_kings 

ended with low material draw

surrendered 

ended because one of users surrendered

timeout 

ended because of timeout

cancelled 

ended because user cancelled it

mate 

ended with checkmate

no_draw_stalemate 

ended with stalemate, black wins


Constructor & Destructor Documentation

thechess::model::Game::Game ( bool  )

Create new game to be added to database.


Member Function Documentation

void thechess::model::Game::add_move ( const chess::Move move,
const chess::Board board_after 
)

Add move to game.

Method was added to avoid additional checking of move (optimization). You must check move yourself before call this method!

bool thechess::model::Game::can_cancel ( UserPtr  user) const

Return if user can cancel the game.

Non-init member of creation can confirm it

bool thechess::model::Game::can_confirm ( UserPtr  user) const

Return if user can confirm the game.

Non-init member of creation can confirm it

bool thechess::model::Game::can_join ( UserPtr  user) const

Return if the user can join the game.

Non-anonymous user can join to challenge made by other user.

void thechess::model::Game::cancel ( UserPtr  user)

The user tries to cancel the game.

On success the game changes its state to cancelled

void thechess::model::Game::check ( Objects &  objects)

Run self-checks for planned action.

Parameters:
objectscollection to expand with other modified dbo Object.

Possible changes caused by this method:

In the latter case, if the game is attributed to the competition, the competition is added to objects.

void thechess::model::Game::confirm ( UserPtr  user)

The user tries to confirm the game.

On success the game changes its state to confirmed

void thechess::model::Game::confirm_by_competition ( )

Method should be called only from competition processing code.

On success the game changes its state to confirmed

void thechess::model::Game::join ( UserPtr  user)

Try to join the user.

On success the game changes its state to confirmed

const Wt::WDateTime& thechess::model::Game::lastmove ( ) const [inline]

Return (virtual) datetime of last move.

If the game was paused, this datetime is modified to reflect pause

void thechess::model::Game::make_competition_game ( UserPtr  white,
UserPtr  black,
CompetitionPtr  competition,
int  competition_stage = -1,
bool  random = false 
)

Turn this game into competition game.

Parameters:
whitethe user playing white pieces
blackthe user playing black pieces
competitionthe parent competition
competition_stagestage of competition or -1 if not defined
randomif colors of pieces will be randomized
void thechess::model::Game::pgn ( std::ostream &  out,
bool  reduced = false 
) const

Write PGN representation of game to stream.

Parameters:
reducedwhether reduced export PGN format is used
See also:
http://cfajohnson.com/chess/SAN/SAN_DOC/Standard
http://www.chessclub.com/help/PGN-spec
void thechess::model::Game::propose_challenge ( UserPtr  init,
chess::Color  c 
)

Turn this game into challenge by one user.

Parameters:
initthe creator of game
ccolor of creator, none color meens random color
void thechess::model::Game::propose_game ( UserPtr  init,
UserPtr  u,
chess::Color  c 
)

Turn this game into game proposed by one user to another.

Parameters:
initthe creator of game
uuser to who game is proposed
ccolor of creator, or none color to set random colors

The documentation for this class was generated from the following files:
 All Classes Functions Enumerations Enumerator