void crazyMovement() { int i; for(i=0; i<1000; i++) stopMove(); moveForward(); delay(100); moveBackwards(); delay(100); }
int SimpleDeadlockDetector::init(const BoardState& s) { std::vector<int> targets; int index = 0; for (auto i = s.begin(); i != s.end(); ++i, ++index) { if (!isTarget(*i) && !isPackageOnTarget(*i)) { continue; } targets.push_back(index); } Log::debug(LOG_GAMEIMPL, "Found %i targets", (int)targets.size()); BoardState copy(s); index = 0; for (auto i = s.begin(); i != s.end(); ++i, ++index) { const char field = *i; if (isPackage(field)) { copy.clearFieldForIndex(index); copy.setFieldForIndex(index, Sokoban::GROUND); Log::debug(LOG_GAMEIMPL, "replaced package with ground at %i", index); } else if (isPackageOnTarget(field)) { copy.clearFieldForIndex(index); copy.setFieldForIndex(index, Sokoban::TARGET); Log::debug(LOG_GAMEIMPL, "replaced packageontarget with target at %i", index); } } #ifdef DEBUG Log::debug(LOG_GAMEIMPL, "board state:\n%s", copy.toString().c_str()); #endif for (int targetIndex : targets) { moveBackwards(copy, targetIndex); } index = 0; for (auto i = copy.begin(); i != copy.end(); ++i, ++index) { const char field = *i; if (!isGround(field) && !isPackage(field)) { continue; } if (_visited.find(index) != _visited.end()) { continue; } #ifdef DEBUG int col; int row; s.getColRowFromIndex(index, col, row); Log::debug(LOG_GAMEIMPL, "Simple deadlock detected at %i:%i", col, row); #endif _deadlocks.insert(index); } Log::info(LOG_GAMEIMPL, "Found %i simple deadlocks", (int)_deadlocks.size()); Log::debug(LOG_GAMEIMPL, "Visited %i fields", (int)_visited.size()); _visited.clear(); return (int)_deadlocks.size(); }
void FreeCamera::update(double deltaTime) { float vel = inputVector.z ? slowVelocity : velocity; if (inputVector.x < 0) moveForwards((float)-inputVector.x * vel * (float)deltaTime); else if (inputVector.x > 0) moveBackwards((float)inputVector.x * vel * (float)deltaTime); if (inputVector.y < 0) strafeLeft((float)-inputVector.y * vel * (float)deltaTime); else if (inputVector.y > 0) strafeRight((float)inputVector.y * vel * (float)deltaTime); }
void setup() { connect_to_robot(); initialize_robot(); set_ir_angle(LEFT, -45); set_ir_angle(RIGHT, 45); set_origin(); set_point(0, 0); print_square_centres(); get_motor_encoders(&leftprev, &rightprev); moveBackwards(PHASE1_SPEED, PHASE1_SLOW, START_OFFSET * CM_TO_ENCODER); //move robot to centre of first square. }
// Decides which kind of movement the tank will do with the given signal read from tty port void move(int signal) { if(signal == 1 ){ moveForwards(1); }else if(signal == 2){ moveBackwards(1); }else if(signal == 3){ turnLeft(1); }else if(signal == 4){ turnRight(1); }else if(signal == 0){ stop(); } }
void mediumMovement() { switch(direcao) { case 1: moveForward(); delay(1800); stopMove(); delay(400); break; case 0: moveBackwards(); delay(1800); stopMove(); delay(400); break; } }
void littleMovement() { switch(direcao) { case 1: moveForward(); delay(600); stopMove(); delay(300); break; case 0: moveBackwards(); delay(100); stopMove(); delay(600); break; } }
void turnAroundInPlace() { /* TURN AROUND */ mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; StopFromSpeedHalf(); mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; moveBackwards(); mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; moveForwardHalf(); //Current Mouse Direction int dirx = mouse.direction.x; int diry = mouse.direction.y; //Reverse and go back mouse.direction.x = -dirx; mouse.direction.y = -diry; //Set Position to next block mouse.x += mouse.direction.x; mouse.y -= mouse.direction.y; }
void solveMaze() { //Reset maze to 0 initializeMaze(&maze); //We Know at the starting point, there's something behind us setN(&maze[0][0], 1); mouse.direction.x = 0; mouse.direction.y = -1; mouse.x = 0; mouse.y = 0; //Disable the mouse for now enableDrive(0); turnOnTimers(0, 0); int areWeSearching = UserInterfaceIntro(); //Does the user want to skip the search phase and load a maze from EEPROM if(areWeSearching) { /* SEARCH MAZE */ for(int i = 0; i < 10; i++) { turnOnLeds(7); _delay_ms(10); turnOnLeds(0); _delay_ms(90); } //Init Mouse enableDrive(1); turnOnTimers(1, 1); setDirection(0, 0); //Update Sensors updateSensors(); updateSensors(); updateWalls(); //Go Forward first block mouse.IR_LONG_CHECK_LEFT = 2; mouse.IR_LONG_CHECK_RIGHT = 2; straight(480, 0, mouse.maxVelocity, mouse.maxVelocity, mouse.acceleration, mouse.deceleration); mouse.x += mouse.direction.x; mouse.y -= mouse.direction.y; /* SEARCH */ InitialSearchRun(); //Search is Complete! updateWalls(); /* TURN AROUND */ mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; StopFromSpeedHalf(); mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; moveBackwards(); //Save Maze to EEPROM saveCurrentMaze(); writeMemByte(MOUSE_DIRECTION, firstTurn); mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; moveForwardHalf(); //Current Mouse Direction int dirx = mouse.direction.x; int diry = mouse.direction.y; //Reverse and go back mouse.direction.x = -dirx; mouse.direction.y = -diry; //Set Position to next block mouse.x += mouse.direction.x; mouse.y -= mouse.direction.y; /* RETURN SEARCH*/ ReturnSearchRun(); //Turn Around mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; StopFromSpeedHalf(); mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; moveBackwards(); //Save Maze to EEPROM saveCurrentMaze(); writeMemByte(MOUSE_DIRECTION, firstTurn); /* PICK UP AND PLACE MOUSE */ enableDrive(0); waitForButtonPressed(); } /* FAST RUN */ FastRun(); //Completed Search run, go back and search some more turnAroundInPlace(); floodFill(maze, firstTurn, mouse.x, mouse.y); /* RETURN */ ReturnSearchRun(); //Turn Around mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; StopFromSpeedHalf(); mouse.rightMotor.stepCount = mouse.leftMotor.stepCount = 0; moveBackwards(); //Save Maze to EEPROM saveCurrentMaze(); writeMemByte(MOUSE_DIRECTION, firstTurn); stopMouse(); while(!isButtonPushed(1)); printMaze(maze); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); for (int i = 0; i < MaxRecentFiles; ++i) { recentFileActions[i] = new QAction(this); recentFileActions[i]->setVisible(false); connect(recentFileActions[i], SIGNAL(triggered()), this, SLOT(openRecentFile())); ui->menuFile->insertAction(ui->actionExit, recentFileActions[i]); } recentFilesSeparator = ui->menuFile->insertSeparator(ui->actionExit); form = new Form(this); view = new GraphicsView(form, this); setCentralWidget(view); itemWidget = new ItemWidget(ui->propertyWidget); itemWidget->setHidden(true); connect(view, SIGNAL(mouseDoubleClick()), itemWidget, SLOT(selectPicture())); formWidget = new FormWidget(ui->propertyWidget); formWidget->connectForm(form); formWidget->update(form); ui->propertyWidget->setWidget(formWidget); fontCombo = new QFontComboBox(this); ui->formatToolBar->insertWidget(ui->actionBold, fontCombo); insertGroup = new QActionGroup(this); insertGroup->addAction(ui->actionSelect); insertGroup->addAction(ui->actionPaint); connect(insertGroup, SIGNAL(triggered(QAction*)), this, SLOT(insertObject(QAction*))); ui->actionLeft->setData(Qt::AlignLeft); ui->actionCenter->setData(Qt::AlignHCenter); ui->actionRight->setData(Qt::AlignRight); zoomGroup = new QActionGroup(this); zoomGroup->addAction(ui->actionActualSize); zoomGroup->addAction(ui->actionFitWidth); zoomGroup->addAction(ui->actionFitHeight); connect(zoomGroup, SIGNAL(triggered(QAction*)), this, SLOT(zoom(QAction*))); ui->actionActualSize->setData(GraphicsView::ActualSize); ui->actionFitWidth->setData(GraphicsView::FitWidth); ui->actionFitHeight->setData(GraphicsView::FitHeight); horzAlignGroup = new QActionGroup(this); horzAlignGroup->addAction(ui->actionLeft); horzAlignGroup->addAction(ui->actionCenter); horzAlignGroup->addAction(ui->actionRight); connect(horzAlignGroup, SIGNAL(triggered(QAction*)), this, SLOT(horzAlign(QAction*))); sizeGroup = new QActionGroup(this); sizeGroup->addAction(ui->actionShrinkWidth); sizeGroup->addAction(ui->actionGrowWidth); sizeGroup->addAction(ui->actionPageWidth); sizeGroup->addAction(ui->actionShrinkHeight); sizeGroup->addAction(ui->actionGrowHeight); sizeGroup->addAction(ui->actionPageHeight); sizeGroup->addAction(ui->actionShrinkBoth); sizeGroup->addAction(ui->actionGrowBoth); sizeGroup->addAction(ui->actionPageBoth); ui->actionShrinkWidth->setData(Form::ShrinkWidth); ui->actionGrowWidth->setData(Form::GrowWidth); ui->actionPageWidth->setData(Form::PageWidth); ui->actionShrinkHeight->setData(Form::ShrinkHeight); ui->actionGrowHeight->setData(Form::GrowHeight); ui->actionPageHeight->setData(Form::PageHeight); ui->actionShrinkBoth->setData(Form::ShrinkBoth); ui->actionGrowBoth->setData(Form::GrowBoth); ui->actionPageBoth->setData(Form::PageBoth); connect(sizeGroup, SIGNAL(triggered(QAction*)), this, SLOT(size(QAction*))); connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(newForm())); connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openForm())); connect(ui->actionReload, SIGNAL(triggered()), this, SLOT(reload())); connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveForm())); connect(ui->actionSaveAs, SIGNAL(triggered()), this, SLOT(saveFormAs())); connect(ui->actionSaveAsPDF, SIGNAL(triggered()), this, SLOT(saveFormAsPdf())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); connect(ui->actionOpenPrintData, SIGNAL(triggered()), this, SLOT(openPrintData())); connect(ui->actionPageSetup, SIGNAL(triggered()), form, SLOT(pageSetup())); connect(ui->actionPagePreview, SIGNAL(triggered()), this, SLOT(preview())); connect(ui->actionSend, SIGNAL(triggered()), this, SLOT(email())); connect(ui->actionPrint, SIGNAL(triggered()), this, SLOT(print())); connect(ui->actionFullScreen, SIGNAL(triggered()), this, SLOT(fullScreen())); connect(ui->actionMargins, SIGNAL(toggled(bool)), form, SLOT(showMargins(bool))); connect(ui->actionGrid, SIGNAL(toggled(bool)), form, SLOT(showGrid(bool))); connect(ui->actionPrintData, SIGNAL(toggled(bool)), form, SLOT(showData(bool))); connect(ui->actionSelectAll, SIGNAL(triggered()), form, SLOT(selectAll())); connect(ui->actionDelete, SIGNAL(triggered()), form, SLOT(deleteSelected())); connect(ui->actionProperties, SIGNAL(toggled(bool)), ui->propertyWidget, SLOT(setVisible(bool))); connect(ui->actionMoveForwards, SIGNAL(triggered()), form, SLOT(moveForwards())); connect(ui->actionMoveBackwards, SIGNAL(triggered()), form, SLOT(moveBackwards())); connect(ui->actionAlignLeft, SIGNAL(triggered()), form, SLOT(alignLeft())); connect(ui->actionAlignRight, SIGNAL(triggered()), form, SLOT(alignRight())); connect(ui->actionAlignTop, SIGNAL(triggered()), form, SLOT(alignTop())); connect(ui->actionAlignBottom, SIGNAL(triggered()), form, SLOT(alignBottom())); connect(ui->actionCut, SIGNAL(triggered()), form, SLOT(cut())); connect(ui->actionCopy, SIGNAL(triggered()), form, SLOT(copy())); connect(ui->actionPaste, SIGNAL(triggered()), this, SLOT(paste())); connect(ui->actionFirstPage, SIGNAL(triggered()), this, SLOT(firstPage())); connect(ui->actionPreviousPage, SIGNAL(triggered()), this, SLOT(previousPage())); connect(ui->actionNextPage, SIGNAL(triggered()), this, SLOT(nextPage())); connect(ui->actionLastPage, SIGNAL(triggered()), this, SLOT(lastPage())); connect(ui->menuView, SIGNAL(aboutToShow()), this, SLOT(updateViewMenu())); connect(form, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); connect(form, SIGNAL(changed()), this, SLOT(formChanged())); connect(view, SIGNAL(doneRubberBanding(QRectF)), this, SLOT(doneRubberBanding(QRectF))); connectForm(); loadSettings(); QTimer::singleShot(0, this, SLOT(init())); }