string AIEngine::randMove() { srand(time(NULL)); vector< pair<int,int> > validPieces = getValidPieces(); // Randomly choose one of available pieces pair<int,int> piece = validPieces[rand() % validPieces.size()]; vector< pair<int,int> > validMoves = getValidMoves(piece); // Randomly choose one of available moves pair<int,int> move = validMoves[rand() % validMoves.size()]; // Update the board int sX = get<0>(piece), sY = get<1>(piece); board->setIndex(sX, sY, '\0'); int dX = get<0>(move), dY = get<1>(move); if(pieceType == 'X') board->setIndex(dX, dY, 'X'); if(pieceType == 'O') board->setIndex(dY, dY, 'O'); // Convert move choice to string return writeMove(sX, sY, dX, dY); }
string AIEngine::getMove(Board &preBoard, Board &postBoard) { string diff; int xO = -1; int yO = -1; int xM = -1; int yM = -1; if (pieceType == 'X') { for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { if (xO == -1) { if (preBoard.getIndex(i, j) != postBoard.getIndex(i, j)) { xO = i; yO = j; } } else { if (preBoard.getIndex(i, j) != postBoard.getIndex(i, j)) { xM = i; yM = j; } } } } } else { for (int i = 7; i >= 0; i--) { for (int j = 7; j >= 0; j--) { if (xO != -1) { if (preBoard.getIndex(i, j) != postBoard.getIndex(i, j)) { xO = i; yO = j; } } else { if (preBoard.getIndex(i, j) != postBoard.getIndex(i, j)) { xM = i; yM = j; } } } } } return writeMove(xO, yO, xM, yM); }
/*Function exists purely so the user only needs a single function call to get the movement, and so that decorator can make the move without determining momentum twice*/ intVector GoLawnMower::getMove(int dir){ /*increase or decrease momentum*/ determineMom(dir, mStats); /*create a list of steps to attempt*/ intVector curMove = writeMove(dir); /*mLastDir updated last to ensure other getMove() functions can maintain the same structure while utilising both dir and mLastDir*/ mLastDir = dir; return curMove; }
void GCodeExport::finalize(int maxObjectHeight, double moveSpeed, const char* endCode) { writeFanCommand(0); setZ(maxObjectHeight + 5000); writeMove(Point3(0,0,maxObjectHeight + 5000) + getPositionXY(), moveSpeed, 0); writeCode(endCode); log("Print time: %d\n", int(getTotalPrintTime())); log("Filament: %d\n", int(getTotalFilamentUsed(0))); for(int n=1; n<MAX_EXTRUDERS; n++) if (getTotalFilamentUsed(n) > 0) log("Filament%d: %d\n", n + 1, int(getTotalFilamentUsed(n))); output_stream->flush(); }
SimulatedClient::SimulatedClient(int addr, int totalClientPosition, int totalServer, int pathLength, double pleft, double pstay, double pright){ setMyAddr(addr); setTotalClientPosition(totalClientPosition); setMobilityPathLength(pathLength); generateStartPosition(); //setCurrentClientPosition(_startClientPosition); _startClientPosition = 0; _currentClientPosition = 0; setMobilityPattern(pleft, pstay, pright); _mobilityPath = new vector<int>(); generateRandomMove_circle(); writeMove(); _totalServer = totalServer; //generateRandomServer(); printMobilityPath(); }
void GCodeExport::finalize(int maxObjectHeight, int moveSpeed, const char* endCode) { writeFanCommand(0); writeRetraction(); setZ(maxObjectHeight + 5000); writeMove(getPositionXY(), moveSpeed, 0); writeCode(endCode); log("Print time: %d\n", int(getTotalPrintTime())); log("Filament: %d\n", int(getTotalFilamentUsed(0))); log("Filament2: %d\n", int(getTotalFilamentUsed(1))); if (getFlavor() == GCODE_FLAVOR_ULTIGCODE) { char numberString[16]; sprintf(numberString, "%d", int(getTotalPrintTime())); replaceTagInStart("<__TIME__>", numberString); sprintf(numberString, "%d", int(getTotalFilamentUsed(0))); replaceTagInStart("<FILAMENT>", numberString); sprintf(numberString, "%d", int(getTotalFilamentUsed(1))); replaceTagInStart("<FILAMEN2>", numberString); } }
void GCodeExport::writePrimeTrain(double travel_speed) { if (extruder_attr[current_extruder].is_primed) { // extruder is already primed once! return; } Point3 prime_pos = extruder_attr[current_extruder].prime_pos; if (!extruder_attr[current_extruder].prime_pos_is_abs) { prime_pos += currentPosition; } writeMove(prime_pos, travel_speed, 0.0); if (flavor == EGCodeFlavor::GRIFFIN) { *output_stream << "G280" << new_line; } else { // there is no prime gcode for other firmware versions... } extruder_attr[current_extruder].is_primed = true; }
void Spacebot::writeNextMove() { Move move = chooseMove(); writeMove(move); }
void GCodeExport::writeMove(Point3 p, double speed, double extrusion_mm3_per_mm) { writeMove(p.x, p.y, p.z, speed, extrusion_mm3_per_mm); }
void GCodeExport::writeMove(Point p, double speed, double extrusion_mm3_per_mm) { writeMove(p.X, p.Y, zPos, speed, extrusion_mm3_per_mm); }