void consume(const IMC::IridiumMsgRx* msg) { DUNE::IMC::IridiumMessage * m = DUNE::IMC::IridiumMessage::deserialize(msg); if (m == NULL) { war(DTR("error while parsing Iridium message")); return; } switch (m->msg_id) { case (ID_ACTIVATESUB): debug("Received an Iridium subscription request. WTF?"); break; case (ID_DEACTIVATESUB): debug("Received an Iridium subscription end request. WTF?"); break; case (ID_IRIDIUMCMD): handleIridiumCommand(dynamic_cast<IridiumCommand *>(m)); break; case (ID_DEVICEUPDATE): handleDeviceUpdate(dynamic_cast<DeviceUpdate *>(m)); break; default: DUNE::IMC::GenericIridiumMessage * irMsg = dynamic_cast<DUNE::IMC::GenericIridiumMessage *>(m); debug("received IMC message of type %s from Iridium.", irMsg->msg->getName()); dispatch(irMsg->msg); break; } delete m; }
void BasicAutopilot::consume(const IMC::DesiredZ* msg) { if (!isActive()) return; m_vertical_ref = msg->value; if (msg->z_units == IMC::Z_DEPTH) { m_vertical_mode = VERTICAL_MODE_DEPTH; float limit = m_max_depth - c_depth_margin; if (m_vertical_ref > limit) { m_vertical_ref = limit; war(DTR("limiting depth to %.1f"), limit); } } else if (msg->z_units == IMC::Z_ALTITUDE) { m_vertical_mode = VERTICAL_MODE_ALTITUDE; // Avoid possible rough transition when changing from depth to altitude m_bottom_follow_depth = m_estate.depth; } else { m_vertical_mode = VERTICAL_MODE_NONE; } // always clear delta timer after changing mode m_vmode_delta.clear(); }
int main() { int t; char s[100]; scanf("%d", &t); for (int i = 0; i < t; i++) { scanf("%s", &s); printf("Case #%d: %lld\n", i+1, war(s)); } }
void consume(const IMC::SetServoPosition* msg) { if (!m_args.limit_rate) { m_positions[msg->id].value = trimValue(msg->value, -m_args.max_angle, m_args.max_angle); dispatch(m_positions[msg->id]); } else { m_last_time = Clock::get(); m_commands[msg->id].value = trimValue(msg->value, -m_args.max_angle, m_args.max_angle); } if (m_args.generate_faults && !m_faulted) { if (m_fault_timer < 0.0) { m_fault_timer = Clock::get(); } else if (Clock::get() - m_fault_timer > m_args.fault_trigger) { m_servo_in_fault = Math::roundToInteger(m_prng->uniform(0, c_servo_count - 1)); m_faulted = true; war(DTR("fault triggered in servo #%d"), m_servo_in_fault); } } else if (m_args.generate_faults && (m_servo_in_fault >= 0)) { if (Clock::get() - m_fault_timer > c_fault_duration) { war(DTR("servo #%d is no longer in fault"), m_servo_in_fault); m_servo_in_fault = -1; } } }
void CCardGame::hand( void ) { CCard c1 = mPlayer1Cards.getCard(); CCard c2 = mPlayer2Cards.getCard(); mHands++; if( c1 > c2 ){ updateDecks( mPlayer1Cards, c1, c2 ); } else if( c1 == c2 ) { war( c1, c2 ); } else { updateDecks( mPlayer2Cards, c2, c1 ); } }
int main() { char choice[16]; int seed; allocate(0x1000, 1, (void **)&state); if(state == NULL) { put("Could not allocate space for gamestate. Terminating."); _terminate(-1); } state->hugcount = 1000; put("Welcome to the hug gambling server.\n"); put("What is your name?\n"); bzero(state->name, 256); recvUntil(0, state->name, 256, '\n'); put("Hi "); put(state->name); put(". "); memcpy((char *)&seed, state->name, 4); hugsrand(state, seed); while(state->hugcount > 0) { if(state->hugcount > 1000000) state->hugcount = 1000000; put("You have "); put(itoa(state->hugcount)); put(" hugs. Shall we play a game?\n1. Coin Flip\n2. Hangman\n3. Dice game\n4. War\nq. Quit\n"); bzero(choice, 16); recvUntil(0, choice, 15, '\n'); switch(choice[0]) { case '1': coinflip(); break; case '2': hangman(); break; case '3': dicegame(); break; case '4': war(); break; case 'q': put("Thanks for playing! Don't spend all your hugs in one place.\n"); _terminate(0); } } put("You're all out of hugs :(. Thanks for playing.\n"); }
static void game_select(char *name) { printf("\n"); char *game = malloc(strlen(name) + 1); strcpy(game, name); str_tolower(game); /* Ignore case when launching game */ if (strcmp(game, games[0]) == 0) war(); else if (strcmp(game, games[1]) == 0) solitaire(); else printf("Not a valid game.\n"); free(game); }
//! Acquire resources. void onResourceAcquisition(void) { try { m_uart = new SerialPort(m_args.uart_dev, c_baud_rate); m_ctl = new UCTK::Interface(m_uart); UCTK::FirmwareInfo info = m_ctl->getFirmwareInfo(); if (info.isDevelopment()) war(DTR("device is using unstable firmware")); else inf(DTR("firmware version %u.%u.%u"), info.major, info.minor, info.patch); } catch (std::runtime_error& e) { throw RestartNeeded(e.what(), c_restart_delay); } }
//! Change the current plan control state mode //! @param[in] s plan control state to switch to //! @param[in] event_desc description of the event that motivated the change //! @param[in] nid id of the maneuver if any //! @param[in] maneuver pointer to maneuver message //! @param[in] print true if the messages should be printed to output void changeMode(IMC::PlanControlState::StateEnum s, const std::string& event_desc, const std::string& nid, const IMC::Message* maneuver, bool print = true) { double now = Clock::getSinceEpoch(); if (print) war("%s", event_desc.c_str()); m_last_event = event_desc; if (s != m_pcs.state) { debug(DTR("now in %s state"), DTR(c_state_desc[s])); bool was_in_plan = initMode() || execMode(); m_pcs.state = s; bool is_in_plan = initMode() || execMode(); if (was_in_plan && !is_in_plan) { m_plan->planStopped(); changeLog(""); } } if (maneuver) { m_pcs.man_id = nid; m_pcs.man_type = maneuver->getId(); } else { m_pcs.man_id.clear(); m_pcs.man_type = 0xFFFF; } m_pcs.setTimeStamp(now); dispatch(m_pcs, DF_KEEP_TIME); }
void Register::add_user(QString a,QString b) { QFile f("..\\quesion\\user\\user.txt"); if(!f.open(QIODevice::WriteOnly|QIODevice::Append)) { qDebug()<< "no vertification file!"; } QTextStream out(&f); if(user_exist(a)){ warning war("用户名已被注册!"); war.show(); war.exec(); this->close(); } out << a << endl << b << endl; f.close(); warning* war = new warning("注册成功!",this); war->show(); war->exec(); this->close(); }
static int solveQP( const scalar& tol, MatrixXXsc& C, VectorXs& dvec, VectorXs& alpha ) { static_assert( std::is_same<scalar,double>::value, "QL only supports doubles." ); assert( dvec.size() == alpha.size() ); // All constraints are bound constraints. int m = 0; int me = 0; int mmax = 0; // C should be symmetric assert( ( C - C.transpose() ).lpNorm<Eigen::Infinity>() < 1.0e-14 ); // Number of degrees of freedom. assert( C.rows() == C.cols() ); int n{ int( C.rows() ) }; int nmax = n; int mnn = m + n + n; assert( dvec.size() == nmax ); // Impose non-negativity constraints on all variables Eigen::VectorXd xl = Eigen::VectorXd::Zero( nmax ); Eigen::VectorXd xu = Eigen::VectorXd::Constant( nmax, std::numeric_limits<double>::infinity() ); // u will contain the constraint multipliers Eigen::VectorXd u( mnn ); // Status of the solve int ifail = -1; // Use the built-in cholesky decomposition int mode = 1; // Some fortran output stuff int iout = 0; // 1 => print output, 0 => silent int iprint = 1; // Working space assert( m == 0 && me == 0 && mmax == 0 ); int lwar = 3 * ( nmax * nmax ) / 2 + 10 * nmax + 2; Eigen::VectorXd war( lwar ); // Additional working space int liwar = n; Eigen::VectorXi iwar( liwar ); { scalar tol_local = tol; ql_( &m, &me, &mmax, &n, &nmax, &mnn, C.data(), dvec.data(), nullptr, nullptr, xl.data(), xu.data(), alpha.data(), u.data(), &tol_local, &mode, &iout, &ifail, &iprint, war.data(), &lwar, iwar.data(), &liwar ); } return ifail; }
main (int argc, char *argv[]) { char inFile[80]; char ans; int ans2; int done = 0; int play_again_flag = 1; int seed = 1; printf ("argc = %d\n", argc); if (argc >= 3) { printf ("argv[1] = %s, argv[2] = %s\n", argv[1], argv[2]); if (!strcmp(argv[1], "-i")) strcpy (inFile, argv[2]); printf ("inFile = %s\n", inFile); inFile_fp = fopen (inFile, "r"); if (inFile_fp == NULL) printf ("failed to open input file - %s\n", inFile); else printf ("reading commands from input file - %s\n", inFile); if (argc == 4) { printf ("argv[3] = %s\n", argv[1]); seed = atoi(argv[3]); printf ("using specified random seed = %d\n", seed); } else { printf ("using default random seed = %d\n", seed); } } else if (argc == 2) { printf ("argv[1] = %s\n", argv[1]); seed = atoi(argv[1]); printf ("using specified random seed = %d\n", seed); } else if (argc == 1) { seed = (((int) time(0)) % 100000) + 2; printf ("using generated random seed = %d\n", seed); } srand(seed); initialize(); introduction(); printf ("Do you wish to skip the detailed reports "); printf ("at the end of each year"); ans = getYesNo(); szR = ans; printf ("Do you want to play"); ans = getYesNo(); if (ans == 'Y') { printf ("okay - let's give the wheel a spin\n\n"); play_again_flag = 1; } else { printf ("ok - see ya round\n"); play_again_flag = 0; } while (play_again_flag) { start_new_game(); done = 0; while (!done) { last_years_results(); if (end_of_game_check()) { done = 1; continue; } feed_the_peasants(); if (starvation_and_unrest()) { done = 1; continue; } if (purchase_land() == 0) { if (sell_land()) { done = 1; continue; } } if (war_with_the_king()) { done = 1; continue; } grain_production(); update_land_tables(); crop_yield_and_losses(); if (war()) { done = 1; continue; } population_changes(); if (harvest_grain()) { done = 1; continue; } update_unrest(); } play_again_flag = play_again(); } exit(0); }
void BasicAutopilot::consume(const IMC::EstimatedState* msg) { if (!isActive()) return; if (msg->getSource() != getSystemId()) return; m_estate = *msg; // check if vertical control mode is valid if (m_vertical_mode >= VERTICAL_MODE_SIZE) { signalBadVertical(DTR("invalid vertical control mode %d")); return; } else if (m_vertical_mode == VERTICAL_MODE_NONE) { float delta = m_vmode_delta.getDelta(); if (delta > 0.0) m_vmode_wait += delta; if (m_vmode_wait > c_mode_timeout) { m_vmode_wait = 0.0; signalBadVertical(DTR("timed out while waiting for vertical control mode")); } return; } else if (m_vertical_mode == VERTICAL_MODE_ALTITUDE) { // Required depth for bottom following = current depth + required altitude correction // in case the follow depth is lower than 0.0 it will be capped since the btrack // is not possible // check if we have altitude measurements if (msg->alt < 0.0) { setEntityState(IMC::EntityState::ESTA_ERROR, DTR(c_no_alt)); err("%s", DTR(c_no_alt)); return; } m_bottom_follow_depth = m_estate.depth + (msg->alt - m_vertical_ref); if (m_bottom_follow_depth < 0.0) { if (m_btrack_wrn.overflow()) { std::string desc = String::str(DTR("water column not deep enough for altitude control ( %0.2f < %0.2f )"), msg->alt + m_estate.depth, m_vertical_ref); setEntityState(IMC::EntityState::ESTA_NORMAL, desc); war("%s", desc.c_str()); m_btrack_wrn.reset(); } } else { m_btrack_wrn.reset(); } // Will not let the bottom follow depth be lower than zero // to avoid causing excessive controller integration m_bottom_follow_depth = std::max(m_bottom_follow_depth, (float)0.0); } else if (m_vertical_mode == VERTICAL_MODE_PITCH) { if (m_estate.depth >= m_max_depth - c_depth_margin) { const std::string desc = DTR("getting too close to maximum admissible depth"); setEntityState(IMC::EntityState::ESTA_ERROR, desc); err("%s", desc.c_str()); requestDeactivation(); return; } } // check if yaw control mode is valid if (m_yaw_mode >= YAW_MODE_SIZE) { signalBadYaw(DTR("invalid yaw control mode %d")); return; } else if (m_yaw_mode == YAW_MODE_NONE) { float delta = m_ymode_delta.getDelta(); if (delta > 0.0) m_ymode_wait += delta; if (m_ymode_wait > c_mode_timeout) { m_ymode_wait = 0.0; signalBadYaw(DTR("timed out waiting for yaw control mode")); } return; } // Compute time delta. float timestep = m_last_estate.getDelta(); // Check if we have a valid time delta. if (timestep < 0.0) return; onEstimatedState(timestep, msg); }