int main( const int argc, const char *argv[] ) { fileleague_s *leagueFile; fileleague_s before; char home[20]; char road[20]; int i; srand( time( NULL ) ); if ( argc < 3 ) { printf( "Usage: %s <input file> <output file>\n", argv[0] ); return EXIT_SUCCESS; } if ( (leagueFile = readLeagueFile( argv[1] )) == NULL ) { printf( "Cannot load league file." ); return EXIT_FAILURE; } before = *leagueFile; for ( i = 0; i < TOTAL_TEAMS; ++i ) { leagueFile->teams[i].color[0] = colors[i].color1; } for ( i = 0; i < TOTAL_TEAMS; ++i ) { if ( before.teams[i].color[0] != leagueFile->teams[i].color[0] ) { printf( "%s changed from %s to %s uniforms.\n", leagueFile->teams[i].name, getColorName( before.teams[i].color[0] ), getColorName( leagueFile->teams[i].color[0] ) ); } } if ( ! writeLeagueFile( argv[2], leagueFile ) ) { printf( "Cannot save league changes.\n" ); free( leagueFile ); return EXIT_FAILURE; } free( leagueFile ); return EXIT_SUCCESS; }
void FilesManager::createDecksReport() { readFromFile("decks.dat"); std::ofstream fileStream; fileStream.open("report.txt", std::ios::out | std::ios::app); if(fileStream) { Colors colors[] = { Red, Black, Blue, White, Green }; int decksSize = getDecksNumber(); for(int i = 0; i < COLORS_COUNT; i++) { fileStream << getColorName(matchColorByInteger(i)) << std::endl; for(int j = 0; j < decksSize; j++) { if(decks[j].getColor() == colors[i]) { fileStream << "Owner: " << getPlayerNameById(decks[j].getDeckOwnerId()) << " "; fileStream << "Card: " << decks[j].getCards()[0].getCardName() << " "; fileStream << "Color: " << decks[j].getCards()[0].getColor() << std::endl; } } } Card mostCommonCard = getMostCommonCardIdInAllDecks(); fileStream << "Most common card: " << mostCommonCard.getCardName() << " "; fileStream << "Color:" << mostCommonCard.getColor() << std::endl; } else { fileStream.clear(); fileStream.close(); throw serializable_exception; } }
int searchSpot() { //menelusuri garis hitam sampai menemukan "color" int hue,colortemp; int threshold = 65; resetGyro(gyroSensor); moveMotorTarget(leftMotor,200,100); moveMotorTarget(rightMotor,200,100); while(getMotorMoving(leftMotor)||getMotorMoving(rightMotor)) sleep(1); while(1) { // sensor sees light: if(getColorReflected(colorSensor) < threshold) { // counter-steer right: motor[leftMotor] = 55; motor[rightMotor] = 15; } else {// sensor sees dark: // counter-steer left: motor[leftMotor] = 15; motor[rightMotor] = 55; } hue=getColorHue(colorSensor); //if(hue==99 || hue==253) { if(getColorName(colorSensor)==green) { colortemp=hue==85?green:red; break; } } return colortemp; }
task checkColor(){ TLegoColors tempColor = getColorName(colorSensor); while(true){ if(tempColor != currentColor){ currentColor = tempColor; } wait1Msec(10); } }
task main() { if (getColorName(colorSensor) == colorBlue){ forward(300,milliseconds,10); // sudah berada di start backward(300,milliseconds,10); // Cari jalan SolveDFS(); } else { // Belum berada di start Start(); SolveDFS(); } eraseDisplay(); if (found_end == 1) { displayTextLine(2, "Solusi ditemukan"); displayTextLine(3, "DONE"); } else { displayTextLine(2, "Solusi tidak ditemukan"); } }
void FilteredColor::ensureFiltered() { #ifndef WASABI_COMPILE_SKIN need_filter = 0; filteredcolor = color; #else // fetch iterator pointer if necessary if (skin_iterator == NULL) { skin_iterator = WASABI_API_SKIN->skin_getIterator(); ASSERT(skin_iterator != NULL); } // see if we're current if (*skin_iterator != latest_iteration) { need_filter = 1; // pointer now invalid, must re-get latest_iteration = *skin_iterator; // and then we'll be current } if (need_filter) { filteredcolor = WASABI_API_SKIN->filterSkinColor(color, getColorName(), group); need_filter = 0; } #endif }
int main(int argc, char *argv[]) { Port Connection; Field field; RobotVision vision; vision.init(); vision.set(); return 0; // while(true) { // vision.update(field, true); // } //vision.preprocess(field); bool end = false; while (!end) { bool pause = false; while (!pause && !end) { int degreeAtTarget; vector<geometry::Vector> region1, region2, region3, destPoints; region1.push_back(geometry::Vector(50,200)); region1.push_back(geometry::Vector(50,150)); region1.push_back(geometry::Vector(0,150)); region1.push_back(geometry::Vector(0,200)); vision.showPoints(region1); field.regions.push_back(Region(region1)); destPoints.clear(); destPoints.push_back(geometry::Vector(25,175)); vision.showPoints(destPoints); field.regions[0].ID = 0; field.regions[0].addDestPoints(destPoints); region2.push_back(geometry::Vector(190,70)); region2.push_back(geometry::Vector(300,70)); region2.push_back(geometry::Vector(190,0)); region2.push_back(geometry::Vector(300,0)); vision.showPoints(region2); field.regions.push_back(Region(region2)); destPoints.clear(); destPoints.push_back(geometry::Vector(230,35)); destPoints.push_back(geometry::Vector(270,35)); vision.showPoints(destPoints); field.regions[1].ID = 1; field.regions[1].addDestPoints(destPoints); region3.push_back(geometry::Vector(300,350)); region3.push_back(geometry::Vector(360,350)); region3.push_back(geometry::Vector(300,400)); region3.push_back(geometry::Vector(360,400)); vision.showPoints(region3); field.regions.push_back(Region(region3)); destPoints.clear(); destPoints.push_back(geometry::Vector(330,375)); vision.showPoints(destPoints); field.regions[2].ID = 2; field.regions[2].addDestPoints(destPoints); field.agent.updated = false; while (!field.agent.updated) vision.update(field,true); cout << "obstacles size: " << field.obstacles.size() << endl; field.agent.coords.clear(); field.agent.coords.push_back(field.agent.COM+geometry::Vector(25,25)); field.agent.coords.push_back(field.agent.COM+geometry::Vector(25,-25)); field.agent.coords.push_back(field.agent.COM+geometry::Vector(-25,-25)); field.agent.coords.push_back(field.agent.COM+geometry::Vector(-25,25)); for(int i = 0; i < field.obstacles.size(); i++){ cout << "obj#" << i << " (" << getColorName(field.obstacles[i].color) << "): " << field.obstacles[i].COM << endl; if (field.obstacles[i].color == yellow) field.obstacles[i].regionID = 1; else if (field.obstacles[i].color == green) field.obstacles[i].regionID = 1; else if (field.obstacles[i].color == red) field.obstacles[i].regionID = 0; else field.obstacles[i].regionID = 2; } // cin.ignore(); pair<geometry::Vector,geometry::Vector> goalDest; // first:target, second:dest params::Color targetColor; std::vector<geometry::Vector> path; bool done = false; if (field.obstacles.size() == 0) { cout << "No obstacle found --> PAUSE mode" << endl; pause = true; continue; } else { cerr << "----after visionUpdate" << endl; goalDest = field.bestTarget(targetColor, done); if (done) { cout << "end" << endl; goalDest.first = field.regions[2].destPoints[0].first; } else cout << "target and dest: " << goalDest.first << " -> " << goalDest.second << " :color " << params::getColorName(targetColor) << endl; // cin.ignore(); // if there is no more objects, break, end = true // set degreeAtTarget // pathfind to target try { field.agent.print(); path = ShortestPath(field.agent.COM, goalDest.first, field, argc, argv); // path.push_back(field.agent.COM); // path.push_back(field.agent.COM + geometry::Vector(-200,100)); // path.push_back(field.agent.COM + geometry::Vector(-200,0)); // path.push_back(field.agent.COM); // path.push_back(field.agent.COM + geometry::Vector(-100,100)); // path.push_back(field.agent.COM + geometry::Vector(-200,100)); // path.push_back(field.agent.COM + geometry::Vector(-300,0)); // path.push_back(field.agent.COM + geometry::Vector(-200,-100)); // path.push_back(field.agent.COM + geometry::Vector(-100,-100)); // path.push_back(field.agent.COM); // path.push_back(field.agent.COM + geometry::Vector(-300,0)); // path.push_back(field.agent.COM + geometry::Vector(-300,-200)); // path.push_back(field.agent.COM + geometry::Vector(-300,0)); // path.push_back(field.agent.COM + geometry::Vector(-200,0)); // path.push_back(field.agent.COM + geometry::Vector(-200,-200)); // path.push_back(field.agent.COM + geometry::Vector(-200,0)); // path.push_back(field.agent.COM + geometry::Vector(-100,0)); // path.push_back(field.agent.COM + geometry::Vector(-100,-200)); // path.push_back(field.agent.COM + geometry::Vector(-100,0)); // path.push_back(field.agent.COM + geometry::Vector(0,-0)); // path.push_back(field.agent.COM + geometry::Vector(0,-200)); // path.push_back(field.agent.COM); // path.push_back(geometry::Vector(202,291)); vision.showPoints(path); cout << "PATH: "; for (geometry::Vector pt : path) { cout << " " << pt; } cout << endl; } catch (exceptions::NoPath) { // if there is no path then what??? cout << "No Path found --> PAUSE mode" << endl; pause = true; continue; } cerr << "----end of bestTarget" << endl; } int x = 100; int index = path.size()-1; vector<int> pathSpeeds; bool rotating = false; preprocessPath(path, pathSpeeds); while (!pause && Connection.move(path, pathSpeeds ,field.agent, index, rotating)) { // && not reached target field.agent.updated = false; while (!field.agent.updated) vision.update(field,false); // if shasing then break // wall check } cout << "----REACHED----" << endl; Connection.fullStop(); if (done) { cout << "-----END------" << endl; end = true; break; } // cin.ignore(); // degreeAtTarget = (goalDest.second - goalDest.first).angle(); rotating = false; bool lost = false; bool pushing = false; preprocessPath(path, pathSpeeds); while (!pause && Connection.safeMove(goalDest.second, field.agent, rotating) && !lost) { // && not reached target field.agent.updated = false; while (!field.agent.updated) vision.update(field,true); for(int i = 0; i < field.obstacles.size(); i++) { if (field.obstacles[i].color == targetColor) { if (pushing && (field.obstacles[i].COM - field.agent.COM).size() >= params::LOST_LIMIT){ cout << "--------OBSTACLE LOST :(-----------" << params::getColorName(targetColor) << endl; cout << (field.obstacles[i].COM - field.agent.COM).size() << endl; lost = true; break; } else if ((field.obstacles[i].COM - field.agent.COM).size() < params::LOST_LIMIT - 20) { // Connection.fullStop(); cout << "----PUSHING-----" << endl; // cin.ignore(); pushing = true; } } } // if shasing then break // wall check } Connection.fullStop(); if (!lost) { cout << "-----DONE------" << endl; // cin.ignore(); } } while (pause && !end) { int input = 0; while (input != 1) { cout << "ENTER 1 to continue: "; cin >> input; } pause = false; // full stop // input for continue // while pause } } // float var = 25.64; // for(int i=0 ; i<30 ; i++){ // Connection.talkToSetare(0,0,0); // usleep(12*var*1000); // Connection.fullStop(); // usleep(400*1000); // } // while(field.agent.direction < 70 ){ // Connection.talkToSetare(0,0,0); // cout << "---- degree is :" << field.agent.direction << endl; // vision.update(field); // } // Connection.fullStop(); // Connection.talkToSetare(70,0,5); // usleep(var*10*1000); cin.ignore(); // close port // delete return 0; }
//------------------------------------------------------------------------------ // drawFunc -- draw this text field //------------------------------------------------------------------------------ void Field::drawFunc() { // Get a pointer to the current display BasicGL::Display* dsp = getDisplay(); if (dsp == 0) return; // --- // When our container is also a Field, get a pointer to it. // --- BasicGL::Field* parent = 0; if (container() != 0) { BasicGL::Field* fp = dynamic_cast<BasicGL::Field*>(container()); if (fp != 0) parent = fp; } // --- // If we don't have a position, try to get one from our container // --- int ll = line(); int cc = column(); if (ll == 0 && parent != 0) { ll = parent->line(); cc = parent->column(); } // --- // Select the correct font based on font name if there is one, and if not, then do it normally // --- if (fontName != 0) dsp->selectFont(isReversed(), isUnderlined(), dsp->getFont(fontName->getString())); else dsp->selectFont(isReversed(), isUnderlined()); // --- // Set the color // --- bool restoreColor = false; osg::Vec4 ocolor = dsp->getCurrentColor(); // only use default colors if we aren't inheriting our container's colors if (!isInheritColor()) { if (getColorName() == 0 && getColor() == 0) { const Basic::Color* cc = 0; if (isHighLighted()) cc = dsp->getHighlightColor(); else cc = dsp->getNormColor(); if (cc != 0) { const osg::Vec4* p = cc->getRGBA(); dsp->setColor(*p); restoreColor = true; } } } // --- // draw the string // --- if (str.len() > 0) { // Draw the text string const char* sp = str; if (ll > 0 && cc > 0) dsp->outputTextLC(ll, cc, sp, int(width()), isVertical()); else dsp->outputText(sp, int(width()), isVertical()); } // --- // draw the brackets // --- if (areBracketsOn() && ll > 0 && cc > 0) { if (isVertical()) { // Position for vertical text dsp->drawLeftBracket(ll-1, cc); dsp->drawRightBracket(ll+int(width()), cc); } else { // Position for normal text dsp->drawLeftBracket(ll, cc-1); dsp->drawRightBracket(ll, cc+int(width())); } } // --- // If we used default colors, restore the old value // --- if (restoreColor) dsp->setColor(ocolor); }
pair<geometry::Vector,geometry::Vector> Field::bestTarget(params::Color& targetColor, bool& done){ // vector<target,dist> vector<pair<geometry::Vector, geometry::Vector>> targetDests; vector<params::Color> targetColors; vector<int> cost; // cerr << "----in bestTarget 1" << endl; // cerr << "-------- obstacles.size " << obstacles.size() << endl; // find target and dists for (int i = 0; i < obstacles.size(); i++) { int regionIndex = 0; for(int j = 0; j < regions.size(); j++) { if (regions[j].ID == obstacles[i].regionID) { regionIndex = j; break; } } // cerr << "----in bestTarget 2 :regionIndex = " << regionIndex << " color: " << getColorName(obstacles[i].color) << endl; bool inside = true; for (int j = 0; j < obstacles[i].coords.size(); j++) if (!regions[regionIndex].isInside(obstacles[i].coords[j])) { inside = false; break; } if (inside) { cout << "--" << getColorName(obstacles[i].color) << " is inside." << endl; continue; } for (int j = 0; j < regions[regionIndex].destPoints.size(); j++) { cerr << regions[regionIndex].destPoints[j].first << endl; pair<geometry::Vector, bool> dPt = regions[regionIndex].destPoints[j]; if (dPt.second == true) { targetDests.push_back(make_pair((obstacles[i].COM - dPt.first)/(1/1.6)+dPt.first, dPt.first)); targetColors.push_back(obstacles[i].color); cost.push_back(j*100); } } // cerr << "----in bestTarget 3" << endl; } // cerr << "----in bestTarget 4 :targetDests.size() = " << targetDests.size() << endl; // calculate obj intersections with lines for (int i = 0; i < obstacles.size(); i++) { for (int j = 0; j < targetDests.size(); j++) { if (obstacles[i].distWithCOM(targetDests[j].first, targetDests[j].second) <= obstacles[i].radious) cost[j] += 1000; cost[j] += (agent.COM - targetDests[j].first).size(); if (obstacles[i].distWithCOM(targetDests[j].first, agent.COM) <= obstacles[i].radious) cost[j] += 100; } } int minIndex = 0; for(int i = 0; i < targetDests.size(); i++) { if (cost[minIndex] <= cost[i]) minIndex = i; } // cerr << "----in bestTarget 5" << endl; if (targetColors.size() == 0) { done = true; return make_pair(geometry::Vector(0,0), geometry::Vector(0,0)); } targetColor = targetColors[minIndex]; return targetDests[minIndex]; }
/*! * \brief Get a string for displaying the card's identity * \return QString */ QString Card::getLabel() { return getValueName() + " of " + getColorName(); }
task main() { //Declare variables int targetImage[8][8] = {{1, 1, 1, 0, 0, 1, 1, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1}, {1, 1, 1, 0, 0, 1, 1, 1}}; int hitImage[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 1, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 0}, {0, 0, 1, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}}; int splashImage[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 1, 1, 1, 0, 0}, {0, 1, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 1, 0}, {0, 0, 1, 1, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}}; int mainGrid[8][8] = {{0, 1, 1, 1, 1, 1, 0, 0}, //[0][0-8] {0, 0, 0, 0, 0, 0, 0, 0}, //[1][0-7] {0, 1, 0, 0, 0, 0, 0, 0}, //[2][0-7] {0, 1, 0, 0, 0, 1, 1, 1}, //[3][0-7] {1, 0, 0, 0, 0, 0, 0, 0}, //[4][0-7] {1, 0, 0, 0, 0, 0, 0, 0}, //[5][0-7] {1, 0, 1, 1, 1, 0, 0, 0}, //[6][0-7] {1, 0, 0, 0, 0, 0, 0, 0}}; //[7][0-7] int colourValue; int x=10; int y=10; int xMove=0; int yMove=0; int xShip=0; int yShip=7-yMove; int hits=0; //Setup colour sensor SensorType[S3] = sensorEV3_Color;//set TYPE SensorMode[S3] = modeEV3Color_Color;//set MODE while(hits<17) /* ************************************************************* Red - 5 - SHOOT Blue - 2 - LEFT Yellow - 4 - RIGHT Green - 3 - DOWN ************************************************************* */ { //Erase target image clearTarget(targetImage,x,y); sleep(500); //Check colour colourValue=getColorName(S3); sleep(50); if (colourValue==2) { if(xMove>0) { xMove--; } else if(xMove==0) { xMove=7; } } if (colourValue==4) { if(xMove<7) { xMove++; } else if(xMove==7) { xMove=0; } } if (colourValue==3) { if(yMove>0) { yMove--; } else if(yMove==0) { yMove=7; } } x=xMove*8+10; y=yMove*8+10; if (colourValue==5) { //Calculate Main Grid Location xShip=xMove; yShip=7-yMove; //Play torpedo drop sound torpedoSound(); if (mainGrid[yShip][xShip]==1) { //Play hit sound kabloom(); //Draw hit image kabloomDraw(hitImage,x,y); //Increment hits hits++; //Remove ship mainGrid[yShip][xShip]=0; } else { //Play splash sound sploosh(); //Draw splash image splooshDraw(splashImage,x,y); } } //Draw target image drawTarget(targetImage,x,y); //Sleep for a small amount of time sleep(500); } displayBigTextLine(2, "Winner!"); sleep(5000); }