bool ChessAI::nextMove() { Square s, e; if (!isSetUp) { err << "nextMove() called when ChessAI not yet set up" << err; return false; } copyInData(game); if (gameOver) { err << "nextMove() caalled after game is over" << err; return false; } if (colorToMove!=myColor) { err << "called chessAI with wrong color to move" << err; return false; } err << "\n\n" << err; bool success=findBestMove(true, settings.checkDepth); return success; }
void MatlabTemplateComponentImpl<Tin,Tout>::process() { //Get the input buffer inBuf_->getReadData(readDataSet_); //Check dimensions of our matlab matrix const mwSize* dims = mxGetDimensions(matlabInput_); size_t s = readDataSet_->data.size(); if(s != dims[0]) { mxDestroyArray(matlabInput_); if(TypeInfo<T>::isComplex) { matlabInput_ = mxCreateDoubleMatrix(1, s, mxCOMPLEX); } else { matlabInput_ = mxCreateDoubleMatrix(1, s, mxREAL); } } //Copy data into our matlab matrix copyInData(readDataSet_->data, matlabInput_); //bug in matlab windows - has to be reopened every time #ifdef _WIN32 // _WIN32 is defined by all Windows 32 compilers, but not by others. if(!matlab_.open("")) { throw ResourceNotFoundException("Failed to start Matlab engine"); } #endif //Send data to matlab matlab_.putVariable("matlab_input", matlabInput_); //Use OutputBuffer to capture MATLAB output memset(buffer_, 0, 256 * sizeof(char)); matlab_.outputBuffer(buffer_, 256); //Process in Matlab matlab_.evalString(command_.c_str()); //The evaluate string returns the result into the output buffer if (buffer_[0] != 0) { LOG(LWARNING) << buffer_; } //Output data if required if(hasOutput_x || passThrough_x) { if(passThrough_x) { //Get a write data set outBuf_->getWriteData(writeDataSet_, readDataSet_->data.size()); //Copy data through copy(readDataSet_->data.begin(), readDataSet_->data.end(), writeDataSet_->data.begin()); writeDataSet_->sampleRate = readDataSet_->sampleRate; writeDataSet_->timeStamp = readDataSet_->timeStamp; } else { //Get the matlab output mxArray* matlab_output = matlab_.getVariable("matlab_output"); size_t m = mxGetM(matlab_output); size_t n = mxGetN(matlab_output); //Get a write data set of the correct size and copy data outBuf_->getWriteData(writeDataSet_, m>n?m:n); copyOutData(matlab_output, writeDataSet_->data); } //Release write data set outBuf_->releaseWriteData(writeDataSet_); } //Release read data set inBuf_->releaseReadData(readDataSet_); }