-
Notifications
You must be signed in to change notification settings - Fork 104
add a new functions #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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` | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update this name (see above) |
||
| * **Args:** None | ||
| * **Action:** Round turn the robot ninty degrees to the right | ||
| * **Response:** `ack` once the movement completes | ||
|
|
||
| #### `runLeft` | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please update this name (see above) |
||
| * **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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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); | ||||||
|
|
||||||
|
Comment on lines
+296
to
+299
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an unrelated change. Can you split it out into its own pull request? Same goes for similar changes below. |
||||||
| // 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(); | ||||||
|
Comment on lines
+730
to
+732
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't need to redundantly store the slider value here |
||||||
| } 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" ) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| turn(Movement::RUN_RIGHT); | ||||||
| return ""; | ||||||
| } else if (function == "runLeft" ) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| turn(Movement::RUN_LEFT); | ||||||
| return ""; | ||||||
| } else if (function == "turnBack" ) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| turn(Movement::TURN_RIGHT_180); | ||||||
| return ""; | ||||||
| } else if (function == "turnRight" || function == "turnRight90" ) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Comment on lines
+1132
to
+1134
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep this PR strictly scoped to curve turns. Please split this into its own PR. |
||||||
| turn(Movement::TURN_RIGHT_90); | ||||||
| return ""; | ||||||
| } else if (function == "turnLeft" || function == "turnLeft90") { | ||||||
| } else if (function == "turnLeft" || function == "turnLeft90" ) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| 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 | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is getting a bit too big. Can you create a separate helper function for the curve turn logic? |
||||||
| 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 | ||||||
|
Comment on lines
+1530
to
+1548
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting change but probably belongs as its own PR, because I'm not convinced programmatically setting the speed slider is wise. (There might be other ways to accomplish the goal of making the mouse acceleration more realistic and apparent.) |
||||||
| // 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() ); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this comment. |
||||||
| if (isWall(semiPos, semiDir)) { | ||||||
| return true; | ||||||
| } | ||||||
| } | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| double progressRequired(Movement movement); | ||||||
| void updateMouseProgress(double progress); | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename these to
curveTurnRightandcurveTurnLeftfor explicitness