Skip to content
Snippets Groups Projects
Commit 15cf6dda authored by Gaste Adrien's avatar Gaste Adrien
Browse files

Bases du jeu pingouins.

Makefile et main modifiés, fichiers .hpp et .cpp crées
parent a50d3c7a
No related branches found
No related tags found
No related merge requests found
CC=g++-4.9 CC=g++
BIN=bin BIN=bin
INCLUDE=-I src/game -I src/util -I src/monte_carlo -I src/mcts -I src/minmax INCLUDE=-I src/game -I src/util -I src/monte_carlo -I src/mcts -I src/minmax
CFLAGS=-g -O3 -ffast-math -fopenmp -c -Wall -std=c++11 $(INCLUDE) CFLAGS=-g -O3 -ffast-math -fopenmp -c -Wall -std=c++11 $(INCLUDE)
LDFLAGS=-fopenmp -std=c++11 #-lprofiler -Wl,-no_pie LDFLAGS=-fopenmp -std=c++11 #-lprofiler -Wl,-no_pie
SOURCES=omp_util.cpp fast_log.cpp display_node.cpp connect4.cpp morpion.cpp test_two_players_game.cpp test_connect4.cpp monte_carlo.cpp test_monte_carlo.cpp test_fast_log.cpp\ SOURCES=omp_util.cpp fast_log.cpp display_node.cpp penguin.cpp connect4.cpp morpion.cpp test_two_players_game.cpp test_connect4.cpp monte_carlo.cpp test_monte_carlo.cpp test_fast_log.cpp\
statistics.cpp node.cpp allocator.cpp test_allocator.cpp openings.cpp mcts_two_players.cpp test_mcts_two_players.cpp test_minmax.cpp\ statistics.cpp node.cpp allocator.cpp test_allocator.cpp openings.cpp mcts_two_players.cpp test_mcts_two_players.cpp test_minmax.cpp\
bits.cpp test_bits.cpp main.cpp bits.cpp test_bits.cpp main.cpp
OBJECTS=$(addprefix $(BIN)/, $(SOURCES:.cpp=.o)) OBJECTS=$(addprefix $(BIN)/, $(SOURCES:.cpp=.o))
......
...@@ -23,3 +23,5 @@ Bitboard obstacles : 1 s'il y a un obstacle ...@@ -23,3 +23,5 @@ Bitboard obstacles : 1 s'il y a un obstacle
0 sinon 0 sinon
==> ~Bitboard eau (OR 1 << Pos. pingouin1) (OR 1 << Pos. pingouin2)...(OR 1 << Pos. pingouin8) ==> ~Bitboard eau (OR 1 << Pos. pingouin1) (OR 1 << Pos. pingouin2)...(OR 1 << Pos. pingouin8)
==> Le premier joueur est Red
#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 false;
//return state.first_player_win || state.second_player_win || state.total_moves == 9;
}
bool penguin::won(std::uint8_t player) const
{
return false;
//if (player == CROSS) return state.first_player_win;
//return state.second_player_win;
}
bool penguin::lost(std::uint8_t player) const
{
return false;
/*if (player == CIRCLE) return state.first_player_win;
return state.second_player_win;*/
}
bool penguin::draw(std::uint8_t player) const
{
return false;
/*if (state.first_player_win || state.second_player_win) return false;
return state.total_moves == 9;*/
}
uint8_t penguin::current_player() const
{
return 0;
/*return state.total_moves & 1 ? CIRCLE : CROSS; // CROSS even, CIRCLE odd*/
}
int penguin::value(uint8_t player) const
{
/*if (player == CROSS) {
return state.first_player_win ? 1 : (state.second_player_win ? -1 : 0);
}
else if (player == CIRCLE) {
return state.second_player_win ? 1 : (state.first_player_win ? -1 : 0);
}
return 0;*/
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 == CROSS ? "X" : (player == CIRCLE ? "O" : " ");
return "TODO";
}
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;
}
}
#ifndef __PENGUIN_HPP__
#define __PENGUIN_HPP__
#include "game.hpp"
#include <random>
#include <array>
#include <iostream>
#include <memory>
namespace game
{
struct penguin_state
{
uint64_t one_fish = 0x7F59398348146BD; //Position of one-fish tiles (bitboard)
uint64_t two_fish = 0x86C628366B102; //Position of two-fish tiles (bitboard)
uint64_t three_fish = 0x802000548180840; //Position of three-fish tiles (bitboard)
//Penguins
uint32_t p1_red = 0;
uint32_t p2_red = 1;
uint32_t p3_red = 8;
uint32_t p4_red = 9;
uint32_t p1_blue = 51;
uint32_t p2_blue = 52;
uint32_t p3_blue = 58;
uint32_t p4_blue = 59;
bool red_player_win = false;
bool blue_player_win = false;
int score_red = 0;
int score_blue = 0;
bool current_player_red = true; //True if red must play now
};
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)
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;
private:
penguin_state state;
};
std::ostream& operator<<(std::ostream& os, const penguin& pen);
}
#endif
#include "test_connect4.hpp" #include "test_connect4.hpp"
#include "connect4.hpp" #include "connect4.hpp"
#include "morpion.hpp" #include "morpion.hpp"
#include "penguin.hpp"
#include "test_two_players_game.hpp" #include "test_two_players_game.hpp"
#include "test_monte_carlo.hpp" #include "test_monte_carlo.hpp"
#include "test_fast_log.hpp" #include "test_fast_log.hpp"
...@@ -24,7 +25,11 @@ int main(int argc, char *argv[]) ...@@ -24,7 +25,11 @@ int main(int argc, char *argv[])
//mcts::run_test_mcts_two_players(game::connect4()); //mcts::run_test_mcts_two_players(game::connect4());
//game::run_test_two_players_game(game::morpion()); //game::run_test_two_players_game(game::morpion());
mcts::run_test_mcts_two_players(game::morpion()); //mcts::run_test_mcts_two_players(game::morpion());
game::run_test_two_players_game(game::penguin());
//mcts::run_test_mcts_two_players(game::penguin());
// minmax::test_minmax(); // minmax::test_minmax();
//util::test_bits(200000000); //util::test_bits(200000000);
......
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