Commit 54c1f360 authored by Loic Guegan's avatar Loic Guegan
Browse files

Cleaning log system

parent 2fc44fc8
Pipeline #219024511 passed with stage
in 8 minutes and 51 seconds
icons/screenshot.jpg

74.3 KB | W: | H:

icons/screenshot.jpg

102 KB | W: | H:

icons/screenshot.jpg
icons/screenshot.jpg
icons/screenshot.jpg
icons/screenshot.jpg
  • 2-up
  • Swipe
  • Onion skin
......@@ -35,7 +35,7 @@ void UCIProc::InitializeEngine(){
InitSuccess = EngineProc.running();
if (!InitSuccess)
OC_LOG(error)
LOG(ERROR)
<< "Failed to init engine: " << EnginePath;
}
......@@ -45,7 +45,7 @@ UCIProc::~UCIProc() {
Chrono delay;
while (IsAlive()) {
if (delay.Milliseconds() > 1000) { // Let it 1s to stop
OC_LOG(warning)
LOG(WARNING)
<< "Killing engine!";
EngineProc.terminate();
break;
......
......@@ -21,7 +21,7 @@ void BoardController::Move(Coord src, Coord dst) {
if (state.ActiveColor == ochess::model::BLACK) {
BlackEngine->position("fen " + G.GetFen());
BlackEngine->go(false, false);
OC_LOG(info)
LOG(INFO)
<< "Engine is thinking...";
while (!BlackEngine->IsBestMoveFound()) {
}
......
......@@ -7,13 +7,13 @@ Skin::Skin() {
wxInitAllImageHandlers();
for (auto &theme : CNF.ListPiecesThemes()) {
OC_LOG(trace)
LOG(TRACE)
<< "Loading default pieces skin: " << theme;
LoadPiecesSkin(theme);
break;
}
for (auto &theme : CNF.ListBoardThemes()) {
OC_LOG(trace)
LOG(TRACE)
<< "Loading default board skin: " << theme;
LoadSquaresSkin(theme);
break;
......
......@@ -20,7 +20,7 @@ Editor::Editor(wxFrame *parent) :
ochess::pgn::PGN pgn("/home/loic/test.pgn");
pgn.parseNextGame();
state->moveline = &(pgn.game->GetMoveLine()->editorMove);
state->moveline = &(pgn.game->GetFirstMove()->editorMove);
......
......@@ -14,7 +14,7 @@ EngineView::EngineView() :
void EngineView::OnClose(wxCloseEvent &event) {
(void) event;
OC_LOG(warning)
LOG(WARNING)
<< "Delete";
this->Show(false);
}
......
......@@ -33,16 +33,20 @@ wxFrame(NULL, wxID_ANY, title, pos, size) {
menuBar->Append(menuHelp, "Help");
SetMenuBar(menuBar);
TopSizer = new wxBoxSizer(wxHORIZONTAL);
// Create required windows
//Create(WIN_SETTINGS);
Create(WIN_BOARD);
Create(WIN_EDITOR);
//new EngineSelection(this);
// Setup status bar
CreateStatusBar();
SetStatusText("Welcome to wxWidgets!");
SetStatusText("Welcome to OChess!");
// Various setup
this->SetSizer(TopSizer);
this->Bind(wxEVT_CLOSE_WINDOW, &MainFrame::OnClose, this);
}
......@@ -50,6 +54,7 @@ void MainFrame::Create(WIN name) {
switch (name) {
case WIN_BOARD: {
BoardView *b = new BoardView((wxFrame*) this);
TopSizer->Add(b,1,wxEXPAND);
Windows[name]=b;
break;
}
......@@ -66,6 +71,7 @@ void MainFrame::Create(WIN name) {
}
case WIN_EDITOR: {
EditorView *e = new EditorView((wxFrame*) this);
TopSizer->Add(e,1,wxEXPAND);
Windows[name]=e;
break;
}
......
......@@ -57,7 +57,7 @@ private:
void MenuEventHandler(wxCommandEvent &event);
void OnClose(wxCloseEvent &event);
void Create(WIN name);
wxBoxSizer *TopSizer;
};
} // namespace gui
......
......@@ -15,20 +15,36 @@
#include <boost/log/utility/setup/console.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/move/utility_core.hpp>
#include <boost/log/sources/global_logger_storage.hpp>
#include <fstream>
#define OC_LOG(level) BOOST_LOG_TRIVIAL(level)
#define LOG(level) BOOST_LOG_SEV(ochess_logger::get(),level)
namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace bfs = boost::filesystem;
namespace expr = boost::log::expressions;
namespace attrs = boost::log::attributes;
BOOST_LOG_ATTRIBUTE_KEYWORD(engine_path, "EnginePath", std::string);
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(ochess_logger, src::severity_logger_mt<>)
namespace ochess {
typedef enum LOG_LEVELS{
TRACE=boost::log::trivial::trace,
DEBUG=boost::log::trivial::debug,
INFO=boost::log::trivial::info,
WARNING=boost::log::trivial::warning,
ERROR=boost::log::trivial::error,
fatal=boost::log::trivial::fatal
} LOG_LEVELS;
inline void OC_INIT_LOG() {
#ifdef NDEBUG
boost::log::core::get()->set_filter(boost::log::trivial::severity >
......
......@@ -186,7 +186,7 @@ template<class T> bool Board<T>::move(Coord src, Coord dst) {
dst_s->isEmpty = false;
return true;
}
OC_LOG(warning)
LOG(WARNING)
<< "You are trying to move a piece that do not exist on board: "
<< src.GetXY() << " to " << dst.GetXY();
return false;
......
......@@ -89,7 +89,7 @@ Fen::Fen(std::string fen) :
}
if (!IsValid) {
OC_LOG(warning)
LOG(WARNING)
<< "Invalid FEN used in Fen class constructor: " << fen;
} else
InitFenState();
......@@ -358,7 +358,7 @@ void Fen::BuildBoard(Board<PPiece> *board) {
rowID++;
}
} else
OC_LOG(error)
LOG(ERROR)
<< "Can't build board: " << GetErrorMsg();
}
} // namespace model
......
......@@ -9,7 +9,9 @@ Game::Game(std::string fen) :
f.BuildBoard(&BRD);
State = f.GetState();
}
Game::Game():Game(FEN_INITIAL){}
Game::Game() :
Game(FEN_INITIAL) {
}
boost::optional<PPiece> Game::GetPiece(Coord c) {
if (!BRD.isEmpty(c))
......@@ -72,19 +74,18 @@ bool Game::Move(Coord src, Coord dst) {
return (true);
}
bool Game::Move(ochess::model::Move *m){
bool ret=false;
if(m->isLongCastle || m->isShortCastle){
ret=Castle(m->isLongCastle);
}
else{
Coord src=A.FindSrc(m->dst, m->col,m->isPawn,m->piece);
ret=this->Move(src.GetXY(), m->dst);
bool Game::Move(ochess::model::Move *m) {
bool ret = false;
if (m->isLongCastle || m->isShortCastle) {
ret = Castle(m->isLongCastle);
} else {
Coord src = A.FindSrc(m->dst, m->col, m->isPawn, m->piece);
ret = this->Move(src.GetXY(), m->dst);
}
//std::cout << " dst: " << m->dst << " ispawn: " << m->isPawn << " piece: " << m->piece<< std::endl <<std::flush;
if(ret)
if (ret)
H.ConfigureState(m);
return(ret);
return (ret);
}
void Game::Next() {
......@@ -94,6 +95,43 @@ void Game::Previous() {
H.Previous(&BRD, &State);
}
ochess::model::Move* Game::GetFirstMove() {
return (H.GetInitialState()->main);
}
bool Game::Castle(bool isLong){
if(State.ActiveColor==WHITE){
if(isLong){
return(Move("e1","c1"));
}
else{
return(Move("e1","g1"));
}
}
else{
if(isLong){
return(Move("e8","c8"));
}
else{
return(Move("e8","g8"));
}
}
}
void Game::PlayLine(ochess::model::Move* line){
if(!Move(line)){
std::cout << "Failed to play move in playline" << std::endl << std::flush;
}
if(line->variations.size()>0){
Previous();
for(auto move: line->variations){
PlayLine(move);
}
Next();
}
if(line->main!=nullptr)
PlayLine(line->main);
Previous();
}
bool Game::IsStaleMate(COLOR c) {
if (!A.IsCheck(c)) {
State.ActiveColor = c; // Allow move from c color
......
......@@ -189,43 +189,21 @@ public:
std::string GetFen() {
return (H.GetFen());
}
ochess::model::Move* GetMoveLine(){
return(H.GetInitialState()->main);
}
void PlayLine(ochess::model::Move* line){
if(!Move(line)){
std::cout << "Failed to play move in playline" << std::endl << std::flush;
}
if(line->variations.size()>0){
Previous();
for(auto move: line->variations){
PlayLine(move);
}
Next();
}
if(line->main!=nullptr)
PlayLine(line->main);
Previous();
}
bool Castle(bool isLong){
if(State.ActiveColor==WHITE){
if(isLong){
return(Move("e1","c1"));
}
else{
return(Move("e1","g1"));
}
}
else{
if(isLong){
return(Move("e8","c8"));
}
else{
return(Move("e8","g8"));
}
}
}
/**
* @brief Return the first move of the game
* @return A pointer to the first move of the game or nullptr
*/
ochess::model::Move* GetFirstMove();
/**
* @brief Play all the move and variation in @p line
* @param line The line to play
*/
void PlayLine(ochess::model::Move* line);
/**
* @brief Castle long or short if possible
* @param isLong true if it is a long castle or flase otherwise
*/
bool Castle(bool isLong);
};
} // namespace model
......
......@@ -27,7 +27,6 @@ namespace ochess {
ConfigManager CNF;
}
/**
* Main Application
*/
......
......@@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(test_pgn) {
pgn::PGN parser("./pgn/test.pgn");
BOOST_REQUIRE_MESSAGE(parser.IsOpen(), "Failed to open pgn file");
parser.parseNextGame();
Move *line = parser.game->GetMoveLine();
Move *line = parser.game->GetFirstMove();
// Count moves
BOOST_REQUIRE_MESSAGE(GetVariationSize(line) == 24,
......@@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(test_pgn) {
pgn::PGN parser2("./pgn/checkmate.pgn");
BOOST_REQUIRE_MESSAGE(parser2.IsOpen(), "Failed to open pgn file");
parser2.parseNextGame();
line = parser2.game->GetMoveLine();
line = parser2.game->GetFirstMove();
BOOST_REQUIRE_MESSAGE(GetVariationSize(line) == 7,
"Parsed PGN does not contains the right number of move.");
BOOST_CHECK(GetMoveN(line,6)->isCheckMate);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment