Update metadata and debug opening guesser

This commit is contained in:
Loic Guegan 2023-01-16 17:18:54 +01:00
parent 3b11b9d4f3
commit 3846e5f9f6
4 changed files with 26 additions and 15 deletions

View file

@ -145,24 +145,11 @@ void Game::GetOpening(std::string &name,std::string &eco){
}else { }else {
// If not, get the current move line (or first move) // If not, get the current move line (or first move)
// and try to guess opening // and try to guess opening
auto line=m->GetLine(); // Vector of HalfMove wxGetApp().GetBook().GuessOpening(m->GetLineAsSAN(),name,eco);
std::string pgn;
int count=1;
for(int i=0;i<line.size();i++){
if(i%2==0){
pgn+=std::to_string(count)+".";
count+=1;
}
pgn+=line[i]->move +" ";
}
// If there is a line, try to guess the opening
if(pgn.size()>0){
wxGetApp().GetBook().GuessOpening(pgn,name,eco);
m->SetOpening(name,eco); m->SetOpening(name,eco);
} }
} }
} }
}
void Game::Previous() { void Game::Previous() {
if (current != nullptr) { if (current != nullptr) {

View file

@ -48,10 +48,27 @@ std::vector<HalfMove *> HalfMove::GetLine(){
else else
m=m->parent; m=m->parent;
} }
// Reverse the order to get it in the played order:
std::reverse(line.begin(), line.end()); std::reverse(line.begin(), line.end());
return line; return line;
} }
std::string HalfMove::GetLineAsSAN(){
// If not, get the current move line (or first move)
// and try to guess opening
auto line=GetLine(); // Vector of HalfMove
std::string pgn;
int count=1;
for(int i=0;i<line.size();i++){
if(i%2==0){
pgn+=std::to_string(count)+".";
count+=1;
}
pgn+=line[i]->move +" ";
}
return pgn;
}
HalfMove::HalfMove(HalfMove *m){ HalfMove::HalfMove(HalfMove *m){
src=m->src; src=m->src;
dst=m->dst; dst=m->dst;
@ -271,6 +288,12 @@ void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
m->fen = arbiter.GetFEN(); m->fen = arbiter.GetFEN();
if (m->mainline != nullptr) { if (m->mainline != nullptr) {
BuildAndVerify(m->mainline, arbiter.GetFEN()); BuildAndVerify(m->mainline, arbiter.GetFEN());
} else {
// Otherwise we are on a leaf! So, guess the opening:
std::string name,eco;
wxGetApp().GetBook().GuessOpening(m->GetLineAsSAN(),name,eco);
if(eco.size()>0)
m->SetOpening(name,eco);
} }
for (HalfMove *v : m->variations) { for (HalfMove *v : m->variations) {
BuildAndVerify(v, fen); BuildAndVerify(v, fen);

View file

@ -53,6 +53,7 @@ public:
std::vector<HalfMove *> GetVariations(); 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::map<char, std::uint8_t> GetLineCaptures(); std::map<char, std::uint8_t> GetLineCaptures();
/// @brief The opening name of current line /// @brief The opening name of current line
void SetOpening(const std::string &name, const std::string &eco); void SetOpening(const std::string &name, const std::string &eco);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 314 KiB

After

Width:  |  Height:  |  Size: 188 KiB

Before After
Before After