void main() { int i; double dProb; while(1) { cin.getline(cMachine,89); if(cMachine[0]=='#') break; dProb=0; for(i=0; cMachine[i]!='\0'; i++) { if(cMachine[i]=='.') dProb+=100; else if(cMachine[i]=='/') dProb+=RollLeft(i); else if(cMachine[i]=='\\') dProb+=RollRight(i); else if(cMachine[i]=='|') dProb+=0.5*(RollLeft(i)+RollRight(i)); } cout<<(int)(dProb/i)<<endl; } }
// Autonomous drone control void AutoAdjustPosition(int key) { // Only auto-correct if user is not controlling drone and not in absolute control mode if (key < 0 && !absoluteControl) { // Switch variable int patternSwitch = 0; //// Check if there is no pattern visible, but there was one store previously //if (visiblePattern == 0 && lastVisiblePattern != 0) { // // If so, execute action of last pattern // patternSwitch = lastVisiblePattern; //// Else, execute current action //} else patternSwitch = visiblePattern; patternSwitch = visiblePattern; switch (patternSwitch) { case 4: PitchBackwards(false); RollRight(false); break; case 5: PitchBackwards(false); break; case 6: PitchBackwards(false); RollLeft(false); break; case 7: RollLeft(false); break; case 8: PitchForwards(false); RollLeft(false); break; case 9: PitchForwards(false); break; case 10: PitchForwards(false); RollRight(false); break; case 11: RollRight(false); break; case 1: case 2: case 3: Hover(); break; } //cout << "last visible " << lastVisiblePattern << endl; } }
void KeyControls(int key) { // Quit if ESC key if (key == 0x1b) quitProgram = true; // Start/Stop the game // p key if (key == 'p') { if (gameOn) gameOn = false; else { gameOn = true; // reset points points = 0; // reset timer gameTimeStart = cvGetTickCount(); // reset crate/people pickup cratePicked = false; peoplePicked = false; } } // Change camera - C key static int mode = 0; if (key == 'c') ardrone.setCamera(++mode % 4); // Take off / Landing - SPACE key if (key == ' ') { ardrone.setFlatTrim(); if (ardrone.onGround()) ardrone.takeoff(); else ardrone.landing(); } // Emergency stop // x key if (key == 'x') ardrone.emergency(); // Start hovering // h key if (key == 'h') Hover(); // Movement // r key // Gain altitude if (key == 'r') if (!IsTooHigh()) GainAltitude(); // Down arrow // f key // Loose altitude if (key == 'f') if (!IsTooLow()) LooseAltitude(); // q key // Yaw c-clockwise if (key == 'q') YawCClockwise(); // e key // Yaw clockwise if (key == 'e') YawClockwise(); // Game controls - need to be within bounds to opperate // Left arrow / a key // Roll left if (key == 0x250000 || key == 'a') if (IsWithinLeftBounds()) RollLeft(true); else RollRight(false); // Right arrow / d key // Roll right if (key == 0x270000 || key == 'd') if (IsWithinRightBounds()) RollRight(true); else RollLeft(false); // Up arrow // w key // Pitch forwards if (key == 0x260000 || key == 'w') if (IsWithinUpperBounds()) PitchForwards(true); // Down arrow / s key // Pitch backwards if (key == 0x280000 || key == 's') if (IsWithinLowerBounds()) PitchBackwards(true); // Toggle absolute control // o key if (key == 'o') { if (absoluteControl) absoluteControl = false; else absoluteControl = true; } }