void CannonField::moveShot() { QRegion region = shotRect(); ++timerCount; QRect shotR = shotRect(); if (shotR.intersects(targetRect())) { autoShootTimer->stop(); emit hit(); emit canShoot(true); } else if (shotR.x() > width() || shotR.y() > height() || shotR.intersects(barrierRect())) { autoShootTimer->stop(); emit missed(); emit canShoot(true); } else { region = region.unite(shotR); } update(region); }
void DTKInterpolationAdapter::update_variable_values(std::string var_name, Teuchos::ArrayView<GlobalOrdinal> missed_points) { MPI_Comm old_comm = Moose::swapLibMeshComm(*comm->getRawMpiComm()); System * sys = find_sys(var_name); unsigned int var_num = sys->variable_number(var_name); bool is_nodal = sys->variable_type(var_num).family == LAGRANGE; Teuchos::RCP<FieldContainerType> values = values_to_fill[var_name]->field(); // Create a vector containing true or false for each point saying whether it was missed or not // We're only going to update values for points that were not missed std::vector<bool> missed(values->size(), false); for (Teuchos::ArrayView<const GlobalOrdinal>::const_iterator i=missed_points.begin(); i != missed_points.end(); ++i) missed[*i] = true; unsigned int i=0; // Loop over the values (one for each node) and assign the value of this variable at each node for (FieldContainerType::iterator it=values->begin(); it != values->end(); ++it) { // If this point "missed" then skip it if (missed[i]) { i++; continue; } const DofObject * dof_object = NULL; if (is_nodal) dof_object = mesh.node_ptr(vertices[i]); else dof_object = mesh.elem(elements[i]); if (dof_object->processor_id() == mesh.processor_id()) { // The 0 is for the component... this only works for LAGRANGE! dof_id_type dof = dof_object->dof_number(sys->number(), var_num, 0); sys->solution->set(dof, *it); } i++; } sys->solution->close(); // Swap back Moose::swapLibMeshComm(old_comm); }
bool GameBoard::qt_invoke( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->slotOffset() ) { case 0: fire(); break; case 1: hit(); break; case 2: missed(); break; case 3: newGame(); break; default: return QWidget::qt_invoke( _id, _o ); } return TRUE; }
bool CannonField::qt_emit( int _id, QUObject* _o ) { switch ( _id - staticMetaObject()->signalOffset() ) { case 0: hit(); break; case 1: missed(); break; case 2: angleChanged((int)static_QUType_int.get(_o+1)); break; case 3: forceChanged((int)static_QUType_int.get(_o+1)); break; default: return QWidget::qt_emit(_id,_o); } return TRUE; }
int main(void) { int n; int code = scanf("%d", &n); if (code != 1) return ERR_INPUT; int a[n]; int i; for (i = 0; i < n; ++i) { code = scanf("%d", &a[i]); if ((code != 1) || (a[i] > n)) return ERR_INPUT; } printf("%d\n", missed(a, n)); return 0; }
void CannonField::moveShot() { QRegion r( shotRect() ); timerCount++; QRect shotR = shotRect(); if ( shotR.intersects( targetRect() ) ) { autoShootTimer->stop(); emit hit(); emit canShoot( TRUE ); } else if ( shotR.x() > width() || shotR.y() > height() ) { autoShootTimer->stop(); emit missed(); emit canShoot( TRUE ); } else { r = r.unite( QRegion( shotR ) ); } repaint( r ); }
void CannonField::moveShot() { QRegion r( shotRect() ); timerCount++; QRect shotR = shotRect(); if (mode==cheat_mode && timerCount>20) // when the mode equal cheat_mode , then we determine the timerCount bigger than 10 { autoShootTimer->stop(); } else if ( shotR.intersects( targetRect() ) ) { autoShootTimer->stop(); emit hit(); } else if ( shotR.x() > width() || shotR.y() > height() ) { autoShootTimer->stop(); emit missed(); } else { r = r.unite( QRegion( shotR ) ); } repaint( r ); }
GameBoard::GameBoard( QWidget *parent, const char *name ) : QWidget( parent, name ) { setMinimumSize( 500, 355 ); quit = new QPushButton( "Quit", this, "quit" ); quit->setFont( QFont( "Times", 18, QFont::Bold ) ); connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) ); angle = new LCDRange( "ANGLE", this, "angle" ); angle->setRange( 5, 70 ); force = new LCDRange( "FORCE", this, "force" ); force->setRange( 10, 50 ); frame = new QFrame( this, "cannonFrame" ); frame->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); cannonField = new CannonField( this, "cannonField" ); cannonField->setBackgroundColor( QColor( 250, 250, 200) ); connect( angle,SIGNAL(valueChanged(int)), cannonField,SLOT(setAngle(int))); connect( cannonField,SIGNAL(angleChanged(int)), angle,SLOT(setValue(int))); connect( force,SIGNAL(valueChanged(int)), cannonField,SLOT(setForce(int))); connect( cannonField,SIGNAL(forceChanged(int)), force,SLOT(setValue(int))); connect( cannonField, SIGNAL(hit()),SLOT(hit()) ); connect( cannonField, SIGNAL(missed()),SLOT(missed()) ); angle->setValue( 60 ); force->setValue( 25 ); shoot = new QPushButton( "Shoot", this, "shoot" ); shoot->setFont( QFont( "Times", 18, QFont::Bold ) ); connect( shoot, SIGNAL(clicked()), SLOT(fire()) ); restart = new QPushButton( "New Game", this, "newgame" ); restart->setFont( QFont( "Times", 18, QFont::Bold ) ); connect( restart, SIGNAL(clicked()), SLOT(newGame()) ); hits = new QLCDNumber( 2, this, "hits" ); shotsLeft = new QLCDNumber( 2, this, "shotsleft" ); QLabel *hitsL = new QLabel( "HITS", this, "hitsLabel" ); QLabel *shotsLeftL = new QLabel( "SHOTS LEFT", this, "shotsleftLabel" ); QAccel *accel = new QAccel( this ); accel->connectItem( accel->insertItem( Key_Space), this, SLOT(fire()) ); accel->connectItem( accel->insertItem( Key_Q), qApp, SLOT(quit()) ); quit->setGeometry( 10, 10, 75, 30 ); angle->setGeometry( 10, quit->y() + quit->height() + 10, 75, 130 ); force->setGeometry( 10, angle->y() + angle->height() + 10, 75, 130 ); frame->move( angle->x() + angle->width() + 10, angle->y() ); cannonField->move( frame->x() + 2, frame->y() + 2 ); shoot->setGeometry( 10, 315, 75, 30 ); restart->setGeometry( 380, 10, 110, 30 ); hits->setGeometry( 130, 10, 40, 30 ); hitsL->setGeometry( hits->x() + hits->width() + 5, 10, 60, 30 ); shotsLeft->setGeometry( 240, 10, 40, 30 ); shotsLeftL->setGeometry( shotsLeft->x()+shotsLeft->width()+5, 10, 70, 30 ); newGame(); }
void GeneticAlgorithm::Filter(char ***individual) { // Step 0 std::vector<std::vector<std::pair<int, std::vector<int>>>> over; std::vector<std::vector<int>> miss; for(int day = 0; day < days; ++day) { for(int hour = 0; hour < hours_per_day; ++hour) { int h = day * hours_per_day + hour; std::vector<std::pair<int, std::vector<int>>> h_over; std::vector<int> h_miss; std::vector<bool> missed(classes_count, true); for(int teacher = 0; teacher < teachers_count; ++teacher) { auto it = std::find(classes.begin(), classes.end(), individual[teacher][day][hour]); if(it == classes.end()) continue; int iti = it - classes.begin(); if(missed[iti] == true) { std::vector<int> vv; std::pair<int, std::vector<int>> over_class(iti, vv); h_over.push_back(over_class); missed[iti] = false; } auto oclass = std::find_if(h_over.begin(), h_over.end(), [&iti] (std::pair<int, std::vector<int>> x) -> bool { return x.first == iti; }); oclass->second.push_back(teacher); } for(int i = 0; i < classes_count; ++i) { if(missed[i]) h_miss.push_back(i); } std::remove_if(h_over.begin(), h_over.end(), [] (std::pair<int, std::vector<int>> x) -> bool { return x.second.size() == 1; }); miss.push_back(h_miss); over.push_back(h_over); } } // Step 1 while(true) { bool _continue = false; for(int h = 0; h < days * hours_per_day; ++h) { for(int k = 0; k < days * hours_per_day; ++k) { if(k != h) { for(int i = 0; i < miss[h].size(); ++i) { auto cj = std::find_if(over[k].begin(), over[k].end(), [&miss, &h, &i] (std::pair<int, std::vector<int>> x) -> bool { return x.first == miss[h][i]; }); if(cj != over[k].end()) { for(int j = 0; j < miss[k].size(); ++j) { if(miss[k][j] != miss[h][i]) { auto ci = std::find_if(over[h].begin(), over[h].end(), [&miss, &k, &j] (std::pair<int, std::vector<int>> x) -> bool { return x.first == miss[k][j]; }); if(ci != over[h].end()) { for(int cir = 0; cir < ci->second.size(); ++cir) { for(int cjr = 0; cjr < cj->second.size(); ++cjr) { if(ci->second[cir] == cj->second[cjr]) { int teacher = ci->second[cir]; _continue = true; char tmp = individual[teacher][h / hours_per_day][h % hours_per_day]; individual[teacher][h / hours_per_day][h % hours_per_day] = individual[teacher][k / hours_per_day][k % hours_per_day]; individual[teacher][k / hours_per_day][k % hours_per_day] = tmp; std::remove(miss[h].begin(), miss[h].end(), miss[h][i]); std::remove(miss[k].begin(), miss[k].end(), miss[k][j]); ci->second.erase(ci->second.begin() + cir); cj->second.erase(cj->second.begin() + cjr); std::remove_if(over[h].begin(), over[h].end(), [] (std::pair<int, std::vector<int>> x) -> bool { return x.second.size() == 1; }); std::remove_if(over[k].begin(), over[k].end(), [] (std::pair<int, std::vector<int>> x) -> bool { return x.second.size() == 1; }); goto eend1; } } } } } } } } } } } eend1: if(!_continue) break; } // Step 2 /*while(true) { bool _continue = false; for(int h = 0; h < days * hours_per_day; ++h) { for(int k = 0; k < days * hours_per_day; ++k) { if(k != h) { for(int i = 0; i < miss[k].size(); ++i) { auto ci = std::find_if(over[h].begin(), over[h].end(), [&miss, &k, &i] (std::pair<int, std::vector<int>> x) -> bool { return x.first == miss[k][i]; }); if(ci != over[h].end()) { for(int cir = 0; cir < ci->second.size(); ++cir) { if(individual[ci->second[cir]][k / hours_per_day][k % hours_per_day] == free_hour_symbol) { _continue = true; char tmp = individual[ci->second[cir]][k / hours_per_day][k % hours_per_day]; individual[ci->second[cir]][k / hours_per_day][k % hours_per_day] = individual[ci->second[cir]][h / hours_per_day][h % hours_per_day]; individual[ci->second[cir]][h / hours_per_day][h % hours_per_day] = tmp; std::remove(miss[k].begin(), miss[k].end(), miss[k][i]); ci->second.erase(ci->second.begin() + cir); std::remove_if(over[h].begin(), over[h].end(), [] (std::pair<int, std::vector<int>> x) -> bool { return x.second.size() == 1; }); goto eend2; } } } } } } } eend2: if(!_continue) break; }*/ }
GameBoard::GameBoard( QWidget *parent, const char *name ) : QWidget( parent, name ) { QPushButton *quit = new QPushButton( "&Quit", this, "quit" ); quit->setFont( QFont( "Times", 18, QFont::Bold ) ); connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) ); LCDRange *angle = new LCDRange( "ANGLE", this, "angle" ); angle->setRange( 5, 70 ); LCDRange *force = new LCDRange( "FORCE", this, "force" ); force->setRange( 10, 50 ); cannonField = new CannonField( this, "cannonField" ); connect( angle, SIGNAL(valueChanged(int)), cannonField, SLOT(setAngle(int)) ); connect( cannonField, SIGNAL(angleChanged(int)), angle, SLOT(setValue(int)) ); connect( force, SIGNAL(valueChanged(int)), cannonField, SLOT(setForce(int)) ); connect( cannonField, SIGNAL(forceChanged(int)), force, SLOT(setValue(int)) ); connect( cannonField, SIGNAL(hit()), this, SLOT(hit()) ); connect( cannonField, SIGNAL(missed()), this, SLOT(missed()) ); QPushButton *shoot = new QPushButton( "&Shoot", this, "shoot" ); shoot->setFont( QFont( "Times", 18, QFont::Bold ) ); connect( shoot, SIGNAL(clicked()), SLOT(fire()) ); connect( cannonField, SIGNAL(canShoot(bool)), shoot, SLOT(setEnabled(bool)) ); QPushButton *restart = new QPushButton( "&New Game", this, "newgame" ); restart->setFont( QFont( "Times", 18, QFont::Bold ) ); connect( restart, SIGNAL(clicked()), this, SLOT(newGame()) ); hits = new QLCDNumber( 2, this, "hits" ); shotsLeft = new QLCDNumber( 2, this, "shotsleft" ); QLabel *hitsL = new QLabel( "HITS", this, "hitsLabel" ); QLabel *shotsLeftL = new QLabel( "SHOTS LEFT", this, "shotsleftLabel" ); QGridLayout *grid = new QGridLayout( this, 2, 2, 10 ); grid->addWidget( quit, 0, 0 ); grid->addWidget( cannonField, 1, 1 ); grid->setColStretch( 1, 10 ); QVBoxLayout *leftBox = new QVBoxLayout; grid->addLayout( leftBox, 1, 0 ); leftBox->addWidget( angle ); leftBox->addWidget( force ); QHBoxLayout *topBox = new QHBoxLayout; grid->addLayout( topBox, 0, 1 ); topBox->addWidget( shoot ); topBox->addWidget( hits ); topBox->addWidget( hitsL ); topBox->addWidget( shotsLeft ); topBox->addWidget( shotsLeftL ); topBox->addStretch( 1 ); topBox->addWidget( restart ); angle->setValue( 60 ); force->setValue( 25 ); angle->setFocus(); newGame(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); //QPushButton *quit = new QPushButton(("&Quit")); QPushButton *quit = new QPushButton(QObject::tr("Quit")); quit->setFont(QFont("Times", 18, QFont::Bold)); QObject::connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); QGridLayout *gridLayout = new QGridLayout; gridLayout->addWidget(quit, 0,0); // myWidget *previousWidget; // for (int row=1; row<4; ++row){ // for (int col=0; col<3; ++col){ // myWidget *combine = new myWidget(); // gridLayout.addWidget(combine); // // if (!(row ==1 && col ==0)){ // combine->linkPreviousWidget(previousWidget); // } // previousWidget = combine; // } // } myWidget *angle = new myWidget; gridLayout->addWidget(angle, 1, 0, 1, 1); myWidget *force = new myWidget; gridLayout->addWidget(force, 2,0,1,1); CannonField *cannonField = new CannonField; gridLayout->addWidget(cannonField, 1,1, 2, 3); gridLayout->setColumnStretch(1,20); //why we need this? QObject::connect(cannonField, SIGNAL(angleChanged(int)), angle, SLOT(setValue(int))); QObject::connect(cannonField, SIGNAL(forceChanged(int)), force, SLOT(setValue(int))); QObject::connect(angle, SIGNAL(valueChanged(int)), cannonField, SLOT(setAngle(int))); QObject::connect(force, SIGNAL(valueChanged(int)), cannonField, SLOT(setForce(int))); angle->setValue(60); angle->setFocus(); angle->setLabelText("Angle"); force->setValue(15); force->setLabelText("Force"); QPushButton *shoot = new QPushButton(QObject::tr("&Shoot")); shoot->setFont(QFont("Times", 18, QFont::Bold)); QObject::connect(shoot, SIGNAL(clicked()), cannonField, SLOT(shoot())); gridLayout->addWidget(shoot, 3,0); ScoreBoard *scoreBoard = new ScoreBoard; QObject::connect(cannonField, SIGNAL(hit()), scoreBoard, SLOT(countHit())); QObject::connect(cannonField, SIGNAL(missed()), scoreBoard, SLOT(countMiss())); gridLayout->addWidget(scoreBoard, 0, 1, 1, 2); QWidget window; window.setLayout(gridLayout); window.setGeometry(100, 100, 500, 500); window.show(); return app.exec(); }