From 93566b4067dfff7e3e105c41c46c216cd8b8ae05 Mon Sep 17 00:00:00 2001 From: David Lee <54704426+GoGoCom@users.noreply.github.com> Date: Mon, 15 Dec 2025 07:49:41 +1100 Subject: [PATCH] add a new functions I added two functions such as a round turn left and right named runRight, runLeft. --- README.md | 12 +++++ src/Window.cpp | 135 ++++++++++++++++++++++++++++++++++++++++++++----- src/Window.h | 4 ++ 3 files changed, 137 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 67995b41..04e8b7cf 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,8 @@ void turnRight(); void turnLeft(); void turnRight45(); void turnLeft45(); +void runRight(); +void runLeft(); void setWall(int x, int y, char direction); void clearWall(int x, int y, char direction); @@ -205,6 +207,16 @@ int/float getStat(string stat); * **Action:** Turn the robot forty-five degrees to the left * **Response:** `ack` once the movement completes +#### `runRight` +* **Args:** None +* **Action:** Round turn the robot ninty degrees to the right +* **Response:** `ack` once the movement completes + +#### `runLeft` +* **Args:** None +* **Action:** Round Turn the robot ninty degrees to the left +* **Response:** `ack` once the movement completes + #### `setWall X Y D` * **Args:** * `X` - The X coordinate of the cell diff --git a/src/Window.cpp b/src/Window.cpp index f43ab704..b2a97922 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -293,6 +293,10 @@ Window::Window(QWidget *parent) refreshMazeFileComboBox(path); updateMazeAndPath(maze, path); + QStringList SplitStr = path.split("/"); + QString TitleStr = SplitStr.takeLast(); + this->setWindowTitle("mms : "+TitleStr); + // Add the mouse algos refreshMouseAlgoComboBox(SettingsMisc::getRecentMouseAlgo()); @@ -409,6 +413,10 @@ void Window::updateMazeAndPath(Maze *maze, QString path) { updateMaze(maze); m_currentMazeFile = path; SettingsMisc::setRecentMazeFile(path); + + QStringList SplitStr = path.split("/"); + QString TitleStr = SplitStr.takeLast(); + this->setWindowTitle("mms : "+TitleStr); } void Window::updateMaze(Maze *maze) { @@ -719,6 +727,9 @@ void Window::startRun() { // Only enabled while mouse is running m_pauseButton->setEnabled(true); m_resetButton->setEnabled(true); + + // for mouse speed control + m_sliderValue = m_speedSlider->value(); } else { // Clean up the failed process m_runOutput->appendPlainText(process->errorString()); @@ -1111,10 +1122,19 @@ QString Window::executeCommand(QString command) { } bool success = moveForward(numHalfSteps); return success ? "" : CRASH; - } else if (function == "turnRight" || function == "turnRight90") { + } else if (function == "runRight" ) { + turn(Movement::RUN_RIGHT); + return ""; + } else if (function == "runLeft" ) { + turn(Movement::RUN_LEFT); + return ""; + } else if (function == "turnBack" ) { + turn(Movement::TURN_RIGHT_180); + return ""; + } else if (function == "turnRight" || function == "turnRight90" ) { turn(Movement::TURN_RIGHT_90); return ""; - } else if (function == "turnLeft" || function == "turnLeft90") { + } else if (function == "turnLeft" || function == "turnLeft90" ) { turn(Movement::TURN_LEFT_90); return ""; } else if (function == "turnRight45") { @@ -1213,12 +1233,18 @@ double Window::progressRequired(Movement movement) { case Movement::TURN_RIGHT_45: case Movement::TURN_LEFT_45: return 16.66; + case Movement::TURN_RIGHT_180: case Movement::TURN_RIGHT_90: case Movement::TURN_LEFT_90: return 33.33; + case Movement::RUN_RIGHT: + case Movement::RUN_LEFT: + return 33.33 * 1.5; default: ASSERT_NEVER_RUNS(); } + + return 0.0; } void Window::updateMouseProgress(double progress) { @@ -1265,6 +1291,12 @@ void Window::updateMouseProgress(double progress) { destinationRotation -= Angle::Degrees(90); } else if (m_movement == Movement::TURN_LEFT_90) { destinationRotation += Angle::Degrees(90); + } else if (m_movement == Movement::TURN_RIGHT_180) { + destinationRotation -= Angle::Degrees(180); + } else if (m_movement == Movement::RUN_RIGHT) { + destinationRotation -= Angle::Degrees(90); + } else if (m_movement == Movement::RUN_LEFT) { + destinationRotation += Angle::Degrees(90); } else { ASSERT_NEVER_RUNS(); } @@ -1279,15 +1311,65 @@ void Window::updateMouseProgress(double progress) { double fraction = 1.0 - (remaining / required); // Calculate the current translation and rotation - Coordinate startingTranslation = getCoordinate(m_startingPosition); + Coordinate startingTranslation = getCoordinate(m_startingPosition); Coordinate destinationTranslation = getCoordinate(destinationLocation); + Angle startingRotation = DIRECTION_TO_ANGLE().value(m_startingDirection); + + Coordinate currentTranslation = startingTranslation * (1.0 - fraction) + destinationTranslation * fraction; + Angle currentRotation = startingRotation * (1.0 - fraction) + destinationRotation * fraction; + + // Calculate the current translation and rotation for a curv turn + if (m_movement == Movement::RUN_RIGHT || m_movement == Movement::RUN_LEFT) { + //- m_runOutput->appendPlainText("run test"); + if (m_startingDirection == SemiDirection::NORTH) { + destinationLocation.y += 1; + if (m_movement == Movement::RUN_RIGHT) { + currentTranslation += Coordinate::Cartesian( Dimensions::halfTileLength() * (1.0 - currentRotation.getSin()) * +1, Dimensions::halfTileLength()*currentRotation.getCos() * +1 ); + //destinationLocation.first += 1; + } + else if (m_movement == Movement::RUN_LEFT) { + currentTranslation += Coordinate::Cartesian( Dimensions::halfTileLength() * (1.0 - currentRotation.getSin()) * -1, Dimensions::halfTileLength()*currentRotation.getCos() * -1 ); + //destinationLocation.first -= 1; + } + } + else if (m_startingDirection == SemiDirection::EAST) { + destinationLocation.x += 1; + if (m_movement == Movement::RUN_RIGHT) { + currentTranslation += Coordinate::Cartesian( Dimensions::halfTileLength() * ( currentRotation.getSin()) * -1, Dimensions::halfTileLength()*(1.0 - currentRotation.getCos()) * -1 ); + //destinationLocation.second -= 1; + } + else if (m_movement == Movement::RUN_LEFT) { + currentTranslation += Coordinate::Cartesian( Dimensions::halfTileLength() * ( currentRotation.getSin()) * +1, Dimensions::halfTileLength()*(1.0 - currentRotation.getCos()) * +1); + //destinationLocation.second += 1; + } + } + else if (m_startingDirection == SemiDirection::SOUTH) { + destinationLocation.y -= 1; + if (m_movement == Movement::RUN_RIGHT) { + currentTranslation += Coordinate::Cartesian( Dimensions::halfTileLength() * (1.0 + currentRotation.getSin()) * -1, Dimensions::halfTileLength()*( currentRotation.getCos()) * +1 ); + //destinationLocation.first -= 1; + } + else if (m_movement == Movement::RUN_LEFT) { + currentTranslation += Coordinate::Cartesian( Dimensions::halfTileLength() * (1.0 + currentRotation.getSin()) * +1, Dimensions::halfTileLength()*( currentRotation.getCos()) * -1); + //destinationLocation.first += 1; + } + } + else if (m_startingDirection == SemiDirection::WEST) { + destinationLocation.x -= 1; + if (m_movement == Movement::RUN_RIGHT) { + currentTranslation += Coordinate::Cartesian( Dimensions::halfTileLength() * ( currentRotation.getSin()) * -1, Dimensions::halfTileLength()*(1.0 + currentRotation.getCos()) * +1); + //destinationLocation.second += 1; + } + else if (m_movement == Movement::RUN_LEFT) { + currentTranslation += Coordinate::Cartesian( Dimensions::halfTileLength() * ( currentRotation.getSin()) * +1, Dimensions::halfTileLength()*(1.0 + currentRotation.getCos()) * -1); + //destinationLocation.second -= 1; + } + }else { + // stopRun("Stop running because of a wrong direction!"); + return; + } - Angle startingRotation = DIRECTION_TO_ANGLE().value(m_startingDirection); - Coordinate currentTranslation = startingTranslation * (1.0 - fraction) + - destinationTranslation * fraction; - Angle currentRotation = - startingRotation * (1.0 - fraction) + destinationRotation * fraction; - + } // Teleport the mouse, reset movement state if done m_mouse->teleport(currentTranslation, currentRotation); if (remaining == 0.0) { @@ -1445,6 +1527,25 @@ bool Window::moveForward(int numHalfSteps) { stats->startRun(); } // TODO: upforgrabs + // increase the speed by the distance that will be travelled + switch(numHalfSteps) { + case 1: + case 2: + m_speedSlider->setValue(m_sliderValue); + break; + case 3 : + case 4 : + m_speedSlider->setValue(m_sliderValue*1.25); + break; + case 5: + case 6: + m_speedSlider->setValue(m_sliderValue*1.5); + break; + default : + m_speedSlider->setValue(m_sliderValue*2.0); + break; + } + // TODO: upforgrabs // Half steps shouldn't count as a full move // increase the stats by the distance that will be travelled stats->addDistance(numHalfSteps); @@ -1454,10 +1555,13 @@ bool Window::moveForward(int numHalfSteps) { } void Window::turn(Movement movement) { - ASSERT_TR(movement == Movement::TURN_LEFT_45 || + ASSERT_TR(movement == Movement::RUN_LEFT || + movement == Movement::RUN_RIGHT || + movement == Movement::TURN_LEFT_45 || movement == Movement::TURN_LEFT_90 || movement == Movement::TURN_RIGHT_45 || - movement == Movement::TURN_RIGHT_90); + movement == Movement::TURN_RIGHT_90 || + movement == Movement::TURN_RIGHT_180 ); m_movement = movement; // TODO: upforgrabs @@ -1670,6 +1774,7 @@ bool Window::isWall(SemiPosition semiPos, SemiDirection semiDir) const { } else { ASSERT_NEVER_RUNS(); } + return false; } bool Window::isWall(SemiPosition semiPos, SemiDirection semiDir, @@ -1679,8 +1784,9 @@ bool Window::isWall(SemiPosition semiPos, SemiDirection semiDir, if (isWall(semiPos, semiDir)) { return true; } + // m_runOutput->appendPlainText( QVariant(semiPos.x).toString() + " , " + QVariant(semiPos.y).toString() ); for (int i = 1; i <= halfStepsAhead; i += 1) { - switch (semiDir) { + switch (m_mouse->getCurrentDiscretizedRotation()) { case SemiDirection::NORTH: semiPos.y += 1; break; @@ -1712,9 +1818,10 @@ bool Window::isWall(SemiPosition semiPos, SemiDirection semiDir, default: ASSERT_NEVER_RUNS(); } - if (isWall(semiPos, semiDir)) { + } + //m_runOutput->appendPlainText( QVariant(halfStepsAhead).toString() + "-(" + QVariant(semiPos.x).toString() + " , " + QVariant(semiPos.y).toString() + "):" +QVariant( (int) semiDir ).toString() ); + if (isWall(semiPos, semiDir)) { return true; - } } return false; } diff --git a/src/Window.h b/src/Window.h index 39224e28..04bbff27 100644 --- a/src/Window.h +++ b/src/Window.h @@ -29,8 +29,11 @@ enum class Movement { MOVE_DIAGONAL, TURN_RIGHT_45, TURN_RIGHT_90, + TURN_RIGHT_180, TURN_LEFT_45, TURN_LEFT_90, + RUN_RIGHT, + RUN_LEFT , NONE, }; @@ -177,6 +180,7 @@ class Window : public QMainWindow { double m_movementProgress; double m_movementStepSize; QSlider *m_speedSlider; + int m_sliderValue; double progressRequired(Movement movement); void updateMouseProgress(double progress);