int main() { srand(time(NULL)); Stat stat; char name[50]; Snake snake; Pos food; ToGiveTread toGiveThread = {RIGHT, false, false}; showLeaderboard(); initStat(&stat); strcpy(name, stat.nickname); HANDLE hReadThread = CreateThread(NULL, 0, ReadThread, &toGiveThread, 0, NULL); strcpy(stat.nickname, name); initField(); initSnake(&snake); initFood(&snake, &food, &stat); updateAds(&stat); do{ Sleep(sleepTime(stat.level)); }while(!updateSnake(&snake, &food, &toGiveThread, &stat)); toGiveThread.toStopThread = true; clearScr(); updateScore(&stat); CloseHandle(hReadThread); showLeaderboard(); return 0; }
bool GameScene::init() { if( !Layer::init() ){ return false; } initField(); return true; }
void Matrix::init() { initRules(); initField(); initStats(); initTetrominoes(); initState(); initTimer(); }
bool Field::init() { if (!Layer::init()) { return false; } scheduleUpdate(); initField(); return true; }
void settingOtherPlayGround(WINDOW* thisWindow){ //wborder(thisWindow, 'I', 'I', '-', '-', '*', '*', '*', '*'); for (int i = 1; i < 23; i = i++){ for (int j = 1; j < 24; j = j + 2){ if (i == 0 || i == 23) mvwprintw(thisWindow, i, j, "□"); else mvwprintw(thisWindow, i, j, "□"); } } initField(); refreshField(thisWindow, 5, 5, 5); wrefresh(thisWindow); }
int main() { // INIT COMS cd = (Comm_data*) malloc(sizeof(Comm_data)); uart = init_clear_uart(cd); alt_timestamp_start(); srand(alt_timestamp()); CardCtrl *cardCtrl = (CardCtrl*)malloc(sizeof(CardCtrl)); PlayerCtrl* playerCtrl = (PlayerCtrl*)malloc(sizeof(PlayerCtrl)); initCards(cardCtrl); printf("Waiting for players\n"); while(connected_count < 3) { receivedFromAndroid(); } printf("Got all players\n"); initPlayers(playerCtrl, connected_count); int y; for (y = 0; y < connected_count; y++) { if (pid_connected[y] == 1) { tell_user_pid_role(y, playerCtrl->players[y]); Message message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); } } int i, j; for (i = 0; i < connected_count; i++) { drawCardsForId(i, cardCtrl, 2, playerCtrl); } field = malloc(sizeof(Field)); alt_up_char_buffer_dev *charBuffer = initCharBuffer(); alt_up_pixel_buffer_dma_dev *pixelBuffer = initPixelBuffer(); initField(field, playerCtrl, cardCtrl, charBuffer); *leds = *switches; alt_timestamp_start(); srand(alt_timestamp()); Message message; tell_user_all_opponent_range_role(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); tell_user_all_opponent_blue_lives(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); tell_user_their_turn(0); while (1){ int listening = 1; while (listening) { Message message = receivedFromAndroid(); switch (message.type) { case DRAW_CARDS: drawCardsForId(message.fromId, cardCtrl, message.count, playerCtrl); tell_user_ok(message.fromId); break; case UPDATE_HAND: updateHandForId(playerCtrl, message.fromId, message.count, message.cards); break; case UPDATE_BLUE: updateBlueCardsForId(playerCtrl, message.fromId, message.count, message.cards); tell_user_ok(message.fromId); break; case UPDATE_LIVES: updateLivesForId(playerCtrl, message.fromId, message.count); break; case GATLING: startGatling(playerCtrl, message.fromId); tell_user_ok(message.fromId); break; case ALIENS: startAliens(playerCtrl, message.fromId); tell_user_ok(message.fromId); break; case BEER: { //TODO //updateLivesForId(playerCtrl, message.fromId, message.count); Message message = receivedFromAndroid(); if (message.type == UPDATE_LIVES) updateLivesForId(playerCtrl, message.fromId, message.count); updateHand(message.fromId, playerCtrl); break; } case GENERAL_STORE: startStore(playerCtrl, message.fromId, cardCtrl); break; case SALOON: startSaloon(playerCtrl, message.fromId); tell_user_ok(message.fromId); break; case ZAP: { startZap(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; } case PANIC: startPanic(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; case CAT_BALOU: startCatBalou(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; case DUEL: startDuel(playerCtrl, message.toId, message.fromId, message.self); if (message.self == 0) { tell_user_ok(message.fromId); } break; case JAIL: //TODO tell_user_jail(message.toId, message.cards); break; case END_TURN: listening = 0; break; default: break; } alt_up_char_buffer_clear(charBuffer); runField(field, isGameEnd, winningPlayer); } endTurn(playerCtrl); tell_user_all_opponent_range_role(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); tell_user_all_opponent_blue_lives(playerCtrl->turn, getPlayersInfoForId(playerCtrl, playerCtrl->turn)); message = receivedFromAndroid(); if (message.type == ACKNOWLEDGE); int y; for (y = 0; y < MAX_CARDS; y++ ) { if (playerCtrl->players[playerCtrl->turn].blueCards[y] >= 72 && playerCtrl->players[playerCtrl->turn].blueCards[y] <= 74) { drawCardsForId(playerCtrl->turn, cardCtrl, 1, playerCtrl); break; } } tell_user_their_turn(playerCtrl->turn); alt_up_char_buffer_clear(charBuffer); runField(field, isGameEnd, winningPlayer); } return 0; }
void Communicator::makeInitField() { InitFieldPacket initField(buffer); }
void TableInfo::setDefined(RecordType &rec, UINT n, bool defined) const { rec.m_data[getIndicatorOffset(n)] = defined ? INDICATOR_DEFINED : INDICATOR_UNDEFINED; if(!defined) { initField(rec,n); } }
Glass::Glass(const math::Rect& r, float brickSize) : m_brickSize(brickSize), m_rect(r) { loadTextures(); initField((uint)(r.w/brickSize), (uint)(r.h/brickSize)); }
int main(int argc, char **argv) { struct timespec start, finish; start_time if (argc<8) { printf("Usage: %s x y iteration INCREMENT_TIME, INCREMENT threads EPSILON\n", argv[0]); } sscanf(argv[1], "%d", &x); sscanf(argv[2], "%d", &y); sscanf(argv[3], "%d", &iteration); sscanf(argv[4], "%d", &INCREMENT_TIME); sscanf(argv[5], "%lf", &INCREMENT); sscanf(argv[6], "%d", &threads); sscanf(argv[7], "%lf", &EPSILON); omp_set_num_threads(threads); field = malloc(sizeof(TemperatureField)); tempField = malloc(sizeof(TemperatureField)); field->x = y; field->y = x; #ifdef DISPLAY XWindow_Init(field); #endif int iter, inc; int *X_Size = malloc(sizeof(int)*INCREMENT_TIME); int *Y_Size = malloc(sizeof(int)*INCREMENT_TIME); X_Size[INCREMENT_TIME-1] = x; Y_Size[INCREMENT_TIME-1] = y; for (inc=INCREMENT_TIME-2; inc>=0; --inc) { X_Size[inc] = X_Size[inc+1] / INCREMENT; Y_Size[inc] = Y_Size[inc+1] / INCREMENT; } for (inc=0; inc<INCREMENT_TIME; ++inc) { if (!inc) { newField(field, X_Size[inc], Y_Size[inc], 0, 0); newField(tempField, X_Size[inc], Y_Size[inc], 0, 0); initField(field); } else { newField(field, X_Size[inc], Y_Size[inc], X_Size[inc-1], Y_Size[inc-1]); newField(tempField, X_Size[inc], Y_Size[inc], X_Size[inc-1], Y_Size[inc-1]); } #ifdef DISPLAY XResize(field); #endif for (iter=0; iter<iteration; iter++) { double error = temperature_iterate(field); if (error<EPSILON) { printf("Finished. iteration=%d, error=%lf\n", iter, error); break; } swapField = field; field = tempField; tempField = swapField; #ifdef DISPLAY end_time if (time_elapsed_ns > FRAME_INTERVAL*1000000) { start_time; XRedraw(field); } // puts("Field:"); // int i, j; // for (i=0; i<field->x; ++i) // { // for (j=0; j<field->y; ++j) // printf("%lf ", field->t[i][j]); // puts(""); // } #endif } } deleteField(field); deleteField(tempField); free(X_Size); free(Y_Size); printf("Finished in %d iterations.\n", iter_cnt); end_time; printf("%lf\n", time_elapsed_s); return 0; }
/* function initField : Initialize the field GF2E with irreducible polynomial. This function is used by the simulator, while the verifier does the same thing. The verifier' field is different from the simulator's field but the fields are isomorphics so the calculations are correct. * param t : degree of the irreducible polynomial * param randomNum : seed for the random calculations. */ JNIEXPORT void JNICALL Java_edu_biu_scapi_interactiveMidProtocols_sigmaProtocol_orMultiple_SigmaORMultipleSimulator_initField (JNIEnv *env, jobject, jint t, jint randomNum){ //call the function that does the initialization. initField(t, randomNum); }
int main(void) { while (1) { state = 0; int setTime = 15; numPlayers = 2; initScreen(); clearScreen(); initCharBuffer(); clean_up(); initKeyboard(); initState0(); initAI(); //Bypass the menu system for testing if (IORD(keys,0) == 8) { initPlayer(pOne, MARIO, "pOne", 50, 100, HUMAN); initPlayer(pTwo, LUIGI, "pTwo", 50, 100, COMPUTER); state = 2; } else { while (state == 0) { decode_scancode(ps2, &decode_mode, buf, &ascii); state_0(decode_mode, buf[0]); }; initState1(pOne); if(aOn)file_handle = initAudio(fname); if(aOn)alt_irq_register(AUDIO_0_IRQ, &ab, (alt_isr_func) write_fifo); if(aOn) alt_up_audio_enable_write_interrupt(ab->audio); while (state == 1) { decode_scancode(ps2, &decode_mode, buf, &ascii); state_1(decode_mode, buf[0], ascii); if(aOn)loop_audio(file_handle, fname, ab); }; } //clean_up(); clearCharBuffer(); clearScreen(); //enable keyboard IRQ void* keyboard_control_register_ptr = (void*) (KEYBOARD_BASE + 4); alt_irq_register(KEYBOARD_IRQ, keyboard_control_register_ptr, keyboard_ISR); alt_up_ps2_enable_read_interrupt(ps2); //Draw field and UI to both buffers initField(); updateField(); drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name); drawGas(p[pOne].gas); drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp); drawBullet(p[pOne].bulletType); //drawWindIndicator(1); updateScreen(); updateField(); drawName(p[pOne].name, p[pTwo].name, p[pThree].name, p[pFour].name); drawGas(p[pOne].gas); drawHealth(p[pOne].hp, p[pTwo].hp, p[pThree].hp, p[pFour].hp); drawBullet(p[pOne].bulletType); //drawWindIndicator(1); float time; alt_timestamp_start(); int start_timer_flag = 1; //printf("NUM PLAYERA %i\n", numPlayers); int i; while (state == 2) { int fallFlag = 1; //Checks to see if any players are falling while (fallFlag == 1) { fallFlag = 0; for (i = 0; i < numPlayers; i++) { if (p[i].alive) { if (p[i].y + TANK_HEIGHT >= SCREEN_HEIGHT-1) { p[i].hp = 0; p[i].alive = DEAD; } checkPlayerFalling(i); if (p[i].isFalling) { undrawPlayer(i); updatePlayer(i); fallFlag = 1; } } } if (fallFlag == 1) { updateScreen(); } } if(start_timer_flag){ start_time = (float) alt_timestamp() / (float) alt_timestamp_freq(); start_timer_flag = 0; } time = (float) alt_timestamp() / (float) alt_timestamp_freq()-start_time; if (time >= setTime) { setPlayerTurn(); } if (p[turn].type == HUMAN) { runGame(); } else { p[turn].deg = 0; aiMain(turn); setPlayerTurn(); } printTimer(setTime - time); int deadCount = 0; for (i = 0; i < numPlayers; i++) { if (p[i].alive == DEAD) deadCount++; } if (deadCount == numPlayers - 1) { usleep(500000); state = 3; } } alt_up_ps2_disable_read_interrupt(ps2); if(aOn)alt_up_audio_disable_write_interrupt(ab->audio); GameOverScreen(); } }