mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Integrate CMI
This commit is contained in:
parent
aa6ec0ea60
commit
a1289dec3d
13 changed files with 118 additions and 278 deletions
9
.gitmodules
vendored
9
.gitmodules
vendored
|
@ -1,6 +1,3 @@
|
||||||
[submodule "libs/cgeditor"]
|
|
||||||
path = libs/cgeditor
|
|
||||||
url = https://gitlab.com/manzerbredes/cgeditor.git
|
|
||||||
[submodule "libs/chessarbiter"]
|
[submodule "libs/chessarbiter"]
|
||||||
path = libs/chessarbiter
|
path = libs/chessarbiter
|
||||||
url = https://gitlab.com/manzerbredes/chessarbiter.git
|
url = https://gitlab.com/manzerbredes/chessarbiter.git
|
||||||
|
@ -10,3 +7,9 @@
|
||||||
[submodule "libs/uciadapter"]
|
[submodule "libs/uciadapter"]
|
||||||
path = libs/uciadapter
|
path = libs/uciadapter
|
||||||
url = https://gitlab.com/manzerbredes/uciadapter.git
|
url = https://gitlab.com/manzerbredes/uciadapter.git
|
||||||
|
[submodule "libs/chess-move-interface"]
|
||||||
|
path = libs/chess-move-interface
|
||||||
|
url = https://gitlab.com/manzerbredes/chess-move-interface.git
|
||||||
|
[submodule "cgeditor"]
|
||||||
|
path = libs/cgeditor
|
||||||
|
url = https://gitlab.com/manzerbredes/cgeditor.git
|
||||||
|
|
|
@ -33,6 +33,11 @@ add_subdirectory(libs/uciadapter)
|
||||||
target_link_libraries(ochess uciadapter)
|
target_link_libraries(ochess uciadapter)
|
||||||
include_directories(${UCIADAPTER_INCLUDE_DIR})
|
include_directories(${UCIADAPTER_INCLUDE_DIR})
|
||||||
|
|
||||||
|
# ChessMoveInterface
|
||||||
|
add_subdirectory(libs/chess-move-interface)
|
||||||
|
target_link_libraries(ochess ChessMoveInterface)
|
||||||
|
include_directories(${CMI_INCLUDE_DIR})
|
||||||
|
|
||||||
# Assets
|
# Assets
|
||||||
add_custom_command(TARGET ochess PRE_BUILD
|
add_custom_command(TARGET ochess PRE_BUILD
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
|
|
@ -29,6 +29,7 @@ OChess is based on several satellite projects that implement individual and inde
|
||||||
- [pgnp](https://gitlab.com/manzerbredes/pgnp): An efficient PGN parser
|
- [pgnp](https://gitlab.com/manzerbredes/pgnp): An efficient PGN parser
|
||||||
- [uciadapter](https://gitlab.com/manzerbredes/uciadapter): A cross platform utility to interact with *UCI* chess engines
|
- [uciadapter](https://gitlab.com/manzerbredes/uciadapter): A cross platform utility to interact with *UCI* chess engines
|
||||||
- [cgeditor](https://gitlab.com/manzerbredes/cgeditor): A 2D chess game moves presenter/editor
|
- [cgeditor](https://gitlab.com/manzerbredes/cgeditor): A 2D chess game moves presenter/editor
|
||||||
|
- [chess-move-interface](https://gitlab.com/manzerbredes/chess-move-interface) A chess half move interface for libraries interoperability
|
||||||
|
|
||||||
## Acknowledgments
|
## Acknowledgments
|
||||||
- The [chess-openings](https://github.com/lichess-org/chess-openings) project by [lichess-org](https://github.com/lichess-org) for their openings databases
|
- The [chess-openings](https://github.com/lichess-org/chess-openings) project by [lichess-org](https://github.com/lichess-org) for their openings databases
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5e18d43a6ba4fd378178418de6b2ca7a67d64c21
|
Subproject commit 83c92b1f48520ed71a9f056badc86c97aafa4e45
|
1
libs/chess-move-interface
Submodule
1
libs/chess-move-interface
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 7125292878ffc3568018e1e509c9210a074c67a6
|
|
@ -1 +1 @@
|
||||||
Subproject commit 2ac42558f2b6269ad4d8e0809519f96aae1fd342
|
Subproject commit f7a24ed8d5802c834abc4fe54c286ce509dae609
|
|
@ -47,7 +47,7 @@ std::shared_ptr<Game> PGNGameBase::GetCurrentGame() {
|
||||||
g=new Game(fen);
|
g=new Game(fen);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
HalfMove *m = new HalfMove(pgnp_moves);
|
HalfMove *m = new HalfMove(pgnp_moves->GetAsCMI());
|
||||||
m->SetFen(fen);
|
m->SetFen(fen);
|
||||||
g=new Game(m, fen);
|
g=new Game(m, fen);
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ std::string PGNGameBase::GetPGN(std::shared_ptr<Game> g) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m !=nullptr){
|
if(m !=nullptr){
|
||||||
pgn += GetMovesPGN(m,m->IsABlackMove());
|
pgn += GetMovesPGN(m,m->IsBlack());
|
||||||
pgn += " ";
|
pgn += " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,32 +168,35 @@ std::string PGNGameBase::GetMovesPGN(HalfMove *m, bool needDots) {
|
||||||
std::string part;
|
std::string part;
|
||||||
bool newNeedDots = false;
|
bool newNeedDots = false;
|
||||||
|
|
||||||
if (!m->IsABlackMove() || needDots) {
|
if (!m->IsBlack() || needDots) {
|
||||||
part += std::to_string(m->Number) + ".";
|
part += std::to_string(m->GetNumber()) + ".";
|
||||||
if (needDots) {
|
if (needDots) {
|
||||||
part += "..";
|
part += "..";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
part += m->move;
|
part += m->GetSAN();
|
||||||
|
|
||||||
if (m->comment.size() > 0) {
|
if(m->GetNAG()>0)
|
||||||
|
part += " $" + std::to_string(m->GetNAG());
|
||||||
|
|
||||||
|
if (m->GetComment().size() > 0) {
|
||||||
part += " {";
|
part += " {";
|
||||||
part += m->comment;
|
part += m->GetComment();
|
||||||
part += "}";
|
part += "}";
|
||||||
newNeedDots = true;
|
newNeedDots = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m->GetVariations().size() > 0) {
|
if (m->GetVariations().size() > 0) {
|
||||||
newNeedDots = true;
|
newNeedDots = true;
|
||||||
for (HalfMove *v : m->GetVariations()) {
|
for (CMI::HalfMove *v : m->GetVariations()) {
|
||||||
part += " (";
|
part += " (";
|
||||||
part += GetMovesPGN(v, m->IsABlackMove());
|
part += GetMovesPGN(static_cast<HalfMove*>(v), m->IsBlack());
|
||||||
part += ")";
|
part += ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m->GetMainline() != nullptr) {
|
if (m->GetMainline() != nullptr) {
|
||||||
part += " " + GetMovesPGN(m->GetMainline(), !m->IsABlackMove() && newNeedDots);
|
part += " " + GetMovesPGN(static_cast<HalfMove*>(m->GetMainline()), !m->IsBlack() && newNeedDots);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (part);
|
return (part);
|
||||||
|
|
|
@ -53,7 +53,7 @@ bool Game::IsBlackToPlay() {
|
||||||
if (current == nullptr) {
|
if (current == nullptr) {
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
return (!current->IsBlack);
|
return (!current->IsBlack());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::DeleteTag(std::string tagname) { tags.erase(tagname); }
|
void Game::DeleteTag(std::string tagname) { tags.erase(tagname); }
|
||||||
|
@ -65,7 +65,7 @@ void Game::DeleteMove(HalfMove *m) {
|
||||||
delete m;
|
delete m;
|
||||||
} else {
|
} else {
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
current = m->GetParent();
|
current = static_cast<HalfMove*>(m->GetParent());
|
||||||
if (current != nullptr) {
|
if (current != nullptr) {
|
||||||
current->RemoveChild(m);
|
current->RemoveChild(m);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ void Game::GetOpening(std::string &name,std::string &eco){
|
||||||
|
|
||||||
void Game::Previous() {
|
void Game::Previous() {
|
||||||
if (current != nullptr) {
|
if (current != nullptr) {
|
||||||
current = current->GetParent();
|
current = static_cast<HalfMove*>(current->GetParent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ std::vector<std::string> Game::ListTags() {
|
||||||
|
|
||||||
void Game::Next() {
|
void Game::Next() {
|
||||||
if (current != nullptr) {
|
if (current != nullptr) {
|
||||||
HalfMove *m = current->GetMainline();
|
HalfMove *m = static_cast<HalfMove*>(current->GetMainline());
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
current = m;
|
current = m;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ void Game::Next() {
|
||||||
|
|
||||||
HalfMove *Game::GetNextMove(){
|
HalfMove *Game::GetNextMove(){
|
||||||
if(current!=nullptr)
|
if(current!=nullptr)
|
||||||
return current->GetMainline();
|
return static_cast<HalfMove*>(current->GetMainline());
|
||||||
return moves;
|
return moves;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,22 +2,13 @@
|
||||||
|
|
||||||
HalfMove::HalfMove(std::string move_absolute,std::string move_san) : capture(' ') {
|
HalfMove::HalfMove(std::string move_absolute,std::string move_san) : capture(' ') {
|
||||||
SetAbsoluteMove(move_absolute);
|
SetAbsoluteMove(move_absolute);
|
||||||
this->move = move_san;
|
SetSAN(move_san);
|
||||||
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
fen = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
|
||||||
}
|
}
|
||||||
|
|
||||||
HalfMove::HalfMove(std::string move_absolute, std::string move_san, std::string fen) : fen(fen), capture(' ') {
|
HalfMove::HalfMove(std::string move_absolute, std::string move_san, std::string fen) : fen(fen), capture(' ') {
|
||||||
SetAbsoluteMove(move_absolute);
|
SetAbsoluteMove(move_absolute);
|
||||||
this->move = move_san;
|
SetSAN(move_san);
|
||||||
}
|
|
||||||
|
|
||||||
HalfMove::~HalfMove() {
|
|
||||||
if (mainline != nullptr) {
|
|
||||||
delete mainline;
|
|
||||||
}
|
|
||||||
for (HalfMove *m : variations) {
|
|
||||||
delete m;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HalfMove::SetOpening(const std::string &name, const std::string &eco){
|
void HalfMove::SetOpening(const std::string &name, const std::string &eco){
|
||||||
|
@ -25,8 +16,8 @@ void HalfMove::SetOpening(const std::string &name, const std::string &eco){
|
||||||
while(m!=nullptr){
|
while(m!=nullptr){
|
||||||
m->opening=name;
|
m->opening=name;
|
||||||
m->eco=eco;
|
m->eco=eco;
|
||||||
if(m->parent != nullptr && m->parent->mainline==m)
|
if(m->GetParent() != nullptr && static_cast<HalfMove*>(m->GetParent()->GetMainline())==m)
|
||||||
m=m->parent;
|
m=static_cast<HalfMove*>(m->GetParent());
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -43,10 +34,10 @@ std::vector<HalfMove *> HalfMove::GetLine(){
|
||||||
while(m!=nullptr){
|
while(m!=nullptr){
|
||||||
line.push_back(m);
|
line.push_back(m);
|
||||||
// Check if in a variation:
|
// Check if in a variation:
|
||||||
if(m->parent!=nullptr && m->parent->mainline!=m)
|
if(m->GetParent()!=nullptr && static_cast<HalfMove*>(m->GetParent()->GetMainline())!=m)
|
||||||
m=m->parent->parent; // Because we are in a variation
|
m=static_cast<HalfMove*>(m->GetParent()->GetParent()); // Because we are in a variation
|
||||||
else
|
else
|
||||||
m=m->parent;
|
m=static_cast<HalfMove*>(m->GetParent());
|
||||||
}
|
}
|
||||||
// Reverse the order to get it in the played order:
|
// Reverse the order to get it in the played order:
|
||||||
std::reverse(line.begin(), line.end());
|
std::reverse(line.begin(), line.end());
|
||||||
|
@ -64,7 +55,7 @@ std::string HalfMove::GetLineAsSAN(){
|
||||||
pgn+=std::to_string(count)+".";
|
pgn+=std::to_string(count)+".";
|
||||||
count+=1;
|
count+=1;
|
||||||
}
|
}
|
||||||
pgn+=line[i]->move +" ";
|
pgn+=line[i]->GetSAN() +" ";
|
||||||
}
|
}
|
||||||
return pgn;
|
return pgn;
|
||||||
}
|
}
|
||||||
|
@ -72,29 +63,21 @@ std::string HalfMove::GetLineAsSAN(){
|
||||||
HalfMove::HalfMove(HalfMove *m){
|
HalfMove::HalfMove(HalfMove *m){
|
||||||
src=m->src;
|
src=m->src;
|
||||||
dst=m->dst;
|
dst=m->dst;
|
||||||
move=m->move;
|
SetSAN(m->GetSAN());
|
||||||
fen=m->fen;
|
fen=m->fen;
|
||||||
capture=m->capture;
|
capture=m->capture;
|
||||||
IsBlack = m->IsBlack;
|
SetIsBlack(m->IsBlack());
|
||||||
Number = m->Number;
|
SetNumber(m->GetNumber());
|
||||||
nag = m->nag;
|
SetNAG(m->GetNAG());
|
||||||
comment=m->comment;
|
SetComment(m->GetComment());
|
||||||
if(m->mainline != nullptr){
|
if(m->GetMainline() != nullptr){
|
||||||
SetMainline(new HalfMove(m->mainline));
|
SetMainline(static_cast<CMI::HalfMove*>(new HalfMove(static_cast<HalfMove*>(m->GetMainline()))));
|
||||||
}
|
}
|
||||||
for (int i=0; i < m->variations.size(); i++) {
|
for (CMI::HalfMove *v: m->GetVariations()) {
|
||||||
AddVariation(new HalfMove(m->variations[i]));
|
AddVariation(new HalfMove(static_cast<HalfMove*>(v)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HalfMove::AddVariation(HalfMove *m) {
|
|
||||||
m->IsBlack = this->IsBlack;
|
|
||||||
m->Number = this->Number;
|
|
||||||
HalfMove::variations.push_back(m);
|
|
||||||
cgeditor::CGEHalfMove::variations.push_back(m);
|
|
||||||
m->SetParent(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<char, std::uint8_t> HalfMove::GetLineCaptures() {
|
std::map<char, std::uint8_t> HalfMove::GetLineCaptures() {
|
||||||
std::map<char, std::uint8_t> captures;
|
std::map<char, std::uint8_t> captures;
|
||||||
HalfMove *m = this;
|
HalfMove *m = this;
|
||||||
|
@ -105,7 +88,7 @@ std::map<char, std::uint8_t> HalfMove::GetLineCaptures() {
|
||||||
} else {
|
} else {
|
||||||
captures[c] = 1;
|
captures[c] = 1;
|
||||||
}
|
}
|
||||||
m = m->parent;
|
m = static_cast<HalfMove*>(m->GetParent());
|
||||||
} while (m != nullptr);
|
} while (m != nullptr);
|
||||||
return (captures);
|
return (captures);
|
||||||
}
|
}
|
||||||
|
@ -113,96 +96,30 @@ std::map<char, std::uint8_t> HalfMove::GetLineCaptures() {
|
||||||
void HalfMove::SetCapture(char c) { capture = c; }
|
void HalfMove::SetCapture(char c) { capture = c; }
|
||||||
|
|
||||||
void HalfMove::AddMove(HalfMove *m) {
|
void HalfMove::AddMove(HalfMove *m) {
|
||||||
if (this->mainline == nullptr) {
|
if (GetMainline() == nullptr) {
|
||||||
SetMainline(m);
|
SetMainline(m);
|
||||||
} else {
|
} else {
|
||||||
if (mainline != nullptr) {
|
if(GetMainline()!=nullptr)
|
||||||
mainline->AddVariation(m);
|
GetMainline()->AddVariation(m);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HalfMove::SetMainline(HalfMove *m) {
|
|
||||||
if (!this->IsBlack) {
|
|
||||||
m->IsBlack = true;
|
|
||||||
m->Number = this->Number;
|
|
||||||
} else {
|
|
||||||
m->IsBlack = false;
|
|
||||||
m->Number = this->Number + 1;
|
|
||||||
}
|
|
||||||
HalfMove::mainline = m;
|
|
||||||
cgeditor::CGEHalfMove::MainLine = m;
|
|
||||||
if (m != nullptr) {
|
|
||||||
m->SetParent(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HalfMove::SetParent(HalfMove *m) {
|
|
||||||
HalfMove::parent = m;
|
|
||||||
CGEHalfMove::Parent = m;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HalfMove::RemoveChild(HalfMove *m) {
|
|
||||||
std::uint32_t i = 0;
|
|
||||||
bool found = false;
|
|
||||||
for (i; i < HalfMove::variations.size(); i++) {
|
|
||||||
if (HalfMove::variations[i] == m) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found) {
|
|
||||||
HalfMove::variations.erase(HalfMove::variations.begin() + i);
|
|
||||||
}
|
|
||||||
if (HalfMove::mainline == m) {
|
|
||||||
HalfMove::mainline = nullptr;
|
|
||||||
}
|
|
||||||
cgeditor::CGEHalfMove::RemoveChild((CGEHalfMove *)m);
|
|
||||||
}
|
|
||||||
|
|
||||||
HalfMove *HalfMove::GetParent() { return (parent); }
|
|
||||||
|
|
||||||
HalfMove *HalfMove::GetRoot() {
|
|
||||||
HalfMove *m = this;
|
|
||||||
HalfMove *p = HalfMove::parent;
|
|
||||||
while (p != nullptr) {
|
|
||||||
if (p->mainline != m) {
|
|
||||||
return (m);
|
|
||||||
}
|
|
||||||
m = p;
|
|
||||||
p = m->HalfMove::parent;
|
|
||||||
}
|
|
||||||
return (m);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HalfMove::SetAsMainline() {
|
|
||||||
HalfMove *root = GetRoot();
|
|
||||||
HalfMove *lastRoot;
|
|
||||||
do {
|
|
||||||
lastRoot = root;
|
|
||||||
root->HalfMove::Promote();
|
|
||||||
root = GetRoot();
|
|
||||||
} while (root != lastRoot);
|
|
||||||
}
|
|
||||||
|
|
||||||
HalfMove *HalfMove::GetMainline() { return (mainline); }
|
|
||||||
|
|
||||||
void HalfMove::SetAbsoluteMove(const std::string &move_absolute){
|
void HalfMove::SetAbsoluteMove(const std::string &move_absolute){
|
||||||
this->src=move_absolute.substr(0,2);
|
this->src=move_absolute.substr(0,2);
|
||||||
this->dst=move_absolute.substr(2,2);
|
this->dst=move_absolute.substr(2,2);
|
||||||
}
|
}
|
||||||
|
|
||||||
HalfMove::HalfMove(pgnp::HalfMove *m) : capture(' ') {
|
HalfMove::HalfMove(CMI::HalfMove *m) : capture(' ') {
|
||||||
this->move = m->move;
|
SetSAN(m->GetSAN());
|
||||||
this->nag = m->NAG;
|
SetNAG(m->GetNAG());
|
||||||
this->IsBlack = m->isBlack;
|
SetIsBlack(m->IsBlack());
|
||||||
this->comment=m->comment;
|
SetComment(m->GetComment());
|
||||||
this->Number = m->count;
|
SetNumber(m->GetNumber());
|
||||||
if (m->MainLine != nullptr) {
|
if (m->GetMainline() != nullptr) {
|
||||||
this->SetMainline(new HalfMove(m->MainLine));
|
SetMainline(new HalfMove(m->GetMainline()));
|
||||||
}
|
}
|
||||||
for (pgnp::HalfMove *v : m->variations) {
|
for (CMI::HalfMove *v : m->GetVariations()) {
|
||||||
this->AddVariation(new HalfMove(v));
|
AddVariation(new HalfMove(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,42 +130,19 @@ void HalfMove::GetAbsoluteMove(std::string &src,std::string &dst){
|
||||||
|
|
||||||
void HalfMove::SetFen(std::string fen) { this->fen = fen; }
|
void HalfMove::SetFen(std::string fen) { this->fen = fen; }
|
||||||
|
|
||||||
void HalfMove::Promote() {
|
|
||||||
HalfMove *root = GetRoot();
|
|
||||||
if (root->parent != nullptr) {
|
|
||||||
HalfMove *p = root->parent;
|
|
||||||
if (p->HalfMove::mainline != root) {
|
|
||||||
if (root->parent->HalfMove::parent != nullptr) {
|
|
||||||
HalfMove *pp = root->parent->HalfMove::parent;
|
|
||||||
if (pp->HalfMove::mainline == p) {
|
|
||||||
pp->HalfMove::SetMainline(root);
|
|
||||||
} else {
|
|
||||||
pp->AddVariation(root);
|
|
||||||
pp->HalfMove::RemoveChild(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (p->HalfMove::mainline == root) {
|
|
||||||
p->HalfMove::SetMainline(nullptr);
|
|
||||||
} else {
|
|
||||||
p->HalfMove::RemoveChild(root);
|
|
||||||
}
|
|
||||||
root->AddVariation(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HalfMove::HasParent(HalfMove*m){
|
bool HalfMove::HasParent(HalfMove*m){
|
||||||
return m==parent;
|
return m==static_cast<HalfMove*>(GetParent());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HalfMove::HasChild(HalfMove*m){
|
bool HalfMove::HasChild(HalfMove*m){
|
||||||
if(m==nullptr)
|
if(m==nullptr)
|
||||||
return false;
|
return false;
|
||||||
if(mainline==m){
|
if(static_cast<HalfMove*>(GetMainline())==m){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for(auto var: variations){
|
for(auto var: GetVariations()){
|
||||||
if(var == m)
|
if(static_cast<HalfMove*>(var) == m)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -256,38 +150,34 @@ bool HalfMove::HasChild(HalfMove*m){
|
||||||
|
|
||||||
bool HalfMove::IsVariation() {
|
bool HalfMove::IsVariation() {
|
||||||
HalfMove *m = this;
|
HalfMove *m = this;
|
||||||
HalfMove *p = HalfMove::parent;
|
HalfMove *p = static_cast<HalfMove*>(GetParent());
|
||||||
while (p != nullptr) {
|
while (p != nullptr) {
|
||||||
if (p->mainline != m) {
|
if (static_cast<HalfMove*>(p->GetMainline()) != m) {
|
||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
m = p;
|
m = p;
|
||||||
p = m->HalfMove::parent;
|
p = static_cast<HalfMove*>(m->GetParent());
|
||||||
}
|
}
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string HalfMove::GetFen() { return (fen); }
|
std::string HalfMove::GetFen() { return (fen); }
|
||||||
|
|
||||||
std::vector<HalfMove *> HalfMove::GetVariations() { return (variations); }
|
|
||||||
|
|
||||||
bool HalfMove::IsABlackMove() { return (IsBlack); }
|
|
||||||
|
|
||||||
void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
|
void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
|
||||||
arbiter.Setup(fen);
|
arbiter.Setup(fen);
|
||||||
std::string move_absolute=arbiter.ParseSAN(m->move);
|
std::string move_absolute=arbiter.ParseSAN(m->GetSAN());
|
||||||
m->SetAbsoluteMove(move_absolute);
|
m->SetAbsoluteMove(move_absolute);
|
||||||
bool work = arbiter.Play(move_absolute,arbiter.ParseSANPromotion(m->move));
|
bool work = arbiter.Play(move_absolute,arbiter.ParseSANPromotion(m->GetSAN()));
|
||||||
if (!work) {
|
if (!work) {
|
||||||
wxLogDebug("Bug! %s", m->move);
|
wxLogDebug("Bug! %s", m->GetSAN());
|
||||||
}
|
}
|
||||||
char capture = arbiter.GetCapture();
|
char capture = arbiter.GetCapture();
|
||||||
if (capture != ' ') {
|
if (capture != ' ') {
|
||||||
m->capture = capture;
|
m->capture = capture;
|
||||||
}
|
}
|
||||||
m->fen = arbiter.GetFEN();
|
m->fen = arbiter.GetFEN();
|
||||||
if (m->mainline != nullptr) {
|
if (m->GetMainline() != nullptr) {
|
||||||
BuildAndVerify(m->mainline, arbiter.GetFEN());
|
BuildAndVerify(static_cast<HalfMove*>(m->GetMainline()), arbiter.GetFEN());
|
||||||
} else {
|
} else {
|
||||||
// Otherwise we are on a leaf! So, guess the opening:
|
// Otherwise we are on a leaf! So, guess the opening:
|
||||||
std::string name,eco;
|
std::string name,eco;
|
||||||
|
@ -295,10 +185,10 @@ void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
|
||||||
if(eco.size()>0)
|
if(eco.size()>0)
|
||||||
m->SetOpening(name,eco);
|
m->SetOpening(name,eco);
|
||||||
}
|
}
|
||||||
for (HalfMove *v : m->variations) {
|
for (CMI::HalfMove *v : m->GetVariations()) {
|
||||||
BuildAndVerify(v, fen);
|
BuildAndVerify(static_cast<HalfMove*>(v), fen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void HalfMove::BuildAndVerify(std::string initial_fen) {
|
void HalfMove::BuildAndVerify(std::string initial_fen) {
|
||||||
BuildAndVerify(this, initial_fen);
|
BuildAndVerify(this, initial_fen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "CGEditor.hpp"
|
#include "CMI.hpp"
|
||||||
#include "ChessArbiter.hpp"
|
#include "ChessArbiter.hpp"
|
||||||
#include "ochess.hpp"
|
#include "ochess.hpp"
|
||||||
#include "pgnp.hpp"
|
#include "pgnp.hpp"
|
||||||
|
@ -9,11 +9,7 @@
|
||||||
/**
|
/**
|
||||||
* @brief This class extends CGEHalfMove (to be displayed in the game editor)
|
* @brief This class extends CGEHalfMove (to be displayed in the game editor)
|
||||||
*/
|
*/
|
||||||
class HalfMove : public cgeditor::CGEHalfMove {
|
class HalfMove : public CMI::HalfMove {
|
||||||
HalfMove *parent = nullptr;
|
|
||||||
HalfMove *mainline = nullptr;
|
|
||||||
chessarbiter::ChessArbiter arbiter;
|
|
||||||
std::vector<HalfMove *> variations;
|
|
||||||
std::string fen;
|
std::string fen;
|
||||||
/// @brief Used in to retrieve captured pieces (see GetLineCaptures())
|
/// @brief Used in to retrieve captured pieces (see GetLineCaptures())
|
||||||
char capture;
|
char capture;
|
||||||
|
@ -22,35 +18,20 @@ class HalfMove : public cgeditor::CGEHalfMove {
|
||||||
std::string src,dst;
|
std::string src,dst;
|
||||||
/// @brief Opening reach by that move while taking into account all the parents
|
/// @brief Opening reach by that move while taking into account all the parents
|
||||||
std::string opening, eco;
|
std::string opening, eco;
|
||||||
|
chessarbiter::ChessArbiter arbiter;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HalfMove(HalfMove *m);
|
HalfMove(HalfMove *m);
|
||||||
HalfMove(std::string move_absolute,std::string move_san);
|
HalfMove(std::string move_absolute,std::string move_san);
|
||||||
HalfMove(std::string move_absolute,std::string move_san, std::string fen);
|
HalfMove(std::string move_absolute,std::string move_san, std::string fen);
|
||||||
HalfMove(pgnp::HalfMove *m);
|
HalfMove(CMI::HalfMove *m);
|
||||||
|
|
||||||
~HalfMove();
|
|
||||||
/// @brief Add variation to current move
|
|
||||||
void AddVariation(HalfMove *m);
|
|
||||||
/// @brief Remove the specified child from mainline and/or variations
|
|
||||||
void RemoveChild(HalfMove *m);
|
|
||||||
void AddMove(HalfMove *m);
|
void AddMove(HalfMove *m);
|
||||||
/// @brief Set value of the mailine
|
|
||||||
void SetMainline(HalfMove *m);
|
|
||||||
/// @brief Set this move as mainline
|
|
||||||
void SetAsMainline();
|
|
||||||
/// @brief Promote the current move and submove
|
|
||||||
void Promote();
|
|
||||||
/// @brief Check if current half move is within a variation
|
/// @brief Check if current half move is within a variation
|
||||||
bool IsVariation();
|
bool IsVariation();
|
||||||
/// @brief Get the root of a variation
|
/// @brief Get the root of a variation
|
||||||
bool HasParent(HalfMove*m);
|
bool HasParent(HalfMove*m);
|
||||||
bool HasChild(HalfMove*m);
|
bool HasChild(HalfMove*m);
|
||||||
HalfMove *GetRoot();
|
|
||||||
/// @brief Get parent of the current move
|
|
||||||
HalfMove *GetParent();
|
|
||||||
HalfMove *GetMainline();
|
|
||||||
std::vector<HalfMove *> GetVariations();
|
|
||||||
/// @brief Retrieve the list of moves from the current one to the first one
|
/// @brief Retrieve the list of moves from the current one to the first one
|
||||||
std::vector<HalfMove *> GetLine();
|
std::vector<HalfMove *> GetLine();
|
||||||
std::string GetLineAsSAN();
|
std::string GetLineAsSAN();
|
||||||
|
@ -59,12 +40,9 @@ public:
|
||||||
void SetOpening(const std::string &name, const std::string &eco);
|
void SetOpening(const std::string &name, const std::string &eco);
|
||||||
/// @brief Getters for name and eco
|
/// @brief Getters for name and eco
|
||||||
void GetOpening(std::string &name, std::string &eco);
|
void GetOpening(std::string &name, std::string &eco);
|
||||||
/// @brief Set parent of the current move
|
|
||||||
void SetParent(HalfMove *m);
|
|
||||||
std::string GetFen();
|
std::string GetFen();
|
||||||
void SetFen(std::string fen);
|
void SetFen(std::string fen);
|
||||||
void SetCapture(char c);
|
void SetCapture(char c);
|
||||||
bool IsABlackMove();
|
|
||||||
void GetAbsoluteMove(std::string &src,std::string &dst);
|
void GetAbsoluteMove(std::string &src,std::string &dst);
|
||||||
void SetAbsoluteMove(const std::string &move_absolute);
|
void SetAbsoluteMove(const std::string &move_absolute);
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ GameTabRightPanel::GameTabRightPanel(wxFrame *parent, std::shared_ptr<Game> game
|
||||||
nag_panel->Bind(wxEVT_BUTTON, [p=this](wxCommandEvent &e){
|
nag_panel->Bind(wxEVT_BUTTON, [p=this](wxCommandEvent &e){
|
||||||
HalfMove *m = p->game->GetCurrentMove();
|
HalfMove *m = p->game->GetCurrentMove();
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
m->nag=p->GetNagFromStr(((wxButton*)e.GetEventObject())->GetLabel().ToStdString());
|
m->SetNAG(p->editor_canvas->GetNAGId(((wxButton*)e.GetEventObject())->GetLabel().ToStdString()));
|
||||||
p->editor_canvas->Refresh();
|
p->editor_canvas->Refresh();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -103,9 +103,9 @@ void GameTabRightPanel::OnCommentChange(wxCommandEvent &event) {
|
||||||
wxLogDebug("GameTabRightPanel: comment input change");
|
wxLogDebug("GameTabRightPanel: comment input change");
|
||||||
HalfMove *m = game->GetCurrentMove();
|
HalfMove *m = game->GetCurrentMove();
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
m->comment=event.GetString().Trim().ToStdString();
|
m->SetComment(event.GetString().Trim().ToStdString());
|
||||||
// Remove newlines:
|
// Remove newlines:
|
||||||
for(char &c:m->comment){
|
for(char &c:m->GetComment()){
|
||||||
if(c=='\n')
|
if(c=='\n')
|
||||||
c=' ';
|
c=' ';
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ void GameTabRightPanel::Notify() {
|
||||||
HalfMove *m = game->GetCurrentMove();
|
HalfMove *m = game->GetCurrentMove();
|
||||||
if (m != nullptr) {
|
if (m != nullptr) {
|
||||||
comment_input->ChangeValue(
|
comment_input->ChangeValue(
|
||||||
m->comment); // ChangeValue do not raise events
|
m->GetComment()); // ChangeValue do not raise events
|
||||||
}
|
}
|
||||||
editor_canvas->SetMoves(game->GetMoves(), m);
|
editor_canvas->SetMoves(game->GetMoves(), m);
|
||||||
// Put it here for now:
|
// Put it here for now:
|
||||||
|
@ -190,49 +190,49 @@ void GameTabRightPanel::RefreshTagsList() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GameTabRightPanel::GetNagFromStr(std::string str){
|
std::uint8_t GameTabRightPanel::GetNagFromStr(std::string str){
|
||||||
// TODO: Bind more NAG!
|
// TODO: Bind more NAG!
|
||||||
if(str=="!")
|
if(str=="!")
|
||||||
return "$1";
|
return 1;
|
||||||
else if(str=="?")
|
else if(str=="?")
|
||||||
return "$2";
|
return 2;
|
||||||
else if(str=="!!")
|
else if(str=="!!")
|
||||||
return "$3";
|
return 3;
|
||||||
else if(str=="??")
|
else if(str=="??")
|
||||||
return "$4";
|
return 4;
|
||||||
else if(str=="!?")
|
else if(str=="!?")
|
||||||
return "$5";
|
return 5;
|
||||||
else if(str=="?!")
|
else if(str=="?!")
|
||||||
return "$6";
|
return 6;
|
||||||
else if(str=="=")
|
else if(str=="=")
|
||||||
return "$10";
|
return 10;
|
||||||
else if(str=="∞")
|
else if(str=="∞")
|
||||||
return "$13";
|
return 13;
|
||||||
else if(str=="⩲")
|
else if(str=="⩲")
|
||||||
return "$14";
|
return 14;
|
||||||
else if(str=="⩱")
|
else if(str=="⩱")
|
||||||
return "$15";
|
return 15;
|
||||||
else if(str=="±")
|
else if(str=="±")
|
||||||
return "$16";
|
return 16;
|
||||||
else if(str=="∓")
|
else if(str=="∓")
|
||||||
return "$17";
|
return 17;
|
||||||
else if(str=="+-")
|
else if(str=="+-")
|
||||||
return "$18";
|
return 18;
|
||||||
else if(str=="-+")
|
else if(str=="-+")
|
||||||
return "$19";
|
return 19;
|
||||||
else if(str=="⨀")
|
else if(str=="⨀")
|
||||||
return "$22";
|
return 22;
|
||||||
else if(str=="○")
|
else if(str=="○")
|
||||||
return "$26";
|
return 26;
|
||||||
else if(str=="⟳")
|
else if(str=="⟳")
|
||||||
return "$32";
|
return 32;
|
||||||
else if(str=="↑")
|
else if(str=="↑")
|
||||||
return "$36";
|
return 36;
|
||||||
else if(str=="→")
|
else if(str=="→")
|
||||||
return "$40";
|
return 40;
|
||||||
else if(str=="⯹")
|
else if(str=="⯹")
|
||||||
return "$44";
|
return 44;
|
||||||
else if(str=="⨁")
|
else if(str=="⨁")
|
||||||
return "$138";
|
return 138;
|
||||||
return "";
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,5 +30,5 @@ public:
|
||||||
void OnLiveAnalysis(wxCommandEvent &event);
|
void OnLiveAnalysis(wxCommandEvent &event);
|
||||||
void ApplyPreferences();
|
void ApplyPreferences();
|
||||||
void OnLiveEngineClose(wxCloseEvent &e);
|
void OnLiveEngineClose(wxCloseEvent &e);
|
||||||
std::string GetNagFromStr(std::string str);
|
std::uint8_t GetNagFromStr(std::string str);
|
||||||
};
|
};
|
|
@ -115,52 +115,7 @@ void EditorCanvas::DrawElement(const cgeditor::Element &e) {
|
||||||
dc->DrawRectangle(recToDraw);
|
dc->DrawRectangle(recToDraw);
|
||||||
}
|
}
|
||||||
if(e.prop & cgeditor::Property::Nag){
|
if(e.prop & cgeditor::Property::Nag){
|
||||||
if(text=="$0")
|
text=e.text;
|
||||||
text="";
|
|
||||||
else if(text=="$1")
|
|
||||||
text="!";
|
|
||||||
else if(text=="$2")
|
|
||||||
text="?";
|
|
||||||
else if(text=="$3")
|
|
||||||
text="!!";
|
|
||||||
else if(text=="$4")
|
|
||||||
text="??";
|
|
||||||
else if(text=="$5")
|
|
||||||
text="!?";
|
|
||||||
else if(text=="$6")
|
|
||||||
text="?!";
|
|
||||||
else if(text=="$10")
|
|
||||||
text="=";
|
|
||||||
else if(text=="$13")
|
|
||||||
text="∞";
|
|
||||||
else if(text=="$14")
|
|
||||||
text="⩲";
|
|
||||||
else if(text=="$15")
|
|
||||||
text="⩱";
|
|
||||||
else if(text=="$16")
|
|
||||||
text="±";
|
|
||||||
else if(text=="$17")
|
|
||||||
text="∓";
|
|
||||||
else if(text=="$18")
|
|
||||||
text="+-";
|
|
||||||
else if(text=="$19")
|
|
||||||
text="-+";
|
|
||||||
else if(text=="$22"||text=="$23")
|
|
||||||
text="⨀";
|
|
||||||
else if(text=="$26"||text=="$27")
|
|
||||||
text="○";
|
|
||||||
else if(text=="$32"||text=="$33")
|
|
||||||
text="⟳";
|
|
||||||
else if(text=="$36"||text=="$37")
|
|
||||||
text="↑";
|
|
||||||
else if(text=="$40"||text=="$41")
|
|
||||||
text="→";
|
|
||||||
else if(text=="$44" || text=="$45")
|
|
||||||
text="⯹";
|
|
||||||
else if(text=="$138" || text=="$139")
|
|
||||||
text="⨁";
|
|
||||||
else
|
|
||||||
text="NA";
|
|
||||||
}
|
}
|
||||||
// Draw move text
|
// Draw move text
|
||||||
if (CGEditor::status.UseMoveIcons) {
|
if (CGEditor::status.UseMoveIcons) {
|
||||||
|
@ -177,12 +132,16 @@ void EditorCanvas::DrawElement(const cgeditor::Element &e) {
|
||||||
void EditorCanvas::HandleEvent(const cgeditor::Event &e) {
|
void EditorCanvas::HandleEvent(const cgeditor::Event &e) {
|
||||||
if (e.type == cgeditor::Event::Goto) {
|
if (e.type == cgeditor::Event::Goto) {
|
||||||
game->SetCurrent((HalfMove *)e.move);
|
game->SetCurrent((HalfMove *)e.move);
|
||||||
|
SyncCache();
|
||||||
} else if (e.type == cgeditor::Event::Delete) {
|
} else if (e.type == cgeditor::Event::Delete) {
|
||||||
game->DeleteMove((HalfMove *)e.move);
|
game->DeleteMove((HalfMove *)e.move);
|
||||||
|
SyncCache();
|
||||||
} else if (e.type == cgeditor::Event::Promote) {
|
} else if (e.type == cgeditor::Event::Promote) {
|
||||||
game->PromoteMove((HalfMove *)e.move);
|
game->PromoteMove((HalfMove *)e.move);
|
||||||
|
SyncCache();
|
||||||
} else if (e.type == cgeditor::Event::SetAsMainline) {
|
} else if (e.type == cgeditor::Event::SetAsMainline) {
|
||||||
game->SetMoveAsMainline((HalfMove *)e.move);
|
game->SetMoveAsMainline((HalfMove *)e.move);
|
||||||
|
SyncCache();
|
||||||
}
|
}
|
||||||
wxCommandEvent event(GAME_CHANGE, GetId());
|
wxCommandEvent event(GAME_CHANGE, GetId());
|
||||||
event.SetEventObject(this);
|
event.SetEventObject(this);
|
||||||
|
|
Loading…
Add table
Reference in a new issue