aboutsummaryrefslogtreecommitdiff
path: root/src/game_tab/HalfMove.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game_tab/HalfMove.cpp')
-rw-r--r--src/game_tab/HalfMove.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/game_tab/HalfMove.cpp b/src/game_tab/HalfMove.cpp
index 7f19480..32924e1 100644
--- a/src/game_tab/HalfMove.cpp
+++ b/src/game_tab/HalfMove.cpp
@@ -1,13 +1,13 @@
#include "HalfMove.hpp"
HalfMove::HalfMove(std::string move_absolute,std::string move_san) : capture(' ') {
- this->move_absolute=move_absolute;
+ SetAbsoluteMove(move_absolute);
this->move = move_san;
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(' ') {
- this->move_absolute=move_absolute;
+ SetAbsoluteMove(move_absolute);
this->move = move_san;
}
@@ -21,7 +21,8 @@ HalfMove::~HalfMove() {
}
HalfMove::HalfMove(HalfMove *m){
- move_absolute=m->move_absolute;
+ src=m->src;
+ dst=m->dst;
move=m->move;
fen=m->fen;
capture=m->capture;
@@ -137,6 +138,11 @@ void HalfMove::SetAsMainline() {
HalfMove *HalfMove::GetMainline() { return (mainline); }
+void HalfMove::SetAbsoluteMove(const std::string &move_absolute){
+ this->src=move_absolute.substr(0,2);
+ this->dst=move_absolute.substr(2,2);
+}
+
HalfMove::HalfMove(pgnp::HalfMove *m) : capture(' ') {
this->move = m->move;
this->nag = m->NAG;
@@ -151,6 +157,11 @@ HalfMove::HalfMove(pgnp::HalfMove *m) : capture(' ') {
}
}
+void HalfMove::GetAbsoluteMove(std::string &src,std::string &dst){
+ src=this->src;
+ dst=this->dst;
+}
+
void HalfMove::SetFen(std::string fen) { this->fen = fen; }
void HalfMove::Promote() {
@@ -177,6 +188,23 @@ void HalfMove::Promote() {
}
}
+bool HalfMove::HasParent(HalfMove*m){
+ return m==parent;
+}
+
+bool HalfMove::HasChild(HalfMove*m){
+ if(m==nullptr)
+ return false;
+ if(mainline==m){
+ return true;
+ }
+ for(auto var: variations){
+ if(var == m)
+ return true;
+ }
+ return false;
+}
+
bool HalfMove::IsVariation() {
HalfMove *m = this;
HalfMove *p = HalfMove::parent;
@@ -198,8 +226,9 @@ bool HalfMove::IsABlackMove() { return (IsBlack); }
void HalfMove::BuildAndVerify(HalfMove *m, std::string fen) {
arbiter.Setup(fen);
- m->move_absolute=arbiter.ParseSAN(m->move);
- bool work = arbiter.Play(m->move_absolute,arbiter.ParseSANPromotion(m->move));
+ std::string move_absolute=arbiter.ParseSAN(m->move);
+ m->SetAbsoluteMove(move_absolute);
+ bool work = arbiter.Play(move_absolute,arbiter.ParseSANPromotion(m->move));
if (!work) {
wxLogDebug("Bug! %s", m->move);
}