I am writing a c++ NodeJs native add-on using the v8 that implements a minimax tic-tac-toe AI.
I have a problem where nested functions are not working.
Here is my code:
namespace Game {
Move bestMove(...) {
// implementation
}
}
namespace addon {
using namespace v8;
using std::vector;
...
// this function returns the best move back to nodejs
void bestMove(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
...
auto returnVal = Game::bestMove(params); // Game::bestMove() returns the best move for the computer
args.GetReturnValue().Set((returnVal.row * 3) + returnVal.col); // returns the move back to nodejs
}
Normally, if the game board is this (computer is o):
x _ _
_ _ _
_ _ _
The function shouldn't return 0
because it is already taken by x
.
However it seems to always return 0
.
After I investigated a bit, I realized that the function Game::bestMove()
never gets called.
Add yes, I know this is the problem because after I added std::cout << "Computing";
in the function Move bestMove()
, it never got printed to the console.
However, if I add std::cout << "Computing";
in the function addon::bestMove()
, it works.
There is also no compile time error thrown.
Thanks for any help.