-
Notifications
You must be signed in to change notification settings - Fork 2
/
scrabble_config.hpp
95 lines (77 loc) · 4.18 KB
/
scrabble_config.hpp
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
#ifndef scrabble_config_h
#define scrabble_config_h
#include <iostream>
#include <string>
#include <vector>
//struct _object;
//typedef _object PyObject;
using PyObject = bool(unsigned, unsigned, unsigned*, unsigned*, char*);
enum Board_Type {STANDARD_BOARD, WWF_BOARD, WWF_SOLO_BOARD};
enum Player_Type {HUMAN, AI};
enum Piece_Source_Type {STANDARD_SOURCE, WWF_SOURCE};
enum Output_Type {TEXT, GUI, EXPERIMENT};
enum GUI_Event {TILES, AI_PLAY, GAME_INIT, BOARD_INIT, CHECK_PLAY, CONFIRM_PLAY, CHECK_HINT, GIVE_HINT, CHECK_SAVE};
/**
* This class encapsulates everything that is configurable in this program.
* Note that this class is a singleton.
*/
////////////////////////////////////////////////////////////////////////////////
class Scrabble_Config
////////////////////////////////////////////////////////////////////////////////
{
public:
Scrabble_Config(std::istream& in, Output_Type output, PyObject* py = nullptr);
Scrabble_Config(unsigned num_players,
const std::vector<Player_Type>& player_types,
const std::vector<std::string>& player_names,
unsigned num_player_pieces = 7,
Board_Type board_type = STANDARD_BOARD,
Output_Type output = TEXT,
bool color_output = true,
bool clear_screen_before_output = true,
const std::string& dictionary = "TWL06.txt",
Piece_Source_Type piece_source_type = STANDARD_SOURCE,
unsigned max_num_log_msgs_to_displ = 10,
unsigned constrained_square_limit = 3,
PyObject* py = nullptr);
unsigned NUM_PLAYERS() const { return m_num_players ; }
const std::vector<Player_Type>& PLAYER_TYPES() const { return m_player_types ; }
const std::vector<std::string>& PLAYER_NAMES() const { return m_player_names ; }
unsigned NUM_PLAYER_PIECES() const { return m_num_player_pieces ; }
Board_Type BOARD_TYPE() const { return m_board_type ; }
Output_Type OUTPUT() const { return m_output ; }
bool COLOR_OUTPUT() const { return m_color_output ; }
bool CLEAR_SCREEN_BEFORE_OUTPUT() const { return m_clear_screen_before_output; }
const std::string& DICTIONARY() const { return m_dictionary ; }
Piece_Source_Type PIECE_SOURCE_TYPE() const { return m_piece_source_type ; }
unsigned MAX_NUM_LOG_MSGS_TO_DISPL() const { return m_max_num_log_msgs_to_displ ; }
unsigned CONSTRAINED_SQUARE_LIMIT() const { return m_constrained_square_limit ; }
PyObject* PY_CALLBACK() const { return m_py ; }
static Board_Type str_to_board(const std::string& board_str);
static Piece_Source_Type str_to_tileset(const std::string& tileset_str);
/**
* operator<< - produces a nice-looking output that should convey the configuration
*/
std::ostream& operator<<(std::ostream& out) const;
/**
* disable color output - useful when saving
*/
void disable_colors() const { m_color_output = false; }
void enable_colors() const { m_color_output = true; }
private:
unsigned m_num_players;
std::vector<Player_Type> m_player_types;
std::vector<std::string> m_player_names;
unsigned m_num_player_pieces;
Board_Type m_board_type;
Output_Type m_output;
mutable bool m_color_output;
bool m_clear_screen_before_output;
std::string m_dictionary;
Piece_Source_Type m_piece_source_type;
unsigned m_max_num_log_msgs_to_displ;
unsigned m_constrained_square_limit;
PyObject* m_py;
};
std::ostream& operator<<(std::ostream& out, const Scrabble_Config& config);
#endif