mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Simplify absolute moves
This commit is contained in:
parent
98edb4253c
commit
3e40032109
4 changed files with 24 additions and 17 deletions
|
@ -5,8 +5,6 @@
|
||||||
#include "ochess.hpp"
|
#include "ochess.hpp"
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
#define UNPACK_ABSOLUTE_MOVE(MOVE,SRC,DST) {(SRC)=(MOVE).substr(0,2);(DST)=(MOVE).substr(2,2);}
|
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
std::string board;
|
std::string board;
|
||||||
std::string initial_fen;
|
std::string initial_fen;
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#include "HalfMove.hpp"
|
#include "HalfMove.hpp"
|
||||||
|
|
||||||
HalfMove::HalfMove(std::string move_absolute,std::string move_san) : capture(' ') {
|
HalfMove::HalfMove(std::string move_absolute,std::string move_san) : capture(' ') {
|
||||||
this->move_absolute=move_absolute;
|
SetAbsoluteMove(move_absolute);
|
||||||
this->move = move_san;
|
this->move = 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(' ') {
|
||||||
this->move_absolute=move_absolute;
|
SetAbsoluteMove(move_absolute);
|
||||||
this->move = move_san;
|
this->move = move_san;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ HalfMove::~HalfMove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
HalfMove::HalfMove(HalfMove *m){
|
HalfMove::HalfMove(HalfMove *m){
|
||||||
move_absolute=m->move_absolute;
|
src=m->src;
|
||||||
|
dst=m->dst;
|
||||||
move=m->move;
|
move=m->move;
|
||||||
fen=m->fen;
|
fen=m->fen;
|
||||||
capture=m->capture;
|
capture=m->capture;
|
||||||
|
@ -137,6 +138,11 @@ void HalfMove::SetAsMainline() {
|
||||||
|
|
||||||
HalfMove *HalfMove::GetMainline() { return (mainline); }
|
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(' ') {
|
HalfMove::HalfMove(pgnp::HalfMove *m) : capture(' ') {
|
||||||
this->move = m->move;
|
this->move = m->move;
|
||||||
this->nag = m->NAG;
|
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::SetFen(std::string fen) { this->fen = fen; }
|
||||||
|
|
||||||
void HalfMove::Promote() {
|
void HalfMove::Promote() {
|
||||||
|
@ -213,8 +224,9 @@ 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);
|
||||||
m->move_absolute=arbiter.ParseSAN(m->move);
|
std::string move_absolute=arbiter.ParseSAN(m->move);
|
||||||
bool work = arbiter.Play(m->move_absolute,arbiter.ParseSANPromotion(m->move));
|
m->SetAbsoluteMove(move_absolute);
|
||||||
|
bool work = arbiter.Play(move_absolute,arbiter.ParseSANPromotion(m->move));
|
||||||
if (!work) {
|
if (!work) {
|
||||||
wxLogDebug("Bug! %s", m->move);
|
wxLogDebug("Bug! %s", m->move);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,9 @@ class HalfMove : public cgeditor::CGEHalfMove {
|
||||||
std::string fen;
|
std::string fen;
|
||||||
char capture;
|
char capture;
|
||||||
void BuildAndVerify(HalfMove *m, std::string fen);
|
void BuildAndVerify(HalfMove *m, std::string fen);
|
||||||
std::string move_absolute;
|
std::string src,dst;
|
||||||
|
|
||||||
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);
|
||||||
|
@ -62,7 +60,8 @@ public:
|
||||||
void SetFen(std::string fen);
|
void SetFen(std::string fen);
|
||||||
void SetCapture(char c);
|
void SetCapture(char c);
|
||||||
bool IsABlackMove();
|
bool IsABlackMove();
|
||||||
std::string GetAbsoluteMove(){return move_absolute;};
|
void GetAbsoluteMove(std::string &src,std::string &dst);
|
||||||
|
void SetAbsoluteMove(const std::string &move_absolute);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Build current move
|
* @brief Build current move
|
||||||
|
|
|
@ -72,34 +72,32 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTabLeftPanel::Notify(bool skip_animation) {
|
void GameTabLeftPanel::Notify(bool skip_animation) {
|
||||||
wxLogDebug("Called!");
|
|
||||||
// Update fen and captures
|
// Update fen and captures
|
||||||
std::string fen = game->GetFen();
|
std::string fen = game->GetFen();
|
||||||
std::map<char, std::uint8_t> captures;
|
std::map<char, std::uint8_t> captures;
|
||||||
bool animate=false;
|
bool animate=false;
|
||||||
HalfMove *m = game->GetCurrentMove();
|
HalfMove *m = game->GetCurrentMove();
|
||||||
std::string src,dst;
|
std::string src,dst;
|
||||||
|
|
||||||
// Update capture and check if we should to animations during moves change:
|
// Update capture and check if we should to animations during moves change:
|
||||||
if (m){
|
if (m){
|
||||||
captures = m->GetLineCaptures();
|
captures = m->GetLineCaptures();
|
||||||
if(m->HasParent(last_move)){
|
if(m->HasParent(last_move)){
|
||||||
UNPACK_ABSOLUTE_MOVE(m->GetAbsoluteMove(),src,dst);
|
m->GetAbsoluteMove(src,dst);
|
||||||
animate=true;
|
animate=true;
|
||||||
}else if(m->HasChild(last_move)){
|
}else if(m->HasChild(last_move)){
|
||||||
// Accessing last_move here is safe since it is still
|
// Accessing last_move here is safe since it is still
|
||||||
// in the tree of moves (since HasChild found it so not deleted)
|
// in the tree of moves (since HasChild found it so not deleted)
|
||||||
UNPACK_ABSOLUTE_MOVE(last_move->GetAbsoluteMove(),dst,src);
|
last_move->GetAbsoluteMove(dst,src);
|
||||||
animate=true;
|
animate=true;
|
||||||
}
|
}
|
||||||
} else if(game->GetNextMove()){ // First move animation
|
} else if(game->GetNextMove()){ // First move animation
|
||||||
HalfMove *next=game->GetNextMove();
|
HalfMove *next=game->GetNextMove();
|
||||||
if(next==last_move){
|
if(next==last_move){
|
||||||
UNPACK_ABSOLUTE_MOVE(game->GetNextMove()->GetAbsoluteMove(),dst,src);
|
game->GetNextMove()->GetAbsoluteMove(dst,src);
|
||||||
animate=true;
|
animate=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update board canvas:
|
// Update board canvas:
|
||||||
if(skip_animation || !animate){
|
if(skip_animation || !animate){
|
||||||
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
|
board_canvas->SetupBoard(chessarbiter::FENParser::Parse(fen).board,
|
||||||
|
|
Loading…
Add table
Reference in a new issue