Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ void turnRight();
void turnLeft();
void turnRight45();
void turnLeft45();
void runRight();
void runLeft();
Comment on lines +120 to +121
Copy link
Owner

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 curveTurnRight and curveTurnLeft for explicitness


void setWall(int x, int y, char direction);
void clearWall(int x, int y, char direction);
Expand Down Expand Up @@ -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`
Copy link
Owner

Choose a reason for hiding this comment

The 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`
Copy link
Owner

Choose a reason for hiding this comment

The 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
Expand Down
135 changes: 121 additions & 14 deletions src/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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());

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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());
Expand Down Expand Up @@ -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" ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (function == "runRight" ) {
} else if (function == "runRight") {

turn(Movement::RUN_RIGHT);
return "";
} else if (function == "runLeft" ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (function == "runLeft" ) {
} else if (function == "runLeft") {

turn(Movement::RUN_LEFT);
return "";
} else if (function == "turnBack" ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (function == "turnBack" ) {
} else if (function == "turnBack") {

turn(Movement::TURN_RIGHT_180);
return "";
} else if (function == "turnRight" || function == "turnRight90" ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (function == "turnRight" || function == "turnRight90" ) {
} else if (function == "turnRight" || function == "turnRight90") {

Comment on lines +1132 to +1134
Copy link
Owner

Choose a reason for hiding this comment

The 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" ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (function == "turnLeft" || function == "turnLeft90" ) {
} else if (function == "turnLeft" || function == "turnLeft90") {

turn(Movement::TURN_LEFT_90);
return "";
} else if (function == "turnRight45") {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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) {
Expand Down Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The 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);
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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() );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment.

if (isWall(semiPos, semiDir)) {
return true;
}
}
return false;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -177,6 +180,7 @@ class Window : public QMainWindow {
double m_movementProgress;
double m_movementStepSize;
QSlider *m_speedSlider;
int m_sliderValue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
int m_sliderValue;
int m_sliderValue;


double progressRequired(Movement movement);
void updateMouseProgress(double progress);
Expand Down