Data Structures & Algorithms in C++
Goodrich, Tamassia, Mount and Goldwasser
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends
dsac::array::TicTacToe Class Reference

Maintains the state of a game of Tic-Tac-Toe. More...

#include <tic_tac_toe.h>

Collaboration diagram for dsac::array::TicTacToe:
Collaboration graph

Public Types

enum  Mark { X = 1 , Oh = -1 , EMPTY = 0 }
 

Public Member Functions

 TicTacToe ()
 Creates a new game with empty board and player X's turn.
 
void clear_board ()
 Resets the board for a new game.
 
Mark get_mark (int i, int j) const
 
void put_mark (int i, int j)
 
bool is_win (Mark mark)
 Checks whether the board configuration is a win for the given player.
 
Mark get_winner ()
 Returns the winning player's mark, or EMPTY to indicate a tie or unfinished game.
 

Friends

std::ostream & operator<< (std::ostream &out, TicTacToe game)
 Display board on output stream.
 

Detailed Description

Maintains the state of a game of Tic-Tac-Toe.

Member Enumeration Documentation

◆ Mark

Enumerator
Oh 
EMPTY 

Constructor & Destructor Documentation

◆ TicTacToe()

dsac::array::TicTacToe::TicTacToe ( )
inline

Creates a new game with empty board and player X's turn.

Here is the call graph for this function:

Member Function Documentation

◆ clear_board()

void dsac::array::TicTacToe::clear_board ( )
inline

Resets the board for a new game.

◆ get_mark()

Mark dsac::array::TicTacToe::get_mark ( int  i,
int  j 
) const
inline

Returns current content of position (i,j), which might be X, O, or EMPTY

Exceptions
invalid_argumentif (i,j) out of range
Returns
X, O or EMPTY

◆ get_winner()

Mark dsac::array::TicTacToe::get_winner ( )
inline

Returns the winning player's mark, or EMPTY to indicate a tie or unfinished game.

Here is the call graph for this function:

◆ is_win()

bool dsac::array::TicTacToe::is_win ( Mark  mark)
inline

Checks whether the board configuration is a win for the given player.

◆ put_mark()

void dsac::array::TicTacToe::put_mark ( int  i,
int  j 
)
inline

Puts a mark at position (i,j) for current player

Exceptions
invalid_argumentif (i,j) out of range or non-empty
Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
TicTacToe  game 
)
friend

Display board on output stream.


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