From 6b8f5ed7ad2f0e20669f50f134021b08ec5144f5 Mon Sep 17 00:00:00 2001 From: gitJustin86 Date: Mon, 8 Apr 2019 19:52:01 +0100 Subject: [PATCH] justins polynomial knight implementation please don't insult it, he loves math! --- src/chess.cpp | 21 ++++++++++++++++++++- src/functions.cpp | 37 +++++++++++++++++++++++++------------ 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/chess.cpp b/src/chess.cpp index 0b8ad3b..58ad503 100755 --- a/src/chess.cpp +++ b/src/chess.cpp @@ -17,6 +17,25 @@ int main(){ cout << endl; } - cout << "poly test" << endl; + cout << "poly X" << endl; cout << "(1," << poly_knight_offset_x(1) << ")" << endl; + cout << "(2," << poly_knight_offset_x(2) << ")" << endl; + cout << "(3," << poly_knight_offset_x(3) << ")" << endl; + cout << "(4," << poly_knight_offset_x(4) << ")" << endl; + cout << "(5," << poly_knight_offset_x(5) << ")" << endl; + cout << "(6," << poly_knight_offset_x(6) << ")" << endl; + cout << "(7," << poly_knight_offset_x(7) << ")" << endl; + cout << "(8," << poly_knight_offset_x(8) << ")" << endl; + cout << "(9," << poly_knight_offset_x(9) << ")" << endl; + cout << "poly Y" << endl; + cout << "(1," << poly_knight_offset_y(1) << ")" << endl; + cout << "(2," << poly_knight_offset_y(2) << ")" << endl; + cout << "(3," << poly_knight_offset_y(3) << ")" << endl; + cout << "(4," << poly_knight_offset_y(4) << ")" << endl; + cout << "(5," << poly_knight_offset_y(5) << ")" << endl; + cout << "(6," << poly_knight_offset_y(6) << ")" << endl; + cout << "(7," << poly_knight_offset_y(7) << ")" << endl; + cout << "(8," << poly_knight_offset_y(8) << ")" << endl; + cout << "(9," << poly_knight_offset_y(9) << ")" << endl; + } diff --git a/src/functions.cpp b/src/functions.cpp index 7397e71..10e127f 100755 --- a/src/functions.cpp +++ b/src/functions.cpp @@ -42,18 +42,31 @@ std::vector get_possible_moves(Position pn, std::array return pns; } -int poly_knight_offset_x(int x) { - return -2.1500176772557799*pow(10,2)*pow(x,0) + - +5.0175460279545990*pow(10,2)*pow(x,1) + - -4.3971301635198080*pow(10,2)*pow(x,2) + - +1.9251081929895420*pow(10,2)*pow(x,3) + - -4.6354931502296793*pow(10,1)*pow(x,4) + - +6.2293079395174518*pow(10,0)*pow(x,5) + - -4.3751543665888198*pow(10,1)*pow(x,6) + - +1.2500918807028260*pow(10,2)*pow(x,7) + - -2.2939912578846349*pow(10,8)*pow(x,8); +int poly_knight_offset_x(int x) { + return round(-214.986133*pow(10,0)*pow(x,0) + + +501.7139779*pow(10,0)*pow(x,1) + + -439.6717407*pow(10,0)*pow(x,2) + + +192.48892*pow(10,0)*pow(x,3) + + -46.34819552*pow(10,0)*pow(x,4) + + +6.228063921*pow(10,0)*pow(x,5) + + -4.373795219*pow(10,-1)*pow(x,6) + + +1.249282993*pow(10,-2)*pow(x,7) + + +1.789952521*pow(10,-7)*pow(x,8)); } +int poly_knight_offset_y(int x) { + return round(-31.99806307*pow(10,0)*pow(x,0) + + +79.90649854*pow(10,0)*pow(x,1) + + -70.06372154*pow(10,0)*pow(x,2) + + +30.59414865*pow(10,0)*pow(x,3) + + -7.360163258*pow(10,0)*pow(x,4) + + +9.887137664*pow(10,-1)*pow(x,5) + + -6.942530952*pow(10,-2)*pow(x,6) + + +1.98298821*pow(10,-3)*pow(x,7) + + +2.84277784*pow(10,-8)*pow(x,8)); +} + + std::vector get_all_moves(Position pn, std::array board){ PieceType pt = board[pn]; std::vector pns; @@ -101,8 +114,8 @@ std::vector get_all_moves(Position pn, std::array board case PieceType::W_KNIGHT: for (int j = 7; j >= 0; j--){ for (int i = 0; i < 8; i++){ - for (int k = 0; k < 9; k++){ - if (std::make_pair(x+knt_dx[k],y+knt_dy[k]) == std::make_pair(i,j)) + for (int k = 1; k < 10; k++){ + if (std::make_pair(x+poly_knight_offset_x(k),y+poly_knight_offset_y(k)) == std::make_pair(i,j)) pns.push_back(pair_to_pos(std::make_pair(i,j))); } }