I want to run my minimax algorithm async so it doesn't freeze the ui while waiting for a turn. Here is the static method i need to call:
//ChessContext is the current state of the board
//Turn contains fromX, fromY, toX, toY when moving a piece
static Turn getBestTurn(ChessContext cc, int depth);
I have tried this:
//context is a reference to the game currently played
auto fu = std::async(std::launch::async, ChessContext::getBestTurn, context , 5);
Turn t = fu.get();
It's giving me an error saying
boardview.cpp:69:23: error: no matching function for call to 'async'
future:1712:5: note: candidate template ignored: substitution failure [with _Fn = Turn (&)(ChessContext, int), _Args = <ChessContext &, int>]:
no type named 'type' in 'std::result_of<Turn ((ChessContext, int))(ChessContext, int)>'
future:1745:5: note: candidate template ignored: substitution failure [with _Fn = std::launch, _Args = <Turn (&)(ChessContext, int), ChessContext &, int>]:
no type named 'type' in 'std::result_of<std::launch (Turn ()(ChessContext, int), ChessContext, int)>'
I eventually want to run the algorithm on every possible turn on a separate thread, or on two threads at a time to see if it gives me a performance increase.
Minimal code:
#include <iostream>
#include <thread>
#include <future>
class Turn
{
};
class ChessContext
{
public:
ChessContext();
ChessContext(ChessContext &cc);
static Turn getBestTurn(ChessContext cc, int depth);
};
int main(){
ChessContext context;
auto fu = std::async(std::launch::async, ChessContext::getBestTurn, context, 5);
}
Here is the full project https://github.com/zlatkovnik/Super-Chesster.git