Skip to content
Snippets Groups Projects
Commit 02e4104f authored by Bariatti Francesco's avatar Bariatti Francesco
Browse files

Added comments in header

parent 906e7ced
No related branches found
No related tags found
No related merge requests found
...@@ -11,11 +11,11 @@ namespace game ...@@ -11,11 +11,11 @@ namespace game
{ {
struct morpion_state struct morpion_state
{ {
uint16_t cross_bitboard = 0; uint16_t cross_bitboard = 0; //bitboard with the played moves of the cross
uint16_t circle_bitboard = 0; uint16_t circle_bitboard = 0; //bitboard with the played moves of the circle
uint8_t total_moves = 0; uint8_t total_moves = 0; //Total played moves (<= 9)
bool first_player_win = false; bool first_player_win = false; //First player is always the cross
bool second_player_win = false; bool second_player_win = false; //Second player is always the circle
}; };
class morpion : public game<morpion_state> class morpion : public game<morpion_state>
...@@ -24,31 +24,31 @@ namespace game ...@@ -24,31 +24,31 @@ namespace game
morpion(); morpion();
morpion(const morpion& mor) = default; morpion(const morpion& mor) = default;
morpion& operator=(const morpion& mor) = default; morpion& operator=(const morpion& mor) = default;
bool end_of_game() const; bool end_of_game() const; //Is the game ended? (draw or won)
int value(std::uint8_t player) const; //Returns if the player win, loose or nothing int value(std::uint8_t player) const; //Returns if the player win, loose or nothing
bool won(std::uint8_t player) const; bool won(std::uint8_t player) const;
bool lost(std::uint8_t player) const; bool lost(std::uint8_t player) const;
bool draw(std::uint8_t player) const; bool draw(std::uint8_t player) const;
uint8_t current_player() const; uint8_t current_player() const; //The player that has to play next (at the beginning, the first player)
std::uint16_t number_of_moves() const; std::uint16_t number_of_moves() const; //Moves played until now
void play(std::uint16_t m); void play(std::uint16_t m); //Play a move (updates the state)
void undo(std::uint16_t m) {} void undo(std::uint16_t m) {}
std::string player_to_string(std::uint8_t player) const; std::string player_to_string(std::uint8_t player) const; //String representation of a player
std::string move_to_string(std::uint16_t m) const; std::string move_to_string(std::uint16_t m) const; //String representation of a move (for example, A1)
std::string to_string() const; std::string to_string() const; //String representation of the entire game
void playout(std::mt19937& engine, int max_depth = -1); void playout(std::mt19937& engine, int max_depth = -1);
std::set<int> to_input_vector() const; std::set<int> to_input_vector() const;
void from_input_vector(const std::set<int>& input); void from_input_vector(const std::set<int>& input);
morpion_state get_state(); morpion_state get_state(); //Return the state
void set_state(const morpion_state& state); void set_state(const morpion_state& state); //Replace the current state with the one passed as a parameter
std::shared_ptr<game<morpion_state>> do_copy() const; std::shared_ptr<game<morpion_state>> do_copy() const;
std::uint64_t hash(std::uint16_t m) const; std::uint64_t hash(std::uint16_t m) const;
std::uint64_t hash() const; std::uint64_t hash() const;
private: private:
inline void update_win(); inline void update_win(); //Check if someone won and update the state
inline bool has_won(uint16_t bitboard); inline bool has_won(uint16_t bitboard); //Check if the player whose bitboard was passed as a param has won
inline bool get(uint16_t bitboard, uint8_t i, uint8_t j) const; inline bool get(uint16_t bitboard, uint8_t i, uint8_t j) const; //Get a case of the board
const uint8_t CROSS = 1; const uint8_t CROSS = 1;
const uint8_t CIRCLE = 0; const uint8_t CIRCLE = 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment