void Eximo::parsePrologRemainingString(const string& str) { string piecesStr = getSubstringBetween(str, "]],[", ""); // explode that string to a vector of strings vector<string> vec = explodeString(piecesStr, "[,]"); int numWhitePlayerPieces = atoi(vec[0].c_str()); int numBlackPlayerPieces = atoi(vec[1].c_str()); if (eximoGame->numPlayerPieces.first == -1) eximoGame->numPlayerPieces.first = numWhitePlayerPieces; else if (numWhitePlayerPieces != eximoGame->numPlayerPieces.first) { // if player no. pieces changed, update scoreboard if (eximoGame->numPlayerPieces.first - numWhitePlayerPieces > 0) { scoreboard->setScoreboard(WHITE_PLAYER, DEC); captureCell.setX( srcCell.getX() + (destCell.getX() - srcCell.getX()) / 2); captureCell.setY( srcCell.getY() + (destCell.getY() - srcCell.getY()) / 2); capturingChecker = true; capturedCheckerOwner = WHITE_PLAYER; } else scoreboard->setScoreboard(WHITE_PLAYER, INC); eximoGame->numPlayerPieces.first = numWhitePlayerPieces; } if (eximoGame->numPlayerPieces.second == -1) eximoGame->numPlayerPieces.second = numBlackPlayerPieces; else if (numBlackPlayerPieces != eximoGame->numPlayerPieces.second) { // if player no. pieces changed, update scoreboard if (eximoGame->numPlayerPieces.second - numBlackPlayerPieces > 0) { scoreboard->setScoreboard(BLACK_PLAYER, DEC); captureCell.setX( srcCell.getX() + (destCell.getX() - srcCell.getX()) / 2); captureCell.setY( srcCell.getY() + (destCell.getY() - srcCell.getY()) / 2); capturingChecker = true; capturedCheckerOwner = BLACK_PLAYER; } else scoreboard->setScoreboard(BLACK_PLAYER, INC); eximoGame->numPlayerPieces.second = numBlackPlayerPieces; } eximoGame->currentPlayer = stringToPlayer(vec[2]); eximoGame->gameMode = stringToGameMode(vec[3]); }
int8_t MG2639_Cell::getIMI(char * imiRet) { int iRetVal; sendATCommand(READ_IMI); // Send "AT+CIMI" // Successful response e.g.: AT+CIMI\r\n460030916875923\r\nOK\r\n // Fail response e.g.: ERROR iRetVal = readWaitForResponses(RESPONSE_OK, RESPONSE_ERROR, COMMAND_RESPONSE_TIME); if (iRetVal > 0) { // Get the substring between the first \n and second \r: getSubstringBetween(imiRet, (const char *) rxBuffer, '\n', '\r'); } return iRetVal; }
int8_t MG2639_Cell::getICCID(char * iccidRet) { int iRetVal; sendATCommand(GET_ICCID); // Send "AT+ZGETICCID" // Response will be e.g.: "+ZGETICCID: 89860042190733578148\r\nOK\r\n" or // "ERROR" if a SIM card is not inserted iRetVal = readWaitForResponses(RESPONSE_OK, RESPONSE_ERROR, COMMAND_RESPONSE_TIME); if (iRetVal > 0) { // Get the substring between the first space and the first \r // store it in [iccidRet]. getSubstringBetween(iccidRet, (const char *) rxBuffer, ' ', '\r'); } return iRetVal; }
void Eximo::parsePrologBoardString(const string& str) { // clear previous board eximoGame->board.clear(); // get substring representing the current board string boardStr = getSubstringBetween(str, "[[[", "]]"); // explode that string to a vector of strings vector<string> rawBoard = explodeString(boardStr, "[,]"); vector<Cell> boardLine; int boardSize = sqrt(rawBoard.size()); for (unsigned int i = 0; i < rawBoard.size(); i++) { boardLine.push_back(stringToCell(rawBoard[i])); if ((i + 1) % boardSize == 0) { eximoGame->board.push_back(boardLine); boardLine.clear(); } } }