mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Improve engine arrows
This commit is contained in:
parent
f4108bc06c
commit
d6ed30d276
4 changed files with 41 additions and 13 deletions
|
@ -73,6 +73,14 @@ void GameTabLeftPanel::OnPlay(wxCommandEvent &event) {
|
||||||
|
|
||||||
void GameTabLeftPanel::SetEngineArrows(std::vector<std::string> arrows){
|
void GameTabLeftPanel::SetEngineArrows(std::vector<std::string> arrows){
|
||||||
engine_arrows=arrows;
|
engine_arrows=arrows;
|
||||||
|
int min_size=5, max_size=80;
|
||||||
|
int steps=(max_size-min_size)/arrows.size();
|
||||||
|
int current_size=max_size;
|
||||||
|
for(std::string &arrow:engine_arrows){
|
||||||
|
wxLogDebug("%s",arrow);
|
||||||
|
arrow+="#000000%"+std::to_string(current_size);
|
||||||
|
current_size-=steps;
|
||||||
|
}
|
||||||
Notify(true);
|
Notify(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -413,17 +413,38 @@ void BoardCanvas::DrawBoard(wxDC &dc) {
|
||||||
std::uint32_t dx = boardX + (7 - dfile) * square_width + square_width/2;
|
std::uint32_t dx = boardX + (7 - dfile) * square_width + square_width/2;
|
||||||
std::uint32_t dy = boardY + drank * square_width + square_width/2;
|
std::uint32_t dy = boardY + drank * square_width + square_width/2;
|
||||||
|
|
||||||
dc.SetBrush(color_arrows);
|
// Parse arrow for metadata (maybe having a datatype is better)
|
||||||
|
std::uint8_t thickness=50;
|
||||||
|
if(arrow.size()>4){
|
||||||
|
std::string color="#";
|
||||||
|
std::string new_thickness="";
|
||||||
|
char key='?';
|
||||||
|
for(const char &c:arrow){
|
||||||
|
if(c=='#'||c=='%'){
|
||||||
|
key=c;
|
||||||
|
continue;
|
||||||
|
}else if(key=='#'){
|
||||||
|
color+=c;
|
||||||
|
} else if(key=='%'){
|
||||||
|
new_thickness+=c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(color.size()>1)
|
||||||
|
dc.SetBrush(wxColour(color));
|
||||||
|
if(new_thickness.size()>0)
|
||||||
|
thickness=(std::uint8_t)std::stoi(new_thickness);
|
||||||
|
} else
|
||||||
|
dc.SetBrush(color_arrows);
|
||||||
if(((abs(drank-srank) == 2) && (abs(dfile-sfile) == 1))||
|
if(((abs(drank-srank) == 2) && (abs(dfile-sfile) == 1))||
|
||||||
((abs(drank-srank) == 1) && (abs(dfile-sfile) == 2))){
|
((abs(drank-srank) == 1) && (abs(dfile-sfile) == 2))){
|
||||||
if(abs(drank-srank) == 1){
|
if(abs(drank-srank) == 1){
|
||||||
DrawLArrow(dc,sx,sy,dx,dy);
|
DrawLArrow(dc,sx,sy,dx,dy,false,thickness);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DrawLArrow(dc,sx,sy,dx,dy,true);
|
DrawLArrow(dc,sx,sy,dx,dy,true,thickness);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
DrawArrow(dc,sx,sy,dx,dy);
|
DrawArrow(dc,sx,sy,dx,dy,thickness);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -544,7 +565,7 @@ void BoardCanvas::SetClockTime(short hours, short min, short sec,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){
|
void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, std::uint8_t thickness){
|
||||||
// Compute arrow length and angle
|
// Compute arrow length and angle
|
||||||
wxPoint vect(xdst-xsrc,ydst-ysrc);
|
wxPoint vect(xdst-xsrc,ydst-ysrc);
|
||||||
double length=ceil(sqrt(pow(vect.x,2)+pow(vect.y,2)));
|
double length=ceil(sqrt(pow(vect.x,2)+pow(vect.y,2)));
|
||||||
|
@ -560,7 +581,6 @@ void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){
|
||||||
length=ceil(sqrt(pow(vect.x,2)+pow(vect.y,2)));
|
length=ceil(sqrt(pow(vect.x,2)+pow(vect.y,2)));
|
||||||
|
|
||||||
// Compute metrics
|
// Compute metrics
|
||||||
std::uint8_t thickness=50;
|
|
||||||
std::uint8_t tip_height=sqrt(3)/2*thickness;
|
std::uint8_t tip_height=sqrt(3)/2*thickness;
|
||||||
std::uint32_t tail_length=length-tip_height;
|
std::uint32_t tail_length=length-tip_height;
|
||||||
|
|
||||||
|
@ -582,7 +602,7 @@ void BoardCanvas::DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst){
|
||||||
dc.DrawPolygon(4,tail);
|
dc.DrawPolygon(4,tail);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, bool flip){
|
void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, bool flip, std::uint8_t thickness){
|
||||||
double X=xdst-xsrc;
|
double X=xdst-xsrc;
|
||||||
double Y=ydst-ysrc;
|
double Y=ydst-ysrc;
|
||||||
|
|
||||||
|
@ -603,7 +623,6 @@ void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, b
|
||||||
// Draw L shaped arrows
|
// Draw L shaped arrows
|
||||||
if(flip){
|
if(flip){
|
||||||
// Compute metrics
|
// Compute metrics
|
||||||
std::uint8_t thickness=50;
|
|
||||||
double tip_height=sqrt(3)/2*thickness;
|
double tip_height=sqrt(3)/2*thickness;
|
||||||
double yoffset=Y<0 ? -thickness/4 : thickness/4; // Y tail should be longer to form a right angle (corner of tail joins)
|
double yoffset=Y<0 ? -thickness/4 : thickness/4; // Y tail should be longer to form a right angle (corner of tail joins)
|
||||||
if(X<0){tip_height=-tip_height;}
|
if(X<0){tip_height=-tip_height;}
|
||||||
|
@ -623,7 +642,6 @@ void BoardCanvas::DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, b
|
||||||
dc.DrawPolygon(3,tip);
|
dc.DrawPolygon(3,tip);
|
||||||
} else {
|
} else {
|
||||||
// Compute metrics
|
// Compute metrics
|
||||||
std::uint8_t thickness=50;
|
|
||||||
double tip_height=sqrt(3)/2*thickness;
|
double tip_height=sqrt(3)/2*thickness;
|
||||||
double xoffset=X<0 ? -thickness/4 : thickness/4; // Y tail should be longer to form a right angle (corner of tail joins)
|
double xoffset=X<0 ? -thickness/4 : thickness/4; // Y tail should be longer to form a right angle (corner of tail joins)
|
||||||
if(Y<0){tip_height=-tip_height;}
|
if(Y<0){tip_height=-tip_height;}
|
||||||
|
|
|
@ -97,9 +97,9 @@ class BoardCanvas : public wxPanel {
|
||||||
GameState gs;
|
GameState gs;
|
||||||
|
|
||||||
/// @brief Draw an arrow from a source point to a destination point on DC
|
/// @brief Draw an arrow from a source point to a destination point on DC
|
||||||
void DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst);
|
void DrawArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, std::uint8_t thickness=50);
|
||||||
/// @brief Draw an arrow with a L shape (such as knight moves)
|
/// @brief Draw an arrow with a L shape (such as knight moves)
|
||||||
void DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, bool flip=false);
|
void DrawLArrow(wxDC &dc, int xsrc, int ysrc, int xdst, int ydst, bool flip=false, std::uint8_t thickness=50);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BoardCanvas(wxFrame *parent);
|
BoardCanvas(wxFrame *parent);
|
||||||
|
|
|
@ -105,14 +105,16 @@ void LiveEngineDialog::OnTimerTick(wxTimerEvent &event) {
|
||||||
lines_list->DeleteAllItems();
|
lines_list->DeleteAllItems();
|
||||||
engine->SyncAfter(0);
|
engine->SyncAfter(0);
|
||||||
EngineEvaluation *eval=new EngineEvaluation();
|
EngineEvaluation *eval=new EngineEvaluation();
|
||||||
for (auto const &line : engine->GetLines()) {
|
auto const &lines=engine->GetLines();
|
||||||
|
eval->best_lines.resize(lines.size());
|
||||||
|
for (auto const &line : lines) {
|
||||||
long index = lines_list->InsertItem(0, std::to_string(line.first));
|
long index = lines_list->InsertItem(0, std::to_string(line.first));
|
||||||
std::string line_moves;
|
std::string line_moves;
|
||||||
for (std::string move : line.second.pv) {
|
for (std::string move : line.second.pv) {
|
||||||
line_moves += move + " ";
|
line_moves += move + " ";
|
||||||
}
|
}
|
||||||
if(line.second.pv.size()>0){
|
if(line.second.pv.size()>0){
|
||||||
eval->best_lines.push_back(line.second.pv[0]);
|
eval->best_lines.insert(eval->best_lines.begin()+line.first,line.second.pv[0]);
|
||||||
}
|
}
|
||||||
std::string cp_str = std::to_string(line.second.score_cp);
|
std::string cp_str = std::to_string(line.second.score_cp);
|
||||||
if (line.second.score_cp > 0) {
|
if (line.second.score_cp > 0) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue