std::unique_ptr<JsonX::Object> Channel::ctrl(std::unique_ptr<JsonX::Object>&& request) { if (!m_remote) throw runtime_error("Not connected"); return m_remote.ctrl(move(request)); }
Value::Value( Value && other ) { _data = move(other._data); }
int main() { int a[200][200]; x1=0; y1=0; initscr(); start_color(); init_pair(2,COLOR_GREEN,COLOR_BLACK); init_pair(3,6,COLOR_BLACK); init_pair(4,COLOR_RED,COLOR_BLACK); attrset(A_BOLD); noecho(); c=0; x=0; y=0; clear(); refresh(); color_set(2,0); move(0,0); addstr("+"); refresh(); while(c!='*') { x1=0; y1=0; while(y1<COLS-1) { while(x1<LINES-1) { if(a[x1][y1]==1) { move(x1,y1); if((x1==x)&&(y1==y)) { color_set(4,0); addstr("+"); refresh(); } else { color_set(3,0); addstr("o"); refresh(); } } x1+=1; } x1=0; y1+=1; } c=getchar(); if(c=='c') { x1=0; y1=0; while(y1<COLS) { while(x1<LINES) { a[x1][y1]=0; x1+=1; } x1=0; y1+=1; } clear(); color_set(2,0); move(x,y); addstr("+"); refresh(); } if(c=='i') { x1=0; y1=0; while(y1<COLS-1) { while(x1<LINES-1) { if(a[x1][y1]==1) { a[x1][y1]=0; } else { a[x1][y1]=1; } x1+=1; } x1=0; y1+=1; } x1=0; y1=0; while(y1<COLS-1) { while(x1<LINES-1) { if(a[x1][y1]==1) { move(x1,y1); if((x1==x)&&(y1==y)) { color_set(4,0); addstr("+"); refresh(); } else { color_set(3,0); addstr("o"); refresh(); } } else { move(x1,y1); if((x1==x)&&(y1==y)) { color_set(2,0); addstr("+"); refresh(); } else { color_set(3,0); addstr(" "); refresh(); } } x1+=1; } y1+=1; x1=0; } } if(c=='o') { x1=0; y1=0; while(y1<COLS) { while(x1<LINES) { a[x1][y1]=1; x1+=1; } x1=0; y1+=1; } x1=0; y1=0; while(y1<COLS-1) { while(x1<LINES-1) { if(a[x1][y1]==1) { move(x1,y1); if((x1==x)&&(y1==y)) { color_set(4,0); addstr("+"); refresh(); } else { color_set(3,0); addstr("o"); refresh(); } } x1+=1; } x1=0; y1+=1; } } if(c==13) { if(a[x][y]==0) { a[x][y]=1; continue; } if(a[x][y]==1) { a[x][y]=0; color_set(2,0); move(x,y); addstr("+"); } } if(c==68) { if(y>0) { yy=(y-1); color_set(2,0); move(x,y); addstr(" "); move(x,yy); addstr("+"); refresh(); y=yy; } } if(c==67) { if(y<COLS-1) { yy=(y+1); color_set(2,0); move(x,y); addstr(" "); move(x,yy); addstr("+"); refresh(); y=yy; } } if(c==66) { if(x<LINES-1) { xx=(x+1); color_set(2,0); move(x,y); addstr(" "); move(xx,y); addstr("+"); refresh(); x=xx; } } if(c==65) { if(x>0) { xx=(x-1); color_set(2,0); move(x,y); addstr(" "); move(xx,y); addstr("+"); refresh(); x=xx; } } } endwin(); }
/** * Return nanoseconds since start of copy. * * @returns nanoseconds since program start as a 64 bit unsigned integer. */ uint64_t get_time_delta(void) { static struct timeval stv = {.tv_sec = 0}; struct timeval ctv; if (gettimeofday(&ctv, NULL) < 0) fserr(PCOPY_EXIT_FAILURE, "gettimeofday", "current"); if (stv.tv_sec == 0) stv = ctv; if (stv.tv_sec == ctv.tv_sec) return (ctv.tv_usec - stv.tv_usec) * THOUSAND; uint64_t res = ctv.tv_sec - stv.tv_sec - 1; res *= MILLION; res += (MILLION - stv.tv_usec) + ctv.tv_usec; return res * THOUSAND; // micros to nanos } /** * Start up the copy of a segment. Once the open is complete and * the seek to the correct offset is done, let the main thread know * it can continue with the next thread. We start one at a time. * * @param[in,out] fseg The descriptor of the segment to copy. */ void copy_start(file_seg_t * fseg) { static char const st_fmt[] = "th %2d reading 0x%08lX"; if (! HAVE_OPT(QUIET)) { pthread_mutex_lock(&tty_mutex); if (fseg->idx == 0) { move(0,0); printw("copying %s", fseg->fname); move(1,0); printw("copy to %s", fseg->dname); } move(ENTRY_LINE, 0); printw(st_fmt, fseg->idx, fseg->start); refresh(); pthread_mutex_unlock(&tty_mutex); } fseg->fdin = open(fseg->fname, O_RDONLY); if (fseg->fdin < 0) fserr(PCOPY_EXIT_FS_ERR_IN, "open (r)", fseg->fname); fseg->fdout = open(fseg->dname, O_RDWR | O_CREAT, 0600); if (fseg->fdout < 0) fserr(PCOPY_EXIT_FS_ERR_OUT, "open (w)", fseg->dname); if (fseg->start > 0) { if (lseek(fseg->fdin, fseg->start, SEEK_SET) != fseg->start) fserr(PCOPY_EXIT_FS_ERR_IN, "seek (in)", fseg->fname); if (lseek(fseg->fdout, fseg->start, SEEK_SET) != fseg->start) fserr(PCOPY_EXIT_FS_ERR_OUT, "seek (out)", fseg->dname); } if (posix_fadvise(fseg->fdin, fseg->start, fseg->end - fseg->start, POSIX_FADV_SEQUENTIAL) != 0) fserr(PCOPY_EXIT_FS_ERR_IN, "fadvise(r)", fseg->fname); if (posix_fadvise(fseg->fdout, fseg->start, fseg->end - fseg->start, POSIX_FADV_SEQUENTIAL) != 0) fserr(PCOPY_EXIT_FS_ERR_OUT, "fadvise(w)", fseg->dname); pthread_mutex_lock(&th_start_mutex); pthread_cond_signal(&th_start_cond); pthread_mutex_unlock(&th_start_mutex); fseg->lastt = get_time_delta(); } /** * Show copy progress. The display happens if "quiet" has not been * specified. This function will also sleep, if "flow-rate" has * been specified and the time since the last segment read has been * too short. * * @param[in,out] fseg file segment descriptor. "lastt" may be updated. */ void copy_progress(file_seg_t * fseg) { static char const prg_fmt[] = " read to 0x%08lX togo 0x%08lX"; if (! HAVE_OPT(QUIET)) { pthread_mutex_lock(&tty_mutex); move(ENTRY_LINE + 1, 0); printw(prg_fmt, fseg->start, fseg->end - fseg->start); refresh(); pthread_mutex_unlock(&tty_mutex); } if (HAVE_OPT(FLOW_RATE)) { uint64_t cdelta = get_time_delta(); // delta from start uint64_t chunk_time = cdelta - fseg->lastt; // since chunk start /* * If the time used is more than 1/100 of a second less than * the time that is supposed to be consumed, then nanosleep. */ if (chunk_time < nsec_per_iteration - (10*MILLION)) { uint64_t slptm = nsec_per_iteration - chunk_time; struct timespec ts = { .tv_sec = (slptm > BILLION) ? (slptm / BILLION) : 0, .tv_nsec = (slptm > BILLION) ? (slptm % BILLION) : slptm }; (void)nanosleep(&ts, NULL); fseg->lastt = get_time_delta(); } else { fseg->lastt = cdelta; } } }
repetition::repetition(std::shared_ptr<behavior_node> && child) : child(move(child)) { child.reset(); }
//----------------------------------------------------------------------------- // Purpose: Apply joystick to CUserCmd creation // Input : frametime - // *cmd - //----------------------------------------------------------------------------- void CInput::JoyStickMove(float frametime, CUserCmd *cmd) { // complete initialization if first time in ( needed as cvars are not available at initialization time ) if (!m_fJoystickAdvancedInit) { Joystick_Advanced(); m_fJoystickAdvancedInit = true; } // Verify that the user wants to use the joystick if (!in_joystick.GetInt()) return; // Reinitialize the 'advanced joystick' system if hotplugging has caused us toggle between some/none joysticks. bool haveJoysticks = (inputsystem->GetJoystickCount() > 0); if (haveJoysticks != m_fHadJoysticks) { Joystick_Advanced(); m_fHadJoysticks = haveJoysticks; } // Verify that a joystick is available if (!haveJoysticks) return; if (m_flRemainingJoystickSampleTime <= 0) return; frametime = MIN(m_flRemainingJoystickSampleTime, frametime); m_flRemainingJoystickSampleTime -= frametime; QAngle viewangles; // Get starting angles engine->GetViewAngles(viewangles); struct axis_t { float value; int controlType; }; axis_t gameAxes[MAX_GAME_AXES]; memset(&gameAxes, 0, sizeof(gameAxes)); // Get each joystick axis value, and normalize the range for (int i = 0; i < MAX_JOYSTICK_AXES; ++i) { if (GAME_AXIS_NONE == m_rgAxes[i].AxisMap) continue; float fAxisValue = inputsystem->GetAnalogValue((AnalogCode_t)JOYSTICK_AXIS(0, i)); if (joy_wwhack2.GetInt() != 0) { // this is a special formula for the Logitech WingMan Warrior // y=ax^b; where a = 300 and b = 1.3 // also x values are in increments of 800 (so this is factored out) // then bounds check result to level out excessively high spin rates float fTemp = 300.0 * pow(abs(fAxisValue) / 800.0, 1.3); if (fTemp > 14000.0) fTemp = 14000.0; // restore direction information fAxisValue = (fAxisValue > 0.0) ? fTemp : -fTemp; } unsigned int idx = m_rgAxes[i].AxisMap; gameAxes[idx].value = fAxisValue; gameAxes[idx].controlType = m_rgAxes[i].ControlMap; } // Re-map the axis values if necessary, based on the joystick configuration if ((joy_advanced.GetInt() == 0) && (in_jlook.state & 1)) { // user wants forward control to become pitch control gameAxes[GAME_AXIS_PITCH] = gameAxes[GAME_AXIS_FORWARD]; gameAxes[GAME_AXIS_FORWARD].value = 0; // if mouse invert is on, invert the joystick pitch value // Note: only absolute control support here - joy_advanced = 0 if (m_pitch->GetFloat() < 0.0) { gameAxes[GAME_AXIS_PITCH].value *= -1; } } if ((in_strafe.state & 1) || (lookstrafe.GetFloat() && (in_jlook.state & 1))) { // user wants yaw control to become side control gameAxes[GAME_AXIS_SIDE] = gameAxes[GAME_AXIS_YAW]; gameAxes[GAME_AXIS_YAW].value = 0; } m_flPreviousJoystickForward = ScaleAxisValue(gameAxes[GAME_AXIS_FORWARD].value, MAX_BUTTONSAMPLE * joy_forwardthreshold.GetFloat()); m_flPreviousJoystickSide = ScaleAxisValue(gameAxes[GAME_AXIS_SIDE].value, MAX_BUTTONSAMPLE * joy_sidethreshold.GetFloat()); m_flPreviousJoystickPitch = ScaleAxisValue(gameAxes[GAME_AXIS_PITCH].value, MAX_BUTTONSAMPLE * joy_pitchthreshold.GetFloat()); m_flPreviousJoystickYaw = ScaleAxisValue(gameAxes[GAME_AXIS_YAW].value, MAX_BUTTONSAMPLE * joy_yawthreshold.GetFloat()); // Skip out if vgui is active if (vgui::surface()->IsCursorVisible()) return; // If we're inverting our joystick, do so if (joy_inverty.GetBool()) { m_flPreviousJoystickPitch *= -1.0f; } // drive yaw, pitch and move like a screen relative platformer game if (CAM_IsThirdPerson() && thirdperson_platformer.GetInt()) { if (m_flPreviousJoystickForward || m_flPreviousJoystickSide) { // apply turn control [ YAW ] // factor in the camera offset, so that the move direction is relative to the thirdperson camera viewangles[YAW] = RAD2DEG(atan2(-m_flPreviousJoystickSide, -m_flPreviousJoystickForward)) + g_ThirdPersonManager.GetCameraOffsetAngles()[YAW]; engine->SetViewAngles(viewangles); // apply movement Vector2D moveDir(m_flPreviousJoystickForward, m_flPreviousJoystickSide); cmd->forwardmove += moveDir.Length() * cl_forwardspeed.GetFloat(); } if (m_flPreviousJoystickPitch || m_flPreviousJoystickYaw) { Vector vTempOffset = g_ThirdPersonManager.GetCameraOffsetAngles(); // look around with the camera vTempOffset[PITCH] += m_flPreviousJoystickPitch * joy_pitchsensitivity.GetFloat(); vTempOffset[YAW] += m_flPreviousJoystickYaw * joy_yawsensitivity.GetFloat(); g_ThirdPersonManager.SetCameraOffsetAngles(vTempOffset); } if (m_flPreviousJoystickForward || m_flPreviousJoystickSide || m_flPreviousJoystickPitch || m_flPreviousJoystickYaw) { Vector vTempOffset = g_ThirdPersonManager.GetCameraOffsetAngles(); // update the ideal pitch and yaw cam_idealpitch.SetValue(vTempOffset[PITCH] - viewangles[PITCH]); cam_idealyaw.SetValue(vTempOffset[YAW] - viewangles[YAW]); } return; } float joySideMove = 0.f; float joyForwardMove = 0.f; float aspeed = frametime * gHUD.GetFOVSensitivityAdjust(); // apply forward and side control int iResponseCurve = joy_response_move.GetInt(); float val = ResponseCurve(iResponseCurve, m_flPreviousJoystickForward, PITCH, joy_forwardsensitivity.GetFloat()); joyForwardMove += val * cl_forwardspeed.GetFloat(); val = ResponseCurve(iResponseCurve, m_flPreviousJoystickSide, YAW, joy_sidesensitivity.GetFloat()); joySideMove += val * cl_sidespeed.GetFloat(); Vector2D move(m_flPreviousJoystickYaw, m_flPreviousJoystickPitch); float dist = move.Length(); // apply turn control float angle = 0.f; if (JOY_ABSOLUTE_AXIS == gameAxes[GAME_AXIS_YAW].controlType) { float fAxisValue = ResponseCurveLook(joy_response_look.GetInt(), m_flPreviousJoystickYaw, YAW, m_flPreviousJoystickPitch, dist, frametime); angle = fAxisValue * joy_yawsensitivity.GetFloat() * aspeed * cl_yawspeed.GetFloat(); } else { angle = m_flPreviousJoystickYaw * joy_yawsensitivity.GetFloat() * aspeed * 180.0; } angle = JoyStickAdjustYaw(angle); viewangles[YAW] += angle; cmd->mousedx = angle; // apply look control if (IsX360() || in_jlook.state & 1) { float angle = 0; if (JOY_ABSOLUTE_AXIS == gameAxes[GAME_AXIS_PITCH].controlType) { float fAxisValue = ResponseCurveLook(joy_response_look.GetInt(), m_flPreviousJoystickPitch, PITCH, m_flPreviousJoystickYaw, dist, frametime); angle = fAxisValue * joy_pitchsensitivity.GetFloat() * aspeed * cl_pitchspeed.GetFloat(); } else { angle = m_flPreviousJoystickPitch * joy_pitchsensitivity.GetFloat() * aspeed * 180.0; } viewangles[PITCH] += angle; cmd->mousedy = angle; view->StopPitchDrift(); if (m_flPreviousJoystickPitch == 0.f && lookspring.GetFloat() == 0.f) { // no pitch movement // disable pitch return-to-center unless requested by user // *** this code can be removed when the lookspring bug is fixed // *** the bug always has the lookspring feature on view->StopPitchDrift(); } } // apply player motion relative to screen space if (CAM_IsThirdPerson() && thirdperson_screenspace.GetInt()) { float ideal_yaw = cam_idealyaw.GetFloat(); float ideal_sin = sin(DEG2RAD(ideal_yaw)); float ideal_cos = cos(DEG2RAD(ideal_yaw)); float side_movement = ideal_cos*joySideMove - ideal_sin*joyForwardMove; float forward_movement = ideal_cos*joyForwardMove + ideal_sin*joySideMove; cmd->forwardmove += forward_movement; cmd->sidemove += side_movement; } else { cmd->forwardmove += joyForwardMove; cmd->sidemove += joySideMove; } if (IsPC()) { CCommand tmp; if (FloatMakePositive(joyForwardMove) >= joy_autosprint.GetFloat() || FloatMakePositive(joySideMove) >= joy_autosprint.GetFloat()) { KeyDown(&in_joyspeed, NULL); } else { KeyUp(&in_joyspeed, NULL); } } // Bound pitch viewangles[PITCH] = clamp(viewangles[PITCH], -cl_pitchup.GetFloat(), cl_pitchdown.GetFloat()); engine->SetViewAngles(viewangles); }
void detectChanges(){ int i, j; for(i=0; i<noOfHits; i++){ move(hits[i]); } }
void spox_draw(struct spox *s, int **image) { int m, n, a, h, w, ypos, bright, inter; #ifdef CONIO int inc; memset(coniobuf, 0, CONIOBUFSIZE); inc = 0; #endif ypos = s->offset_y; inter = (1 << s->interval) - 1; bright = inter * s->bright / s->interval; w = s->img_width; h = s->img_height - PPH; for (n = 0; n < h; n += PPH) { #ifdef CURSES move(ypos++, s->offset_x); #endif for (m = 0; m < w; m += PPW) { if ((image[n ][m ] & inter) > bright) a = 0x01; else a = 0x00; if ((image[n ][m+1] & inter) > bright) a |= 0x02; if ((image[n+1][m ] & inter) > bright) a |= 0x04; if ((image[n+1][m+1] & inter) > bright) a |= 0x08; if ((image[n+2][m ] & inter) > bright) a |= 0x10; if ((image[n+2][m+1] & inter) > bright) a |= 0x20; #ifdef CURSES addch(c[a]); #endif #ifdef CONIO coniobuf[inc++] = (7<<8) + c[a]; #endif } } #ifdef CURSES move(ypos, s->offset_x); #endif w = s->img_width - 2 * PPW; for (m = 0; m < w; m += PPW) { if ((image[n ][m ] & inter) > bright) a = 0x01; else a = 0x00; if ((image[n ][m+1] & inter) > bright) a |= 0x02; if ((image[n+1][m ] & inter) > bright) a |= 0x04; if ((image[n+1][m+1] & inter) > bright) a |= 0x08; if ((image[n+2][m ] & inter) > bright) a |= 0x10; if ((image[n+2][m+1] & inter) > bright) a |= 0x20; #ifdef CURSES addch(c[a]); #endif #ifdef CONIO coniobuf[inc++] = (7<<8) + c[a]; #endif } #ifdef CURSES refresh(); #endif #ifdef CONIO puttext(s->offset_x + 1, s->offset_y + 1, s->scr_width - s->offset_x, s->scr_height - s->offset_y, coniobuf); #endif }
void Game::round() { std::set<Piece*> gamePieces; for (auto reset = __grid.begin(); reset != __grid.end(); ++reset) { if (*reset) { gamePieces.insert(gamePieces.end(), *reset); (*reset)->setTurned(false); } } for (auto turn = gamePieces.begin(); turn != gamePieces.end(); ++turn) { if (!(*turn)->getTurned()) { (*turn)->setTurned(true); (*turn)->age(); ActionType ac = (*turn)->takeTurn(getSurroundings((*turn)->getPosition())); Position pBefore = (*turn)->getPosition(); Position pAfter = move(pBefore, ac); if (pBefore.x != pAfter.x || pBefore.y != pAfter.y) { Piece *p = __grid[pAfter.y + (pAfter.x * __width)]; if (p) { (*(*turn)) * (*p); if ((*turn)->getPosition().x != pBefore.x || (*turn)->getPosition().y != pBefore.y) { __grid[pAfter.y + (pAfter.x * __width)] = (*turn); __grid[pBefore.y + (pBefore.x * __width)] = p; } } else { (*turn)->setPosition(pAfter); __grid[pAfter.y + (pAfter.x * __width)] = (*turn); __grid[pBefore.y + (pBefore.x * __width)] = nullptr; } } } } for (unsigned int i = 0; i < __grid.size(); ++i) { if (__grid[i] && !(__grid[i]->isViable())) { delete __grid[i]; __grid[i] = nullptr; } } if (getNumResources() <= 0) { __status = Status::OVER; } __round++; }
void Channel::onRemoteSend(std::unique_ptr<JsonX::Object>&& message, MessagePriority priority) { if (!receiveFunction) throw runtime_error("Receive not supported"); receiveFunction(move(message), priority); }
std::unique_ptr<JsonX::Object> Channel::onRemoteCtrl(std::unique_ptr<JsonX::Object>&& request) { if (!ctrlFunction) throw runtime_error("Control not supported"); return ctrlFunction(move(request)); }
void Channel::onRemoteClose(std::unique_ptr<JsonX::Object>&& parameter) { if (!closeFunction) throw runtime_error("Close not supported"); closeFunction(move(parameter)); }
void Channel::onRemoteOpen(std::unique_ptr<JsonX::Object>&& parameter) { if (!openFunction) throw runtime_error("Open not supported"); openFunction(move(parameter)); }
ChannelProxy Channel::onRemoteConnect(ChannelProxy backlink, std::unique_ptr<JsonX::Object>&& parameter) { if (!connectFunction) throw runtime_error("Connect not supported"); return connectFunction(backlink, move(parameter)); }
String::String(StringSumHelper &&rval) { init(); move(rval); }
int main(void) { // seed pseudorandom number generator srand48(time(NULL)); // instantiate window GWindow window = newGWindow(WIDTH, HEIGHT); // instantiate bricks initBricks(window); // instantiate ball, centered in middle of window GOval ball = initBall(window); // add ball to window add(window, ball); // instantiate paddle, centered at bottom of window GRect paddle = initPaddle(window); // add paddle to window add(window, paddle); // instantiate scoreboard, centered in middle of window, just above ball GLabel label = initScoreboard(window); // add label to window add(window, label); // number of bricks initially int bricks = COLS * ROWS; // number of lives initially int lives = LIVES; // number of points initially int points = 0; // ball velocity double velocity_x = drand48() * 2 + 1; double velocity_y = drand48() * 2 + 1; bool ballMove = false; // keep playing until game over while (lives > 0 && bricks > 0) { // check for mouse event GEvent event = getNextEvent(MOUSE_EVENT); GEvent event2 = getNextEvent(MOUSE_EVENT); // if we heard one if (event != NULL) { // if the event was moved if (getEventType(event) == MOUSE_CLICKED) { ballMove = true; } } // if we heard one if (event != NULL) { // if the event was moved if (getEventType(event) == MOUSE_MOVED && ballMove == true) { double y = getY(paddle); // ensure paddle doesn't go out of window if (getX(event) <= 0) { setLocation(paddle, 0, y); } else if (getX(event) + PADDLEWIDTH >= WIDTH) { setLocation(paddle, WIDTH - PADDLEWIDTH, y); } else { // ensure paddle x position follows cursor double x = getX(event); setLocation(paddle, x, y); } } } if (ballMove == true) { move(ball, velocity_x, velocity_y); // when ball hits the left edge if (getX(ball) <= 0) { velocity_x *= -1; } // when ball hits the right edge else if (getX(ball) + getWidth(ball) >= getWidth(window)) { velocity_x *= -1; } // when ball hits the top edge else if (getY(ball) <= 0) { velocity_y *= -1; } // when ball hit the bottom edge else if (getY(ball) >= getHeight(window)) { lives -= 1; ballMove = false; setLocation(ball, WIDTH / 2, HEIGHT / 2); } pause(10); } GObject object = detectCollision(window, ball); if (object != NULL) { if (object == paddle) { velocity_y *= -1; } else if (strcmp(getType(object), "GRect") == 0) { velocity_y *= -1; removeGWindow(window, object); points += 1; updateScoreboard(window, label, points); } } // when no more live or all bricks are broken if (lives == 0 || points == ROWS * COLS) { break; } } // wait for click before exiting waitForClick(); // game over closeGWindow(window); return 0; }
void MainWindow::mouseMoveEvent(QMouseEvent *event) { move(event->globalX()-m_nMouseClick_X_Coordinate,event->globalY()-m_nMouseClick_Y_Coordinate); }
void movein(int iSpeed, float dist) { move(iSpeed, abs((dist-1.75)*1000.0/13.0)); }
void Widget::resizeWindow(QMouseEvent *e) { if (!Settings::getInstance().getUseNativeDecoration()) { if (allowToResize) { int xMouse = e->pos().x(); int yMouse = e->pos().y(); int wWidth = geometry().width(); int wHeight = geometry().height(); if (cursor().shape() == Qt::SizeVerCursor) { if (resizeVerSup) { int newY = geometry().y() + yMouse; int newHeight = wHeight - yMouse; if (newHeight > minimumSizeHint().height()) { resize(wWidth, newHeight); move(geometry().x(), newY); } } else resize(wWidth, yMouse+1); } else if (cursor().shape() == Qt::SizeHorCursor) { if (resizeHorEsq) { int newX = geometry().x() + xMouse; int newWidth = wWidth - xMouse; if (newWidth > minimumSizeHint().width()) { resize(newWidth, wHeight); move(newX, geometry().y()); } } else resize(xMouse, wHeight); } else if (cursor().shape() == Qt::SizeBDiagCursor) { int newX = 0; int newWidth = 0; int newY = 0; int newHeight = 0; if (resizeDiagSupDer) { newX = geometry().x(); newWidth = xMouse; newY = geometry().y() + yMouse; newHeight = wHeight - yMouse; } else { newX = geometry().x() + xMouse; newWidth = wWidth - xMouse; newY = geometry().y(); newHeight = yMouse; } if (newWidth >= minimumSizeHint().width() and newHeight >= minimumSizeHint().height()) { resize(newWidth, newHeight); move(newX, newY); } else if (newWidth >= minimumSizeHint().width()) { resize(newWidth, wHeight); move(newX, geometry().y()); } else if (newHeight >= minimumSizeHint().height()) { resize(wWidth, newHeight); move(geometry().x(), newY); } } else if (cursor().shape() == Qt::SizeFDiagCursor) { if (resizeDiagSupEsq) { int newX = geometry().x() + xMouse; int newWidth = wWidth - xMouse; int newY = geometry().y() + yMouse; int newHeight = wHeight - yMouse; if (newWidth >= minimumSizeHint().width() and newHeight >= minimumSizeHint().height()) { resize(newWidth, newHeight); move(newX, newY); } else if (newWidth >= minimumSizeHint().width()) { resize(newWidth, wHeight); move(newX, geometry().y()); } else if (newHeight >= minimumSizeHint().height()) { resize(wWidth, newHeight); move(geometry().x(), newY); } } else resize(xMouse+1, yMouse+1); } e->accept(); } } }
//main int main(){ int address[100]; int n,i,j=0; int num,result,mode; int start,end; char str[10]; int read; //データ入力部分 while(1){ scanf("%d",&temp.year); if(temp.year<0)break; scanf("%d",&temp.month);if(temp.month<0)break; scanf("%d",&temp.day); if(temp.day<0)break; scanf("%s",temp.item); if(temp.item[0]=='-')break; scanf("%d",&temp.cate); if(temp.cate<0)break; scanf("%d",&temp.value);if(temp.value<0)break; scanf("%d",&temp.inout);if(temp.inout<0)break; data[data_sum]=temp; data_sum++; } while(1){ printf("モード選択\n"); printf("追加-->1 検索-->2 出力-->3\n"); scanf("%d",&mode); //データ追加 if(mode==1){ printf("データ追加\n"); scanf("%d",&temp.year); scanf("%d",&temp.month); scanf("%d",&temp.day); scanf("%s",temp.item); scanf("%d",&temp.cate); scanf("%d",&temp.value); scanf("%d",&temp.inout); num=search(0.0); //back,searchを使用 move(num,0); //moveを使用 data[num]=temp; } //データ検索 else if(mode==2){ printf("データ検索\n"); printf("日付検索-->1 期間指定検索-->2 カテゴリ検索-->3\n"); scanf("%d",&mode); //日付で検索 if(mode==1){ scanf("%d",&temp.year); scanf("%d",&temp.month); scanf("%d",&temp.day); result=search(0,0); if(result==-1){ printf("該当値なし\n"); }else{ start=top(result); end=back(result); j=0; for(i=start;i<=end;i++){ address[j]=i; outstruct[j++]=data[i]; } for(i=0;i<j;i++){ printf("%d :%d/%d/%d ",i+1,outstruct[i].year,outstruct[i].month,outstruct[i].day); printf("%s ",outstruct[i].item); printf("%d ",outstruct[i].cate); printf("%d ",outstruct[i].value); printf("%d\n",outstruct[i].inout); } } } //期間指定検索 else if(mode==2){ scanf("%d",&temp.year); scanf("%d",&temp.month); scanf("%d",&temp.day); scanf("%d",&n); printf("%d年%d月%d日から%d日間のデータを検索します\n\n",temp.year,temp.month,temp.day,n); start=top(search(0,0)); end=serch_later(n,0); printf("配列番号%d番から%d番までのデータが該当します。\n",start,end); printf("該当データを出力します。\n\n"); if(data[end].year==0)printf("存在しません"); else for(i=start;i<=end;i++){ address[j]=i; outstruct[j++]=data[i]; } for(i=0;i<j;i++){ printf("%d :%d/%d/%d ",i+1,outstruct[i].year,outstruct[i].month,outstruct[i].day); printf("%s ",outstruct[i].item); printf("%d ",outstruct[i].cate); printf("%d ",outstruct[i].value); printf("%d\n",outstruct[i].inout); } } //カテゴリで検索 else if(mode==3){ printf("検索するカテゴリを入力\n"); scanf("%d",&read); j=0; for(i=0;i<data_sum;i++){ if(data[i].cate==read){ address[j]=i; outstruct[j++]=data[i]; } } for(i=0;i<j;i++){ printf("%d :%4d/%2d/%2d ",i+1,outstruct[i].year,outstruct[i].month,outstruct[i].day); printf("%10s ",outstruct[i].item); printf("%2d ",outstruct[i].cate); printf("%10d ",outstruct[i].value); printf("%2d\n",outstruct[i].inout); } } //続行確認 printf("続けて編集,削除を行いますか\n"); printf("行わない--> 0 編集-->1 削除-->2\n"); scanf("%d",&mode); if(mode!=0){ if(mode==1)sprintf(str,"編集"); else if(mode==2)sprintf(str,"削除"); printf("検索したデータの左の番号で%sを行います。",str); printf("%sしたいデータの番号を入力してください\n",str); scanf("%d",&num); num--; printf("%d :%d/%d/%d ",num+1,outstruct[num].year,outstruct[num].month,outstruct[num].day); printf("%s ",outstruct[num].item); printf("%d ",outstruct[num].cate); printf("%d ",outstruct[num].value); printf("%d\n",outstruct[num].inout); printf("このデータを%sします。\n",str); //編集 if(mode==1){ printf("データを入力して下さい\n"); move(address[num],1); scanf("%d",&temp.year); scanf("%d",&temp.month); scanf("%d",&temp.day); scanf("%s",temp.item); scanf("%d",&temp.cate); scanf("%d",&temp.value); scanf("%d",&temp.inout); num=search(0.0); //back,searchを使用 move(num,0); //moveを使用 data[num]=temp; //削除 }else if(mode==2){ move(address[num],1); } } } //出力 else if(mode==3){ for(i=0;i<data_sum;i++){ printf("%4d/%2d/%2d ",data[i].year,data[i].month,data[i].day); printf("%10s ",data[i].item); printf("%2d ",data[i].cate); printf("%10d ",data[i].value); printf("%2d\n",data[i].inout); } } printf("続行-->1 終了-->2\n"); scanf("%d",&read); if(read==2)break; } return 0; }
static void do_talk_char(struct talk_win *twin, int ch) { extern int dumb_term; extern screenline* big_picture; screenline* line; int i; char ch0, buf[81]; if (isprint2(ch)) { ch0 = big_picture[twin->curln].data[twin->curcol]; if (big_picture[twin->curln].len < 79) move(twin->curln, twin->curcol); else do_talk_nextline(twin); outc(ch); ++(twin->curcol); line = big_picture + twin->curln; if (twin->curcol < line->len) { /* insert */ ++(line->len); memcpy(buf, line->data + twin->curcol, 80); save_cursor(); do_move(twin->curcol, twin->curln); ochar(line->data[twin->curcol] = ch0); for (i = twin->curcol + 1; i < line->len; i++) ochar(line->data[i] = buf[i - twin->curcol - 1]); restore_cursor(); } line->data[line->len] = 0; return; } switch (ch) { case Ctrl('H'): case '\177': if (twin->curcol == 0) { return; } line = big_picture + twin->curln; --(twin->curcol); if (twin->curcol < line->len) { --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); for (i = twin->curcol; i < line->len; i++) ochar(line->data[i] = line->data[i + 1]); line->data[i] = 0; ochar(' '); restore_cursor(); } move(twin->curln, twin->curcol); return; case Ctrl('D'): line = big_picture + twin->curln; if (twin->curcol < line->len) { --(line->len); save_cursor(); do_move(twin->curcol, twin->curln); for (i = twin->curcol; i < line->len; i++) ochar(line->data[i] = line->data[i + 1]); line->data[i] = 0; ochar(' '); restore_cursor(); } return; case Ctrl('G'): bell(); return; case Ctrl('B'): if (twin->curcol > 0) { --(twin->curcol); move(twin->curln, twin->curcol); } return; case Ctrl('F'): if (twin->curcol < 79) { ++(twin->curcol); move(twin->curln, twin->curcol); } return; case Ctrl('A'): twin->curcol = 0; move(twin->curln, twin->curcol); return; case Ctrl('K'): clrtoeol(); return; case Ctrl('Y'): twin->curcol = 0; move(twin->curln, twin->curcol); clrtoeol(); return; case Ctrl('E'): twin->curcol = big_picture[twin->curln].len; move(twin->curln, twin->curcol); return; case Ctrl('M'): case Ctrl('J'): line = big_picture + twin->curln; strncpy(buf, line->data, line->len); buf[line->len] = 0; if (dumb_term) outc('\n'); do_talk_nextline(twin); break; case Ctrl('P'): line = big_picture + twin->curln; strncpy(buf, line->data, line->len); buf[line->len] = 0; if (twin->curln > twin->sline) { --(twin->curln); move(twin->curln, twin->curcol); } break; case Ctrl('N'): line = big_picture + twin->curln; strncpy(buf, line->data, line->len); buf[line->len] = 0; if (twin->curln < twin->eline) { ++(twin->curln); move(twin->curln, twin->curcol); } break; } str_trim(buf); if (*buf) fprintf(flog, "%s%s: %s%s\n", (twin->eline == b_lines - 1) ? "[1;33m" : "", (twin->eline == b_lines - 1) ? getuserid(currutmp->destuid) : cuser.userid, buf, (ch == Ctrl('P')) ? "[37;45m(Up)[m" : "[m"); }
void ChangeDetectionController::step(double &left, double &right) { ChangeDetectionAgentWorldModel* worldModel = dynamic_cast<ChangeDetectionAgentWorldModel*> (_wm); RobotAgentPtr agent = gWorld->getAgent(worldModel->_agentId); setLED(); agent->setConnectToOthers(Agent::NEUTRAL); if(agent->isPartOfOrganism()){ worldModel->organismTime++; }else{ worldModel->swarmTime++; } // retrieve the values of the distance sensors vector<double> inputs = this->getSensorValues(); if (inputs.size() == 0) { cerr << "ERR: robot did not return any distance sensor data - can't build neural net" << endl; return; } inputs.push_back(1); // bias node // Outputs are the following: // Node 1: Form Organism // Node 2: Leave Organism // Node 3: Halt // Node 4: Avoid obstacle // Node 5: Move to direction // Node 6: Desired organism size - for node 1 // Node 7: Desired direction - for node 5 // Node 8: Desired speed - for node 5 vector<double> outputs = vector<double> (8, 0); // create the neural net if it didn't exist already if (neuralNet == NULL) { neuralNet = new SimplePerceptron(inputs.size(), outputs.size()); neuralNet->setActivationFunction(&ActivationFunctionTanh::apply); // load the weights neuralNet->loadParameters(&weights.front(), weights.size()); } // set the sensor values as input neuron values neuralNet->step(&inputs.front()); // and calculate the output neuralNet->getOutputValues(&outputs.front()); vector<double> choices; // first 5 elements are strategies for (int i = 0; i < 5; i++) { choices.push_back(outputs[i]); } // the first 5 are interpreted as a choice for a strategy. Highest wins. int choice = distance(choices.begin(), max_element(choices.begin(), choices.end())); // Obtain the numbers for speed, direction, and size of the organism. int org_size = (int) MAX_ORG_SIZE * ((outputs[5]+1)/2); double direction = MAX_ANGLE * outputs[6]; double speed = MAX_SPEED * ((outputs[7]+1)/2); // Do some logging if (gWorld->getIterations() % gOrganismSampleFrequency == 0) { ChangeDetectionSharedData::outputLogFile << worldModel->_agentId << "," << gWorld->getIterations() << ", "; for (int i = 0; i < 8; i++) { ChangeDetectionSharedData::outputLogFile << outputs[i] << ((i < 7) ? ":" : ""); } ChangeDetectionSharedData::outputLogFile << "," << choice << "," << org_size << "," << direction << "," << speed << std::endl; } switch (choice) { case FORM: createOrganism(left, right, org_size, speed); break; case LEAVE: leaveOrganism(left, right); break; case HALT: halt(left, right); break; case AVOID: avoidObstacles(left, right, speed); break; case MOVE: move(left, right, direction, speed); break; } }
int main(void) { // seed pseudorandom number generator srand48(time(NULL)); // instantiate window GWindow window = newGWindow(WIDTH, HEIGHT); // instantiate bricks initBricks(window); // instantiate ball, centered in middle of window GOval ball = initBall(window); // instantiate paddle, centered at bottom of window GRect paddle = initPaddle(window); add(window, ball); // instantiate scoreboard, centered in middle of window, just above ball GLabel label = initScoreboard(window); // number of bricks initially int bricks = COLS * ROWS; // number of lives initially int lives = LIVES; // number of points initially int points = 0; // velocity on x axis double xvel = drand48() + 1; //velocity on y axis double yvel = drand48() + 1; waitForClick(); // keep playing until game over while (lives > 0 && points < 50) { GEvent event = getNextEvent(MOUSE_EVENT); if (event != NULL) { if (getEventType(event) == MOUSE_MOVED) { double x = getX(event) - getWidth(paddle) / 2; setLocation(paddle, x, HEIGHT - 10); } } move(ball, xvel, yvel); if (getX(ball) + getWidth(ball) >= getWidth(window)) { xvel = -xvel; } else if (getX(ball) <= 0) { xvel = -xvel; } else if (getY(ball) >= getHeight(window)) { waitForClick(); printf("lol"); lives--; setLocation(ball, (WIDTH / 2) - RADIUS, (HEIGHT / 2) - RADIUS); } else if (getY(ball) <= 0) { yvel = -yvel; } pause(10); GObject object = detectCollision(window, ball); if (object != NULL) { if (object == paddle) { yvel = -yvel; } else if (strcmp(getType(object), "GRect") == 0) { yvel = -yvel; removeGWindow(window, object); points++; } } updateScoreboard(window, label, points); } // wait for click before exiting waitForClick(); // game over closeGWindow(window); return 0; }
void cl(int y, int x) { move(y, x); hline(' ', COLS - x); }
optional::optional(std::shared_ptr<behavior_node> && child) : child(move(child)) { child.reset(); }
String & String::operator = (StringSumHelper &&rval) { if (this != &rval) move(rval); return *this; }
Value &Value::operator=( Value &&other ) { _data = move(other._data); return *this; }
String::String(String &&rval) { init(); move(rval); }
// SEARCH bool ThreeOpt::route_search(class VRP *V, int r, int rules) { /// /// Searches for a Three-Opt move in route r. /// If a satisfactory move is found, /// then the move is made. If no move is found, false is returned. /// VRPMove M, BestM; int ii,a,b,c,d,e,f; BestM.savings=VRP_INFINITY; int e11, e12, e21, e22, e31, e32; // The edges involved in the move: e1, e2, e3 int accept_type=VRPH_FIRST_ACCEPT; // Initialize to null edges e11=e12=e21=e22=e31=e32=0; if( (rules & VRPH_USE_NEIGHBOR_LIST) > 0) report_error("%s: neighbor_list not used in 3OPT search--searches all nodes in route\n",__FUNCTION__); accept_type = VRPH_FIRST_ACCEPT; //default if( (rules & VRPH_LI_ACCEPT) == VRPH_LI_ACCEPT) accept_type=VRPH_LI_ACCEPT; if( (rules & VRPH_BEST_ACCEPT) == VRPH_BEST_ACCEPT) accept_type=VRPH_BEST_ACCEPT; ii=0; b= V->route[r].start; a=VRPH_MAX(V->pred_array[b],0); // edge 1 is a-b c=VRPH_MAX(V->next_array[b],0); if(c==VRPH_DEPOT) return false; d=VRPH_MAX(V->next_array[c],0); if(d==VRPH_DEPOT) return false; e=VRPH_MAX(V->next_array[d],0); if(e==VRPH_DEPOT) return false; f=VRPH_MAX(V->next_array[e],0); if(f==VRPH_DEPOT) return false; int a_end, c_end, e_end; // Set the a_end to 3 hops back from the route's end since // we will have searched all possible moves by this point. // This is ugly... a_end = VRPH_MAX(VRPH_DEPOT,V->pred_array[VRPH_MAX(VRPH_DEPOT,V->pred_array[VRPH_MAX(VRPH_DEPOT, V->pred_array[V->route[r].end])])]); c_end = VRPH_MAX(VRPH_DEPOT, V->pred_array[V->route[r].end]); e_end = V->route[r].end; int *old_sol=NULL; if(rules & VRPH_TABU) { // Remember the original solution old_sol=new int[V->num_original_nodes+2]; V->export_solution_buff(old_sol); } // Evaluate the first move and then enter the loop // We begin with the edges a-b, c-d, and e-f if(evaluate(V,a,b,c,d,e,f,rules,&M)==true) { if(accept_type==VRPH_FIRST_ACCEPT || ((accept_type==VRPH_LI_ACCEPT)&&M.savings<-VRPH_EPSILON)) { // Make the move if(move(V, &M)==false) report_error("%s: move error 1\n",__FUNCTION__); else { if(!(rules & VRPH_TABU)) return true; else { // Check VRPH_TABU status of move - return true if its ok // or revert to old_sol if not and continue to search. if(V->check_tabu_status(&M, old_sol)) { delete [] old_sol; return true; // The move was ok } // else we reverted back - continue the search for a move } } } if(accept_type==VRPH_BEST_ACCEPT || accept_type==VRPH_LI_ACCEPT) { if(M.is_better(V, &BestM, rules))//if(M.savings<BestM.savings) BestM=M; } } a=b; while(a!=a_end) { b=VRPH_MAX(V->next_array[a],0); c=VRPH_MAX(V->next_array[b],0); while(c!=c_end) { d=VRPH_MAX(V->next_array[c],0); e=VRPH_MAX(V->next_array[d],0); while(e!=e_end) { f=VRPH_MAX(V->next_array[e],0); // Evaluate the move! if(evaluate(V,a,b,c,d,e,f,rules,&M)==true) { if(accept_type==VRPH_FIRST_ACCEPT || ((accept_type==VRPH_LI_ACCEPT)&&M.savings<-VRPH_EPSILON)) { // Make the move if(move(V, &M)==false) report_error("%s: move error 1\n",__FUNCTION__); else { if(!(rules & VRPH_TABU)) return true; else { // Check VRPH_TABU status of move - return true if its ok // or revert to old_sol if not and continue to search. if(V->check_tabu_status(&M, old_sol)) { delete [] old_sol; return true; // The move was ok } // else we reverted back - continue the search for a move } } } if(accept_type==VRPH_BEST_ACCEPT || accept_type==VRPH_LI_ACCEPT) { if(M.is_better(V, &BestM, rules)) BestM=M; } } e=f; } c=d; } a=b; } if(accept_type==VRPH_FIRST_ACCEPT || BestM.savings==VRP_INFINITY) return false; if(accept_type==VRPH_BEST_ACCEPT || accept_type==VRPH_LI_ACCEPT) { if(move(V,&BestM)==false) { report_error("%s: best move evaluates to false\n",__FUNCTION__); } else { if(!(rules & VRPH_TABU)) return true; else { // Check VRPH_TABU status of move - return true if its ok // or revert to old_sol if not and continue to search. if(V->check_tabu_status(&BestM, old_sol)) { delete [] old_sol; return true; // The move was ok } // else we reverted back - search over delete [] old_sol; return false; } } } if(move(V,&BestM)==false)//best_e11,best_e12,best_e21,best_e22, best_e31, best_e32,rules)==false) report_error("%s: first move is false!\n",__FUNCTION__); else return true; return false; }
void Channel::send(std::unique_ptr<JsonX::Object>&& message, MessagePriority priority) { if (!m_remote) throw runtime_error("Not connected"); m_remote.send(move(message), priority); }