-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreversiwidget.h
97 lines (61 loc) · 2.5 KB
/
reversiwidget.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef REVERSIWIDGET_H
#define REVERSIWIDGET_H
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "reversifwd.h"
#include "reversiplayer.h"
#include "reversiwinner.h"
namespace ribi {
struct TextCanvas;
namespace reversi {
///Widget is higher level interface of the Reversi Board:
///Widget keeps track of the current player its turn and allows undoing of moves
struct Widget
{
Widget(const int size = 10);
//Need deep copies, due to m_board
Widget(const Widget& other);
//Need deep copies, due to m_board
Widget& operator=(const Widget& other);
bool CanDoMove(const boost::shared_ptr<const Move> move) const noexcept;
void DoMove(const boost::shared_ptr<const Move> move) noexcept;
const boost::shared_ptr<const Board> GetBoard() const noexcept { return m_board; }
const boost::shared_ptr< Board> GetBoard() noexcept { return m_board; }
Player GetCurrentPlayer() const noexcept { return m_current_player; }
const std::vector<boost::shared_ptr<Move>> GetValidMoves() const noexcept;
static std::string GetVersion() noexcept;
static std::vector<std::string> GetVersionHistory() noexcept;
Winner GetWinner() const noexcept;
const boost::shared_ptr<TextCanvas> ToTextCanvas() const noexcept;
void Undo();
private:
boost::shared_ptr<Board> m_board;
///The player to do a move; the player to control the selector
Player m_current_player;
//The undo stack (use std::vector because it is a true STL container)
//first: the Widget before the Move
//second: the last Move done in the game
std::vector<std::pair<boost::shared_ptr<Widget>,boost::shared_ptr<const Move>>> m_undo;
///The x coordinat of the selector
int m_x;
///The y coordinat of the selector
int m_y;
bool CanDoMove(const int x, const int y) const noexcept;
bool CanDoMovePass() const noexcept;
///Create the delta-x and delta-y to search in the 8 directions
static const std::vector<std::pair<int,int>> CreateDeltas() noexcept;
void DoMove(const int x, const int y) noexcept;
void DoMovePass() noexcept;
Player GetOtherPlayer() const noexcept;
//Simply sets a square
//void Set(const int x, const int y, const int state) noexcept;
void TogglePlayer();
friend bool operator==(const Widget& lhs, const Widget& rhs);
};
bool operator==(const Widget& lhs, const Widget& rhs);
bool operator!=(const Widget& lhs, const Widget& rhs);
std::ostream& operator<<(std::ostream& os, const Widget& r);
} //~namespace reversi
} //~namespace ribi
#endif // REVERSIWIDGET_H