Skip to content
Snippets Groups Projects
morpion.cpp 2.85 KiB
Newer Older
#include "morpion.hpp"
#include <sstream>

using namespace std;

namespace game
{
	static vector<vector<uint64_t>> create_hash_values()
	{
		default_random_engine generator;
		uniform_int_distribution<uint64_t> distribution;
		vector<vector<uint64_t>> res(7, vector<uint64_t>(6, 0));
		for (int i = 0; i < 7; ++i) 
		{
			for (int j = 0; j < 6; ++j)
			{
				res[i][j] = distribution(generator);
			}
		}
		return res;
	}

	vector<vector<uint64_t>> morpion::cross_hash_values = create_hash_values();
	vector<vector<uint64_t>> morpion::circle_hash_values = create_hash_values();

	morpion::morpion()
	{
	}

	shared_ptr<game<morpion_state>> morpion::do_copy() const
	{
		return shared_ptr<morpion>(new morpion(*this));
	}

	morpion_state morpion::get_state()
	{
		return state;
	}
	
	void morpion::set_state(const morpion_state& s)
	{
		state = s; 
	}

	bool morpion::end_of_game() const
	{
Le Mikael's avatar
Le Mikael committed
		return state.first_player_win || state.second_player_win || state.total_moves == 9;
	}

	bool morpion::won(std::uint8_t player) const
	{
		//TODO: Implement
		return false;
	}
	
	bool morpion::lost(std::uint8_t player) const
	{
		//TODO: Implement
		return false;
	}

	bool morpion::draw(std::uint8_t player) const
	{
		//TODO: Implement
		return false;
	}

	uint8_t morpion::current_player() const
	{
Le Mikael's avatar
Le Mikael committed
		return state.total_moves & 1 ? CIRCLE : CROSS; // CROSS pair, CIRCLE impair
	}

	int morpion::value(uint8_t player) const
	{
		//TODO: Implement
		return 0;
	}

	uint16_t morpion::number_of_moves() const
	{
Le Mikael's avatar
Le Mikael committed
		return state.total_moves;
	}

	bool morpion::get(uint64_t bitboard, uint8_t col, uint8_t row) const
	{
		//TODO: Implement
		return false;
	}

//#define set(bitboard, col, row) (bitboard |= (1LL << (((col) << 3) + (row))))

	void morpion::update_win()
	{
		//TODO: Implement
	}

	bool morpion::has_won(uint64_t bitboard)
	{
		//TODO: Implement
		return false;
	}

	void morpion::update_moves(uint16_t move)
	{
		//TODO: Implement
	}

	void morpion::play(uint16_t m)
	{    
		//TODO: Implement
	}

	string morpion::player_to_string(uint8_t player) const
	{
		//TODO: Implement
		return "TODO";
	}

	string morpion::move_to_string(uint16_t m) const
	{
		//TODO: Implement
		return "TODO";
	}

	set<int> morpion::to_input_vector() const
	{
		return set<int>();
	}

	void morpion::from_input_vector(const std::set<int>& input)
	{
	}

	string morpion::to_string() const
	{
		//TODO: Implement
		return "TODO";
	}

	void morpion::playout(mt19937& engine, int max_depth)
	{
		while (!end_of_game())
		{
			uniform_int_distribution<uint16_t> distribution(0, number_of_moves() - 1);
			uint16_t move = distribution(engine);
			play(move);
		}
	}

	std::uint64_t morpion::hash() const
	{
		//TODO: Implement
		return 0;
	}

	std::uint64_t morpion::hash(std::uint16_t m) const
	{
		//TODO: Implement
		return 0;
	}
	
	ostream& operator<<(ostream& os, const morpion& mor)
	{
		os << mor.to_string() << endl;
		return os;
	}
}