void game_loop(int mode) { int y=Y/2,x=X/2; updateB(y, x); updateA(); update_log(); /* il client aspetta */ if (mode) { print_message("Comincia l'avversario, attendi!"); recive_message(); } updateB(y, x); updateA(); update_log(); print_message("Il tuo turno"); update_side_view(1); while (muovi_cursorse(&y, &x)) { updateB(Y,X); updateA(); update_log(); update_side_view(0); while (recive_message()); updateB(y,x); updateA(); update_side_view(1); update_log(); print_message("Il tuo turno"); } }
void sc(Q330 *q330) { int i; BOOL IsIdle, IsActiveHigh; QDP_PKT pkt; UINT32 sc[QDP_NSC]; QDP_TYPE_C1_GLOB glob; /* Get current mapping, plus global data (sensor bitmap lives there) */ if (!qdp_C1_RQSC(q330->qdp, sc)) return; if (!qdp_C1_RQGLOB(q330->qdp, &glob)) return; /* Print current values */ if (q330->cmd.update) printf("Current "); qdpPrint_C1_SC(stdout, sc); printf("C1_GLOB SC bitmap = "); utilPrintBinUINT16(stdout, glob.sensor_map); printf("\n"); /* All done if we aren't changing anything */ if (!q330->cmd.update) return; /* Define and install new sensor control line definitions */ if (q330->cmd.sc.sensorA != UNDEFINED_INST) updateA(sc, q330->cmd.sc.sensorA); if (q330->cmd.sc.sensorB != UNDEFINED_INST) updateB(sc, q330->cmd.sc.sensorB); qdpEncode_C1_SC(&pkt, sc); if (!qdpPostCmd(q330->qdp, &pkt, TRUE)) { printf("Set Physical Interfaces command failed\n"); return; } /* Define and install sensor control bitmap based on the above */ for (glob.sensor_map = 0, i = 0; i < QDP_NSC; i++) { IsIdle = ((UINT32) sc[i] & QDP_SC_MASK) == QDP_SC_IDLE ? TRUE : FALSE; IsActiveHigh = ((UINT32) sc[i] & QDP_SC_ACTIVE_HIGH_BIT) != 0 ? TRUE : FALSE; if ((IsIdle && IsActiveHigh) || (!IsIdle && !IsActiveHigh)) glob.sensor_map |= (1 << i); } qdpEncode_C1_GLOB(&pkt, &glob); if (!qdpPostCmd(q330->qdp, &pkt, TRUE)) { printf("Set Global Programming command failed\n"); return; } /* Retrieve the freshly installed values, and print them out */ if (!qdp_C1_RQSC(q330->qdp, sc)) return; if (!qdp_C1_RQGLOB(q330->qdp, &glob)) return; printf("\nUpdated "); qdpPrint_C1_SC(stdout, sc); printf("C1_GLOB SC bitmap = "); utilPrintBinUINT16(stdout, glob.sensor_map); printf("\n"); printf("Changes will not take effect until configuration is saved and the Q330 is rebooted.\n"); }
void create_windows() { /* Creazione finestre varie */ winA = newwin(WIN_GAME_HEIGH, WIN_GAME_WIDTH, WIN_PLAYER_A_START_Y, WIN_PLAYER_A_START_X); winB = newwin(WIN_GAME_HEIGH, WIN_GAME_WIDTH, WIN_PLAYER_B_START_Y, WIN_PLAYER_B_START_X); msg = newwin(WIN_MSG_HEIGH, WIN_MSG_WIDTH, WIN_MSG_START_Y, WIN_MSG_START_X); score = newwin(WIN_SCORE_HEIGH, WIN_SCORE_WIDTH, WIN_SCORE_START_Y, WIN_SCORE_START_X); log_win = newwin(WIN_LOG_HEIGH, WIN_LOG_WIDTH, WIN_LOG_START_Y, WIN_LOG_START_X); wrefresh(winA); wrefresh(winB); wrefresh(msg); wrefresh(score); wrefresh(log_win); winA_outline = newwin(WIN_GAME_OUTLINE_HEIGH, WIN_GAME_OUTLINE_WIDTH, WIN_PLAYER_A_OUTLINE_START_Y, WIN_PLAYER_A_OUTLINE_START_X); winB_outline = newwin(WIN_GAME_OUTLINE_HEIGH, WIN_GAME_OUTLINE_WIDTH, WIN_PLAYER_B_OUTLINE_START_Y, WIN_PLAYER_B_OUTLINE_START_X); msg_outline = newwin(WIN_MSG_OUTLINE_HEIGH, WIN_MSG_OUTLINE_WIDTH, WIN_MSG_OUTLINE_START_Y, WIN_MSG_OUTLINE_START_X); score_outline = newwin(WIN_SCORE_OUTLINE_HEIGH, WIN_SCORE_OUTLINE_WIDTH, WIN_SCORE_OUTLINE_START_Y, WIN_SCORE_OUTLINE_START_X); log_outline = newwin(WIN_LOG_OUTLINE_HEIGH, WIN_LOG_OUTLINE_WIDTH, WIN_LOG_OUTLINE_START_Y, WIN_LOG_OUTLINE_START_X); box(winA_outline,0,0); box(winB_outline,0,0); box(msg_outline,0,0); box(score_outline,0,0); box(log_outline,0,0); mvwprintw(winA_outline, 0, (WIN_GAME_OUTLINE_WIDTH)/2-strlen(player)/2-2, " %s ", player); mvwprintw(winB_outline,0 , (WIN_GAME_OUTLINE_WIDTH)/2-strlen(avversario)/2-1, " %s ", avversario); mvwprintw(score_outline,0 , (WIN_SCORE_OUTLINE_WIDTH)/2-strlen(SCORE_WIN_TITLE)/2-1, " %s ", SCORE_WIN_TITLE); mvwprintw(log_outline,0 , (WIN_LOG_OUTLINE_WIDTH)/2-strlen(LOG_WIN_TITLE)/2-1, " %s ", LOG_WIN_TITLE); mvwprintw(msg_outline,0 , (WIN_MSG_OUTLINE_WIDTH)/2-strlen(MSG_WIN_TITLE)/2-1, " %s ", MSG_WIN_TITLE); wrefresh(winA_outline); wrefresh(winB_outline); wrefresh(msg_outline); wrefresh(score_outline); wrefresh(log_outline); update_log(); updateA(); updateB(Y,X); }
void Bot::update(Game *game){ if(animatedSprite->isEnabled){ switch(type){ case typeA: updateA(); break; case typeB: updateB(); break; case typeC: updateC(); break; case typeD: updateD(game); break; case typeE: updateE(game); break; } } }
void SolverThread::dynamicsAssembly(float dt) { updateB(dt); float dt2 = dt*dt; unsigned totalPoints = m_mesh->numPoints(); float * mass = m_mesh->M(); Matrix33F * hostK = (Matrix33F *)m_hostK->data(); int i = 0; for(unsigned k=0;k<totalPoints;k++) { float m_i = mass[k]; MatrixMap tmp = m_K_row[k]; MatrixMap::iterator Kbegin = tmp.begin(); MatrixMap::iterator Kend = tmp.end(); for (MatrixMap::iterator K = Kbegin; K != Kend;++K) { unsigned j = K->first; Matrix33F K_ij = K->second; Matrix33F * A_ij = A(k,j); *A_ij = K_ij * dt2; if (k == j) { float c_i = mass_damping*m_i; float tmp = m_i + dt*c_i; *(*A_ij).m(0, 0) += tmp; *(*A_ij).m(1, 1) += tmp; *(*A_ij).m(2, 2) += tmp; } hostK[i] = *A_ij; i++; } } m_stiffnessMatrix->valueBuf()->hostToDevice(m_hostK->data()); }
int muovi_cursorse(int *y, int *x) { int ch; while ((ch=getch())) { switch(ch) { case KEY_LEFT: if (*x>0) (*x)--; break; case KEY_RIGHT: if (*x<X-1) (*x)++; break; case KEY_UP: if (*y>0) (*y)--; break; case KEY_DOWN: if (*y<Y-1) (*y)++; break; case 'c': if (remote[*y][*x]==0) { colpisci_casella(*y, *x, 0); return 1; } break; case 'g': if (numero_granate_giocatore>0) { if (lancia_granata(*y, *x)) { numero_granate_giocatore--; return 1; } } break; case 'q': if (conferma("Sicuro di voler terminare la partita ?")) exit_normal("Partita terminata per volere del'utente"); } updateB(*y, *x); } return 0; }
void collectdata(double *y, int* edgesrow, int *edgescol, double * edgesdist, int *relative, int d, int n, int ks, double *a, double *b, double *g) { double *diffy, *yij, *nid; double gij; int i, j, k; int nn_start, nn_end, nn; double *diffxjk, *diffyjk; double gjk, *yjk, *tempA; int relflg = *relative; /* clear data area */ memset(a, 0, sizeof(double)*d*d*d*d); memset(b, 0, sizeof(double)*d*d*n); memset(g, 0, sizeof(double)*n); /* temporary working space */ diffy = (double*)calloc(d, sizeof(double)); yij = (double*)calloc(d*d, sizeof(double)); tempA = (double*)calloc((d*d)*(d*d+1)/2, sizeof(double)); if(!diffy || !yij || !tempA) { mexErrMsgTxt("Out of memory..cannot allocate working space.."); return; } if(relflg==0) { for(i=0; i <n ; i++) { /* figure out the nearest neighbors */ nn_start = edgescol[i]; nn_end = edgescol[i+1]-1; if (nn_end > nn_start) { for(nn=nn_start; nn<=nn_end; nn++) { j = edgesrow[nn]; /* compute diffx and diffy */ /* vecsub(x+i*D, x+j*D, diffx, D);*/ gij = edgesdist[nn]; vecsub(y+i*d, y+j*d, diffy, d); vecout(diffy, yij, d); /* update A, b */ updateA(tempA, yij, 1.0,d*d); updateB(b+i*d*d, gij, yij, d*d); g[i] = g[i]+gij*gij; } } } } else { /* reproducing the code above to some degree so that we don't have to do if statement inside cache-intensive loop */ for(i=0; i <n ; i++) { /* figure out the nearest neighbors */ nn_start = edgescol[i]; nn_end = edgescol[i+1]-1; if (nn_end > nn_start) { for(nn=nn_start; nn<=nn_end; nn++) { j = edgesrow[nn]; gij=edgesdist[nn]; vecsub(y+i*d, y+j*d, diffy, d); vecout(diffy, yij, d); /* printf("diff: %f %f %f\n",yij[0],gij,edgesdist[nn]);*/ /* update A, b */ updateA(tempA, yij, 1.0/(gij*gij), d*d); updateB(b+i*d*d, 1/gij, yij, d*d); g[i] = g[i]+1; } } } } /* make A symmetric */ recoverA(d*d, a, tempA); }
void setUpBoard(Unit *u[NUM]) { Unit t; readMap(); bool gotNames = false; int i; int pnum; int minr, maxr, minc, maxc; for (i = 0; i < NUM; ++i)u[i] = 0; if (!AUTOTOURNEY) { for (i = 0; i < numplayers; ++i) { tryagain: cout << "tla" << i << ": "; cin >> tla[i]; if (tla[i] == "?") { printTlaList(); goto tryagain; } if (!checksOut(tla[i])) { cout << "That tla is not in the list.\n"; cout << "type '?' to see a full list.\n"; goto tryagain; } } } // make all the crowns for (i = 0; i < numplayers; ++i) { pnum = i % numplayers; minr = startBox[pnum].minr; maxr = startBox[pnum].maxr; minc = startBox[pnum].minc; maxc = startBox[pnum].maxc; u[i] = newUnit(tla[pnum], crown); t = *u[i]; u[i]->Place(minr, maxr, minc, maxc, makeSitRep(u, i)); checkPlacement(u[i], t, minr, maxr, minc, maxc); updateB(u[i]); } // make all the knights for (; i < (numplayers + NUMKNIGHTS); ++i) { pnum = i % numplayers; pnum = i % numplayers; minr = startBox[pnum].minr; maxr = startBox[pnum].maxr; minc = startBox[pnum].minc; maxc = startBox[pnum].maxc; u[i] = newUnit(tla[pnum], knight); t = *u[i]; u[i]->Place(minr, maxr, minc, maxc, makeSitRep(u, i)); checkPlacement(u[i], t, minr, maxr, minc, maxc); updateB(u[i]); } // make all the archers for (; i < (numplayers + NUMKNIGHTS + NUMARCHERS); ++i) { pnum = i % numplayers; minr = startBox[pnum].minr; maxr = startBox[pnum].maxr; minc = startBox[pnum].minc; maxc = startBox[pnum].maxc; u[i] = newUnit(tla[pnum], archer); t = *u[i]; u[i]->Place(minr, maxr, minc, maxc, makeSitRep(u, i)); checkPlacement(u[i], t, minr, maxr, minc, maxc); updateB(u[i]); } // make all the infantry for (; i < NUM; ++i) { pnum = i % numplayers; minr = startBox[pnum].minr; maxr = startBox[pnum].maxr; minc = startBox[pnum].minc; maxc = startBox[pnum].maxc; u[i] = newUnit(tla[pnum], infantry); t = *u[i]; u[i]->Place(minr, maxr, minc, maxc, makeSitRep(u, i)); checkPlacement(u[i], t, minr, maxr, minc, maxc); updateB(u[i]); } return; }