#include "penguin.hpp" #include <sstream> using namespace std; namespace game { penguin::penguin() { } shared_ptr<game<penguin_state>> penguin::do_copy() const { return shared_ptr<penguin>(new penguin(*this)); } penguin_state penguin::get_state() { return state; } void penguin::set_state(const penguin_state& s) { state = s; } bool penguin::end_of_game() const { return state.nb_moves_red == 0 && state.nb_moves_blue == 0; } bool penguin::won(std::uint8_t player) const { if (player == RED) return state.score_red > state.score_blue; return state.score_blue > state.score_red; } bool penguin::lost(std::uint8_t player) const { if(player == RED) return state.score_red < state.score_blue; return state.score_blue < state.score_red; } bool penguin::draw(std::uint8_t player) const { return state.score_blue == state.score_red; } uint8_t penguin::current_player() const { return state.current_player_red ? RED : BLUE; } int penguin::value(uint8_t player) const { if (won(player)) return 1; else if (lost(player)) return -1; else return 0; } /* Number of moves that you can play */ uint16_t penguin::number_of_moves() const { //return 9 - state.total_moves; return 0; } //Play the mth move in the possible moves list. void penguin::play(uint16_t m) { /*uint64_t possible_moves = state.possible_moves; possible_moves = possible_moves >> 4*m; //A move is coded with 4 bit uint16_t move = possible_moves & 15; //15 = 1111 //cout << "You choose the possible move number " << m << endl; //cout << "You choose move " << move << endl; if (current_player() == CROSS) state.cross_bitboard |= (((uint16_t) 1) << move); else state.circle_bitboard |= (((uint16_t) 1) << move); //State update state.total_moves++; update_win(); update_moves(); return;*/ } string penguin::player_to_string(uint8_t player) const { return player == RED ? "Red" : "Blue"; } string penguin::move_to_string(uint16_t m) const { //return std::to_string((state.possible_moves >> (4 * m)) & 0xf); return "TODO"; } set<int> penguin::to_input_vector() const { return set<int>(); } void penguin::from_input_vector(const std::set<int>& input) { } string penguin::to_string() const { /*string result = "-------\n"; for (int row = 2; row >= 0; row--) { result += "|"; for (int col = 2; col >= 0; col--) { if(((state.cross_bitboard >> (3*row)) >> col) & 1) result += player_to_string(CROSS)+"|"; else if (((state.circle_bitboard >> (3*row)) >> col) & 1) result += player_to_string(CIRCLE)+"|"; else result += std::to_string(row * 3 + col) + "|"; } result += "\n-------\n"; } return result; */ return "TODO"; } std::uint64_t penguin::hash() const { return 0; } std::uint64_t penguin::hash(std::uint16_t m) const { return 0; } ostream& operator<<(ostream& os, const penguin& pen) { os << pen.to_string() << endl; return os; } }