Wizard
Software Engineering Project - Wizard
Loading...
Searching...
No Matches
game_state.h
1// all in this block is only included if wizard_game_state_h hasnt already been included to prevent to include twice
2#ifndef WIZARD_GAME_STATE_H
3#define WIZARD_GAME_STATE_H
4
5#include <vector>
6#include <algorithm>
7#include <ranges>
8#include <string>
9#include "../../rapidjson/include/rapidjson/document.h"
10#include "player/player.h"
11#include "cards/deck.h"
12#include "cards/card.h"
13#include "cards/trick.h"
14#include "../serialization/serializable.h"
15#include "../serialization/serializable_value.h"
16#include "../serialization/unique_serializable.h"
17
19private:
20
21 static const int _max_nof_players = 6;
22 static const int _min_nof_players = 3;
23
24 std::vector<player*> _players;
25 deck* _deck;
26 trick* _trick; // only save current trick, won tricks are saved with the players
27
28 serializable_value<bool>* _is_started;
29 serializable_value<bool>* _is_finished;
30 serializable_value<bool>* _is_estimation_phase;
31 //TODO: possibly add boolean _determine_trump_color that can be used to tell player to decide on a trump color
32
33 serializable_value<int>* _round_number;
34 serializable_value<int>* _trick_number;
35 serializable_value<int>* _starting_player_idx;
36 serializable_value<int>* _trick_starting_player_idx;
37 serializable_value<int>* _current_player_idx;
38 serializable_value<int>* _trump_color;
39 serializable_value<int>* _trick_estimate_sum;
40
41
42 // from_diff constructor, new game is constructed
43 explicit game_state(std::string id);
44
45 // deserialization constructor
47 std::string id,
48 std::vector<player*>& players,
49 deck* deck,
50 trick* trick,
51
52 serializable_value<bool>* is_started,
53 serializable_value<bool>* is_finished,
54 serializable_value<bool>* is_estimation_phase,
55
56 serializable_value<int>* round_number,
57 serializable_value<int>* trick_number,
58 serializable_value<int>* starting_player_idx,
59 serializable_value<int>* trick_starting_player_idx,
60 serializable_value<int>* current_player_idx,
61 serializable_value<int>* trump_color,
62 serializable_value<int>* trick_estimate_sum
63 );
64
65 // returns the index of 'player' in the '_players' vector
66 int get_player_index(player* player) const;
67 // TODO: these two functions are in the server part in cpp, where do they belong?
68 int get_number_of_turns();
69 void determine_trump_color();
70
71public:
72 game_state();
73 ~game_state() override;
74
75// accessors
76 bool is_full() const;
77 bool is_started() const;
78 bool is_finished() const;
79 bool is_estimation_phase() const;
80 bool is_player_in_game(player* player) const;
81 int get_round_number() const;
82 int get_trick_number() const;
83 int get_trick_estimate_sum() const;
84 int get_max_round_number() const;
85 int get_trump_color() const;
86 player* get_current_player() const;
87 player* get_trick_starting_player() const;
88 player* get_starting_player() const;
89 trick* get_trick() const;
90 std::vector<player*>& get_players();
91
92
93// all in block behind ifdef is only included if wizard server is defined
94// TODO: remove // before ifdef and endif below (if it is still there otherwise ignore this)
95#ifdef WIZARD_SERVER
96// server-side state update functions
97 bool remove_player(player* player, std::string& err);
98 bool add_player(player* player, std::string& err);
99 bool start_game(std::string& err);
100 bool finish_game(std::string& err);
101
102 void setup_round(std::string& err); // server side initialization
103 void wrap_up_round(std::string& err);
104 bool estimate_tricks(player *player, std::string &err, int trick_estimate);
105 bool can_be_played(player* player, const card* card, std::string& err) const noexcept;
106 bool play_card(player* player, const std::string& card_id, std::string& err);
107 bool update_current_player(std::string& err);
108
109#endif
110
111// serializable interface
112 void write_into_json(rapidjson::Value& json, rapidjson::Document::AllocatorType& allocator) const override;
113 static game_state* from_json(const rapidjson::Value& json);
114
115};
116
117
118#endif //WIZARD_GAME_STATE_H
Represents a card in the game.
Definition card.h:15
Represents the card deck in the game.
Definition deck.h:28
Definition game_state.h:18
Represents a player in the game.
Definition player.h:18
Definition serializable_value.h:27
Represents the trick in the game.
Definition trick.h:28
Definition unique_serializable.h:12