-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtictactoegame.h
78 lines (53 loc) · 1.9 KB
/
tictactoegame.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef TICTACTOEGAME_H
#define TICTACTOEGAME_H
#include <iostream>
#include <boost/shared_ptr.hpp>
#include <boost/signals2.hpp>
#include "tictactoeplayer.h"
#include "tictactoewinner.h"
#include "tictactoefwd.h"
namespace ribi {
namespace tictactoe {
///Manages a Board to follow the rules
struct Game
{
Game() noexcept;
///Can the current player put his/her character at (x,y)?
bool CanDoMove(const int x, const int y) const noexcept;
///DoMove lets the current player put his/her token at a certain position on the board.
void DoMove(const int x, const int y) noexcept;
boost::shared_ptr<const Board> GetBoard() const noexcept;
///GetCurrentPlayer returns whose turn it is.
Player GetCurrentPlayer() const noexcept { return m_current_player; }
///GetCurrentTurn returns the turn number.
int GetCurrentTurn() const noexcept;
///GetSummarizedState returns an integer summarizing the
///state, which is both tic-tac-toe board and whose turn it is.
///In trinary, for lowest order digit:\n
///# : content\n
///0-8: board
///9 : current turn\n
///The current turn is stored as:\n
///[#] : description\n
/// 0 : ERROR\n
/// 1 : player1\n
/// 2 : player2\n
int GetSummarizedState() const noexcept;
static std::string GetVersion() noexcept;
static std::vector<std::string> GetVersionHistory() noexcept;
Winner GetWinner() const noexcept;
void Restart() noexcept;
///SetSummarizedState sets the game its state
void SetSummarizedState(const int state) noexcept;
///Just display it as a string
std::string ToTextCanvas() const noexcept;
boost::signals2::signal<void(Game*)> m_signal_changed;
private:
boost::shared_ptr<Board> m_board;
Player m_current_player;
};
std::ostream& operator<<(std::ostream& os,const Game& t) noexcept;
bool operator==(const Game& lhs, const Game& rhs) noexcept;
} //~namespace tictactoe
} //~namespace ribi
#endif // TICTACTOEGAME_H