Newer
Older
#ifndef __PENGUIN_HPP__
#define __PENGUIN_HPP__
#include "game.hpp"
#include "json.hpp"
using json = nlohmann::json;
Bariatti Francesco
committed
#include <random>
#include <array>
#include <iostream>
#include <memory>
namespace game
{
struct penguin_state
{
Bariatti Francesco
committed
uint64_t one_fish = 1152921504606846975; //Position of one-fish tiles (bitboard)
uint64_t two_fish = 0; //Position of two-fish tiles (bitboard)
uint64_t three_fish = 0; //Position of three-fish tiles (bitboard)
Bariatti Francesco
committed
Bariatti Francesco
committed
uint32_t peng_red[4] = {0, 1, 6, 7};
uint32_t peng_blue[4] = {59, 58, 53, 54};
//TODO: delete
uint32_t p1_red = 0;
uint32_t p2_red = 1;
uint32_t p3_red = 6;
uint32_t p4_red = 7;
uint32_t p1_blue = 59;
uint32_t p2_blue = 58;
uint32_t p3_blue = 53;
uint32_t p4_blue = 54;
Bariatti Francesco
committed
Bariatti Francesco
committed
int score_red = 0;
int score_blue = 0;
Bariatti Francesco
committed
Bariatti Francesco
committed
bool current_player_red = true; //True if red must play now. Red always starts
Bariatti Francesco
committed
int nb_moves_red = 0; //Number of moves the red player can play
int nb_moves_blue = 0;
Bariatti Francesco
committed
Bariatti Francesco
committed
bool canPlay_red = true;
bool canPlay_blue = true;
Bariatti Francesco
committed
class penguin : public game<penguin_state>
{
public:
penguin();
penguin(const penguin& pen) = default;
penguin& operator=(const penguin& pen) = default;
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
bool won(std::uint8_t player) const;
bool lost(std::uint8_t player) const;
bool draw(std::uint8_t 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; //Number of moves that you can play
void play(std::uint16_t m); //Play the move m (updates the state).
void undo(std::uint16_t m) {}
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; //String representation of a move (for example, A1)
json to_JSON() const;
std::string to_string() const; //String representation of the entire game
std::set<int> to_input_vector() const;
void from_input_vector(const std::set<int>& input);
penguin_state get_state(); //Return the state
void set_state(const penguin_state& state); //Replace the current state with the one passed as a parameter
std::shared_ptr<game<penguin_state>> do_copy() const;
std::uint64_t hash(std::uint16_t m) const;
std::uint64_t hash() const;
Bariatti Francesco
committed
Bariatti Francesco
committed
//TODO: modify/delete functions
void move_penguin(uint32_t* p);
int update_moves(uint32_t* p, uint64_t obstacles);
Bariatti Francesco
committed
const uint8_t RED = 0;
const uint8_t BLUE = 1;
Bariatti Francesco
committed
};
std::ostream& operator<<(std::ostream& os, const penguin& pen);
}
#endif