Forked from
Bariatti Francesco / pingouins
7 commits ahead of the upstream repository.
-
Pizon Antoine authored
Revert "Added random positioning for penguins and the possibility to display the game in the terminal" This reverts commit 01019274.
Pizon Antoine authoredRevert "Added random positioning for penguins and the possibility to display the game in the terminal" This reverts commit 01019274.
penguin.hpp 3.35 KiB
#ifndef __PENGUIN_HPP__
#define __PENGUIN_HPP__
#include "game.hpp"
#include "json.hpp"
using json = nlohmann::json;
#include <random>
#include <array>
#include <iostream>
#include <memory>
namespace game
{
struct penguin_state
{
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)
//Penguins
uint32_t peng_red[4] = {0, 1, 6, 7};
uint32_t peng_blue[4] = {59, 58, 53, 54};
int score_red = 0;
int score_blue = 0;
bool current_player_red = true; //True if red must play now. Red always starts
int nb_moves_red = 0; //Number of moves the red player can play
int nb_moves_blue = 0;
bool canPlay_red = true;
bool canPlay_blue = true;
};
//Describes the possible content of a peguin game tile
enum tile_content {RED_PENGUIN,BLUE_PENGUIN,ONE_FISH,TWO_FISH,THREE_FISH,OBSTACLE};
// Useful macros to get values out of penguins
#define PENGUIN_POS(penguin) ((penguin) & 63)
#define PENGUIN_TOT_MOVES(penguin) (((penguin) >> 6) & 63)
#define PENGUIN_MOVES_A(penguin) (((penguin) >> 12) & 7)
#define PENGUIN_MOVES_B(penguin) (((penguin) >> 15) & 7)
#define PENGUIN_MOVES_C(penguin) (((penguin) >> 18) & 7)
#define PENGUIN_MOVES_D(penguin) (((penguin) >> 21) & 7)
#define PENGUIN_MOVES_E(penguin) (((penguin) >> 24) & 7)
#define PENGUIN_MOVES_F(penguin) (((penguin) >> 27) & 7)
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;
/**
Returns the content of a tile
i : the line, between 0 and 7
j : the column, between 0 and 7 if i is pair else between 0 and 8
*/
const tile_content get_tile(std::uint8_t tile_index) const;
private:
penguin_state state;
void move_penguin(uint32_t* p, uint16_t rel_move);
uint64_t create_obstacles_bitboard();
int update_penguin_moves(uint32_t* p, uint64_t obstacles);
const uint8_t RED = 0;
const uint8_t BLUE = 1;
};
std::ostream& operator<<(std::ostream& os, const penguin& pen);
}
#endif