void nextMove(char player, char board[3][3]){ int iboard[25]; int i,j,move; pair best; initializeBoard(iboard, board); US = player; THEM = otherPlayer(US); timesCalled=0; //printboard(iboard); best = chooseMoveAB(iboard,player,INT_MIN,INT_MAX); convert1dTo2d(best.move); printf("chooseMoveAB timesCalled: %d bestMove:%d\n", timesCalled,best.move); timesCalled=0; //printboard(iboard); best = chooseMove(iboard,player); convert1dTo2d(best.move); printf("chooseMove timesCalled: %d bestMove:%d\n", timesCalled,best.move); timesCalled=0; //printboard(iboard); best = chooseMoveEvaluate(iboard,player); convert1dTo2d(best.move); printf("chooseMoveEvaluate timesCalled: %d bestMove:%d\n", timesCalled,best.move); timesCalled=0; //printboard(iboard); best = chooseMoveABDepth(iboard,player,INT_MIN,INT_MAX); convert1dTo2d(best.move); printf("chooseMoveAB timesCalled: %d bestMove:%d\n", timesCalled,best.move); }
void GameManager::endTurn() { if (myTurnCounter < 6) { myTurnCounter++; initializeBoard(); if (myCurrentClient < myNumberOfClients - 1) { myCurrentClient++; } else { myCurrentClient = 0; } return; } for (Order* order : myOrderQueue) { cout << "Order " << order->getName() << endl; } /*Sends order queue*/ server->handleQueue(myOrderQueue); this->clear(); /*Changes possesion*/ if (myCurrentClient < myNumberOfClients-1) { myCurrentClient ++; } else { myCurrentClient = 0; } myTurnCounter++; }
int main(int argc, char** argv){ initializeBoard(); initializeUSB1208(); int k=0,i=1,nSamples=16; float angle; float* measurement=calloc(sizeof(float),nSamples); float* involts=calloc(sizeof(float),NUMCHANNELS); printf(" VERT VERTsd | HORIZ HORIZsd | REF REFsd | Approx Angle\n"); for(k=1;k<NUMCHANNELS+1;k++){ for (i=0;i<nSamples;i++){ getUSB1208AnalogIn(k,&measurement[i]); involts[k-1]=involts[k-1]+measurement[i]; delay(10); } involts[k-1]=fabs(involts[k-1])/(float)nSamples; printf(" %0.4f %0.4f ",involts[k-1],stdDeviation(measurement,nSamples)); if(k<NUMCHANNELS) printf(" | "); } printf("\t"); angle=atan(sqrt(involts[0]/involts[1])); printf("%0.3f",angle); printf("\n"); return 0; }
void fillBoard(){ initializeBoard(); for(int index=0;index<INDEX_MAX;index++){ Coord coord=coords[index]; int resource=getResource(coord); set(coord.row,coord.col,resource); resourceCount[resource]++; } }
void initializeAll(char grid[8][8][33], char status[33], char pieceTranslator[33], char gameVariables[21]) { initializeLegal(grid); initializeStatus(status); initializePieces(pieceTranslator); initializeBoard(grid); Initialize_Chess_Play(); return; }
main() { // 0 if no mine, 1 if mine int gameOver = 0, winGame = 0; int i, j; char x[1],y[1]; int row,col; for(i = 0; i < SIZE ; i ++){ for(j = 0; j < SIZE ; j ++){ boardState[i][j] = 0; boardActivated[i][j] = 0; } } initializeBoard(); /**********************************/ while(1){ printf("Choose index of the tile [row]<space>[col]:"); fgets(x,2,stdin); row = x[0] - '0'; getchar(); fgets(y,2,stdin); col = y[0] - '0'; getchar(); boardActivated[row][col] = 1; printBoard(); if(boardState[row][col] == 100){ gameOver = 1; break; } // else checkNeighbors(x,y); if (isGoal(boardState, boardActivated)== 100){ winGame = 1; break; } } if(winGame){ printf("You win the game!\n"); } else if(gameOver){ printf("BOOOM! \n"); } }
// Creates a new game and intialises the game board // and player resources Game newGame (int discipline[], int dice[]) { // sets memory aside for the game Game g = malloc (sizeof(game)); //Makes region makeRegion(g, discipline); // initialise turn to -1 g->currentTurn = -1; // initialise game board int regionID; regionID = 0; while (regionID < NUM_REGIONS) { g->regionDiscipline[regionID] = discipline[regionID]; g->regionDice[regionID] = dice[regionID]; regionID++; } // initialise prestige awards g->mostArcs = NO_ONE; g->mostPubs = NO_ONE; // initialise players // 1<=player<=3 but array is from 0 to 2 so minus 1 to rectify int curPlayer = UNI_A; while (curPlayer < NO_PLAYERS) { // initialises a player's students resources g->uni[curPlayer].numStudents[STUDENT_THD] = INITIAL_THD; g->uni[curPlayer].numStudents[STUDENT_BPS] = INITIAL_BPS; g->uni[curPlayer].numStudents[STUDENT_BQN] = INITIAL_BQN; g->uni[curPlayer].numStudents[STUDENT_MJ] = INITIAL_MJ; g->uni[curPlayer].numStudents[STUDENT_MTV] = INITIAL_MTV; g->uni[curPlayer].numStudents[STUDENT_MMONEY] = INITIAL_MMONEY; // initialises a player's resources and points g->uni[curPlayer].numArcs = 0; g->uni[curPlayer].numCmps = 2; g->uni[curPlayer].numG08s = 0; g->uni[curPlayer].numPubs = 0; g->uni[curPlayer].numIPs = 0; curPlayer++; } //Initialize the gameboard: initializeBoard(g); return g; }
void msw_init(int MODE) { int err = 0; unsigned long l_Tid; unsigned long l_RetCode; unsigned long l_TaskArgs[4]; err = AMSW_Modem_SW_Init(0,0,1,0,XPRIO_EVENT_HDLR,XPRIO_CRITICAL_APPL); if (err) { PRINT_INFO("AMSW_Modem_SW_Init() error\n"); return; } err = initializeBoard(); if (err) { PRINT_INFO("initializeBoard() error\n"); return; } err = amu_init_modem(MODE); if (err) { PRINT_INFO("amu_init_modem error\n"); return; } l_RetCode = xq_create((char *)"AMUQ", 0, 0, &l_TaskArgs[0]); if (l_RetCode != 0) { PRINT_INFO("***** AMU Queue creation error *****\n"); return; } g_AMUQid = l_TaskArgs[0]; // create the AMU task l_RetCode = xt_create((char *)"AMU0", 2, 1024, 0, 0, &l_Tid); if (l_RetCode != 0) { PRINT_INFO("***** AMU task creation error *****\n"); return; } // start the AMU Task amu_go = TRUE; l_RetCode = xt_start(l_Tid, 0, AMUTask, l_TaskArgs); if (l_RetCode != 0) { PRINT_INFO("***** AMU task start error *****\n"); return; } }
int main(void) { initializeBoard(); CoInitOS(); //CoCreateTask(USART_rx,0,0,&USART1_stk[STACK_SIZE_DEFAULT-1],STACK_SIZE_DEFAULT); CoCreateTask(blinkLED,0,0,&blinkLED_stk[STACK_SIZE_DEFAULT-1],STACK_SIZE_DEFAULT); CoCreateTask(btPRESS,0,1,&btPRESS_stk[STACK_SIZE_DEFAULT-1],STACK_SIZE_DEFAULT); //CoCreateTask(GPIO_LCD1602,0,0,&updateLCD_stk[STACK_SIZE_DEFAULT-1],STACK_SIZE_DEFAULT); CoStartOS(); while(1); }
int main(int argc, char** argv){ float desiredDetuning; int laserSock; initializeBoard(); laserSock=initializeLaser(); if(argc==2){ desiredDetuning=atof(argv[1]); printf("Detuning: %2.2f\n",desiredDetuning); }else{ printf("Usage: ./setPumpDetuning <detuning in GHz>\n"); return 1; } setPumpDetuning(laserSock,desiredDetuning); return 0; }
// ------------------------------------------------------------------------ // main( ) - Main program creates task0 and then starts CoOS kernel. // // ------------------------------------------------------------------------ int main(void) { // initialize the LPCXpresso board by: // turning on clock signal for the GPIO peripheral. // setting GPIO port 0, bit22 for output (to drive LED2) initializeBoard(); // initialize the CoOS real time kernel CoInitOS(); // create task1 CoCreateTask(task1,0,0,&task1_stk[STACK_SIZE_DEFAULT-1],STACK_SIZE_DEFAULT); // start the CoOS real time kernel CoStartOS(); // you should never get here! while(1); }
int main() { srand(time(NULL)); clock_t start = clock(); int x1,y1,x2,y2,counter=0; int i,record=0; char tryagain='y';//for restart menu char **board;//for create a board board=(char **)malloc(7*sizeof(char*)); for(i=0;i<7;i++) board[i]=(char*)malloc(7*sizeof(char*)); while(tryagain=='y') { int total_point=0; initializeBoard(board); while(checkclock(start)) { while(getCandiesCoordinates(&x1,&y1,&x2,&y2)); if(checkCandies(&x1,&y1,&x2,&y2,board,&counter)) { crushCandies(&x1,&y1,&x2,&y2,board); total_point=total_point+calculatePoints(&counter); printf("Your total points is %d!\n",total_point); display_board(board); } } fflush(stdin); printf("\ntime is up\n"); if(total_point>record)record=total_point; printf("Record is %d\n",record); printf("Do you want to play again (y/n) :"); scanf("%c",&tryagain); start = clock(); } printf("\nGood Bye\n"); system("pause"); return 0; }
int main (void) { uint32_t n; MscDevInfo.idVendor = USB_VENDOR_ID; MscDevInfo.idProduct = USB_PROD_ID; MscDevInfo.bcdDevice = USB_DEVICE; MscDevInfo.StrDescPtr = (uint32_t)&USB_StringDescriptor[0]; MscDevInfo.MSCInquiryStr = (uint32_t)&InquiryStr[0]; MscDevInfo.BlockSize = MSC_BlockSize; MscDevInfo.BlockCount = MSC_BlockCount; MscDevInfo.MemorySize = MSC_MemorySize; MscDevInfo.MSC_Read = MSC_MemoryRead; MscDevInfo.MSC_Write = MSC_MemoryWrite; DeviceInfo.DevType = USB_DEVICE_CLASS_STORAGE; DeviceInfo.DevDetailPtr = (uint32_t)&MscDevInfo; /* Enable Timer32_1 and IOCON blocks */ LPC_SYSCON->SYSAHBCLKCTRL |= (EN_TIMER32_1 | EN_IOCON | EN_USBREG); initializeBoard(); SPI_Config(); (*rom)->pUSBD->init_clk_pins(); /* Use pll and pin init function in rom */ /* insert a delay between clk init and usb init */ for (n = 0; n < 75; n++) { } (*rom)->pUSBD->init(&DeviceInfo); /* USB Initialization */ init_msdstate(); /* Initialize Storage state machine */ (*rom)->pUSBD->connect(TRUE); /* USB Connect */ while (1); /* Loop forever */ }
int main(int argc, char *argv[]) { arr = (int*)calloc(arrSIZE, sizeof(int)); draws = (int*)calloc(2, sizeof(int)); time_t t; srand((unsigned) time(&t)); shmidArray = sharedMemoArr(arrSIZE, 'S'); shmidDraws = sharedMemoDraws(2, 'T'); shmidFlag = sharedMemoFlag('R'); shmidOutPlayer1 = sharedMemoOutPlayer1(2, 'K'); shmidOutPlayer2 = sharedMemoOutPlayer2(2, 'E'); // freeSharedMemo(); initializeBoard(arr);//Initialize board with players 1 and 2. printArray(arr, arrSIZE); createSons(); freeSharedMemo(); return 0; }
int startTheGame() { char choice[3], ch; int index, easyIndex, hardIndex; int position; int isFirstTurn; int i, j; int isWin; int playerEasyWinScore = 0; int playerEasyLostScore = 0; int playerEasyTieScore = 0; int playerHardWinScore = 0; int playerHardLostScore = 0; int playerHardTieScore = 0; int gameplay; // 0 - Easy gameplay, 1 - Hard gameplay int isSavedEasy, isSavedHard; char easy[3][3], hard[3][3]; FILE *userFile = fopen(FILEPATH, "r"); if(userFile == NULL) { createUserDataFile(); userFile = fopen(FILEPATH, "r"); } fscanf(userFile, "%d", &gameplay); fscanf(userFile, "%d %d %d", &playerEasyWinScore, &playerEasyLostScore, &playerEasyTieScore); fscanf(userFile, "%d %d %d", &playerHardWinScore, &playerHardLostScore, &playerHardTieScore); fscanf(userFile, "%d %d", &isSavedEasy, &isSavedHard); // Check for any saved game if(isSavedEasy) { fscanf(userFile, "%d", &easyIndex); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { ch = getc(userFile); if(ch != '\n') easy[i][j] = ch; ch = getc(userFile); if(ch != '\n') easy[i][j] = ch; } } } if(isSavedHard) { fscanf(userFile, "%d", &hardIndex); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) { ch = getc(userFile); if(ch != '\n') hard[i][j] = ch; ch = getc(userFile); if(ch != '\n') hard[i][j] = ch; } } } fclose(userFile); if( (gameplay && isSavedHard) || (!gameplay && isSavedEasy) ) { system("cls"); printf("You have a saved game.\n"); printf("1. Continue\n"); printf("2. New Game\n"); printf("New Game will overwrite the saved game of current gameplay.\n"); printf("Enter your choice:(Default - Continue) "); fgets(choice, sizeof(choice), stdin); if(gameplay) { isSavedHard = 0; userFile = fopen(FILEPATH, "r+"); fprintf(userFile, "%d\n", gameplay); fprintf(userFile, "%d %d %d\n", playerEasyWinScore, playerEasyLostScore, playerEasyTieScore); fprintf(userFile, "%d %d %d\n", playerHardWinScore, playerHardLostScore, playerHardTieScore); fprintf(userFile, "%d %d\n", isSavedEasy, isSavedHard); if(isSavedEasy) { fprintf(userFile, "%d\n", easyIndex); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n", easy[i][j]); } fclose(userFile); } else { isSavedEasy = 0; userFile = fopen(FILEPATH, "r+"); fprintf(userFile, "%d\n", gameplay); fprintf(userFile, "%d %d %d\n", playerEasyWinScore, playerEasyLostScore, playerEasyTieScore); fprintf(userFile, "%d %d %d\n", playerHardWinScore, playerHardLostScore, playerHardTieScore); fprintf(userFile, "%d %d\n", isSavedEasy, isSavedHard); if(isSavedHard) { fprintf(userFile, "%d\n", hardIndex); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n", hard[i][j]); } fclose(userFile); } if( (atoi(choice)) == 2) { initializeBoard(); index = 0; } else { if(gameplay && isSavedHard) { index = hardIndex; for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) base[i][j] = hard[i][j]; } else { index = easyIndex; for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) base[i][j] = easy[i][j]; } } } else { initializeBoard(); index = 0; } // Start the game for(isFirstTurn = 1; index < 9; index++) { if(index % 2 == 0) { while(1) { system("cls"); displayTheBoard(); if (!isFirstTurn) { printf("AI move: %d\n", position); } else { isFirstTurn = 0; } printf("Enter the position at which you want to put X: (0: Menu) "); fgets(choice, sizeof(choice), stdin); position = atoi(choice); switch(position) { case 0: system("cls"); printf("\nDo you want to save and quit? (Default - Resume)\n"); printf("1. Resume\n2. Save and Quit\n3. Quit without saving\n\n"); printf("Enter your choice: "); fgets(choice, sizeof(choice), stdin); switch(atoi(choice)) { case 1: continue; break; case 2: if(gameplay) isSavedHard = 1; else isSavedEasy = 1; userFile = fopen(FILEPATH, "r+"); fprintf(userFile, "%d\n", gameplay); fprintf(userFile, "%d %d %d\n", playerEasyWinScore, playerEasyLostScore, playerEasyTieScore); fprintf(userFile, "%d %d %d\n", playerHardWinScore, playerHardLostScore, playerHardTieScore); fprintf(userFile, "%d %d\n", isSavedEasy, isSavedHard); if(gameplay) { if(isSavedEasy == 1) { fprintf(userFile, "%d\n", easyIndex); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n",easy[i][j]); } fprintf(userFile, "%d\n", index); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n",base[i][j]); } else { fprintf(userFile, "%d\n", index); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n",base[i][j]); if(isSavedHard == 1) { fprintf(userFile, "%d\n", hardIndex); for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) fprintf(userFile, "%c\n",hard[i][j]); } } fclose(userFile); return(0); break; case 3: return(0); break; default: continue; } break; case 1: //Fall through case 2: //Fall through case 3: //Fall through case 4: //Fall through case 5: //Fall through case 6: //Fall through case 7: //Fall through case 8: //Fall through case 9: if(checkThePlace(position)) break; else { printf("\nERROR:Position is not available.\n"); printf("Try again.\n\n"); system("pause"); continue; } break; default: printf("\nERROR:Position is not valid.\n"); printf("Try again.\n\n"); system("pause"); continue; } break; } playerMove(position, 'X'); // User's move } else { position = getThePosition(); playerMove(position, 'O'); // AI's move } system("cls"); displayTheBoard(); isWin = winCheck(); // Check the win conditions if(isWin) { if(index % 2 == 0) // User wins { printf(" == You won ==\n\n"); if(gameplay) playerHardWinScore++; else playerEasyWinScore++; } else // AI wins { printf(" = You lost! =\n\n"); if(gameplay) playerHardLostScore++; else playerEasyLostScore++; } break; } } if(!isWin) { printf(" ==== TIE ====\n\n"); if(gameplay) playerHardTieScore++; else playerEasyTieScore++; } userFile = fopen(FILEPATH, "r+"); fprintf(userFile, "%d\n", gameplay); fprintf(userFile, "%d %d %d\n", playerEasyWinScore, playerEasyLostScore, playerEasyTieScore); fprintf(userFile, "%d %d %d\n", playerHardWinScore, playerHardLostScore, playerHardTieScore); fclose(userFile); printf("\nEnter 1 to retry, or press any other key to go to Main Menu: "); fgets(choice, sizeof(choice), stdin); if(atoi(choice) == 1) startTheGame(); return(0); }
int main(int argc, char **argv){ #ifdef DEBUG DEBUG_FILE = fopen("debug.txt", "w"); #endif initscr(); keypad(stdscr, TRUE); noecho(); clear(); start_color(); init_pair(COL_BLUE, COLOR_BLUE, COLOR_BLACK); init_pair(COL_YELLOW, COLOR_YELLOW, COLOR_BLACK); init_pair(COL_RED, COLOR_RED, COLOR_BLACK); init_pair(COL_WHITE, COLOR_WHITE, COLOR_BLACK); init_pair(COL_GREEN, COLOR_GREEN, COLOR_BLACK); init_pair(COL_CYAN, COLOR_CYAN, COLOR_BLACK); WINDOWMAX_Y = getmaxy(stdscr); WINDOWMAX_X = getmaxx(stdscr); INPUTMODE = INM_NORMAL; dprintf("Window size is %ix%i\n", WINDOWMAX_X, WINDOWMAX_Y); USECOLOR = 1; GCRUNFREQ = 50; CONSIZE = WINDOWMAX_Y - CHUNKSIZE - 5; const char *PATTERN = NULL; const char *BOARDNAME = NULL; int getoptval; while((getoptval = getopt(argc, argv, "cg:p:n:s:")) != -1){ switch(getoptval) { //Disable color case 'c': USECOLOR = 0; break; case 'p': PATTERN = optarg; break; case 'n': BOARDNAME = optarg; break; case 'g': GCRUNFREQ = atoi(optarg); break; case 's': CONSIZE = atoi(optarg); break; } } CONSIZE = clamp(CONSIZE, 5, 15); consoleBuffer = calloc(CONSIZE * GSTRINGSIZE, 1); cprintf("Welcome to the game of life! Press space/zxc to begin!"); cprintf("Use arrows/wasd to move. Press q to quit."); struct board *b; if(PATTERN){ b = readNewBoard(PATTERN); if(BOARDNAME){ setBoardName(b, BOARDNAME); } }else{ b = createBoard(BOARDNAME); initializeBoard(b); } //START TESTS /*#define on(x, y) curChunk(b)->board[at(x, y)] = 1*/ /*on(1, 1);*/ /*on(2, 2);*/ /*on(3, 2);*/ /*on(2, 3);*/ /*on(3, 1);*/ /*goto CLEANUP;*/ //END TESTS while(1){ erase(); drawBoard(b); inputRenderer(); consoleRenderer(); refresh(); if(!input(b)) goto CLEANUP; } CLEANUP: #ifdef DEBUG fclose(DEBUG_FILE); #endif free(consoleBuffer); freeBoard(b); endwin(); printf("Program complete"); return 0; }
int main (int argc, char* argv[]){ int i,k; float myTemp,myVolts; unsigned int periods, valueADC; initializeBoard(); /* setRS485ServoPosition(SERVO1, 0, 0); printf("Sending IFC to GPIB instruments on bridge %02x\n",GPIBBRIDGE1); i=resetGPIBBridge(GPIBBRIDGE1); printf("Status %d\n",i); delay(200); i=initializeK485(K485AMMETER,GPIBBRIDGE1); printf("Init K485\nStatus %d\n",i); i=initializeF8840(FLUKE8840,GPIBBRIDGE1); printf("Init Fluke 8840\nStatus %d\n",i); i=initSorensen120(SORENSEN120,GPIBBRIDGE1); printf("Init Sorensen\nStatus %d\n",i); i=initializeBK1696(RS232BRIDGE1); printf("Init BK1696 instrument #1\nStatus %d\n",i); i=getPVCN7500(OMEGA1,&myTemp); if (!i) printf("Omega 1 temperature = %.1f°\n",myTemp); else printf("Status %d\n",i); i=getPVCN7500(OMEGA2,&myTemp); if (!i) printf("Omega 2 temperature = %.1f°\n",myTemp); else printf("Status %d\n",i); i = getRS485AnalogRecorderPeriod(ANALOGRECORD, &periods); printf("Analog recorder sampling every %dmS\n",periods*16); for (k=0; k<4; k++){ i=readRS485AnalogRecorder(ANALOGRECORD, k, 5.0, &myVolts, &myTemp); delay(100); printf("Analog recorder chan %d = %.2f ± %.2f\n",k,myVolts, myTemp); } i=getReadingK485(&myTemp, K485AMMETER,GPIBBRIDGE1); if (!i) printf("K485 reading = %E\n",myTemp);else printf("Status %d\n",i); delay(100); i=getReadingF8840(&myTemp, FLUKE8840,GPIBBRIDGE1); if (!i) printf("Fluke 8840 reading = %E\n",myTemp);else printf("Status %d\n",i); for (k=0;k<8;k++){ i=setVoltsBK1696(RS232BRIDGE1, (float) k * 1.2+1.1); delay(100); printf("Set Servo %d\t",k); setRS485ServoPosition(SERVO1, 0, k); getRS485ServoPosition(SERVO1,0,&i); printf("Return pos %d\n",i); delay (100); i=getReadingF8840(&myTemp, FLUKE8840,GPIBBRIDGE1); if (!i) printf("Fluke = %E\t",myTemp); else printf("Status %d\n",i); delay (100); i=getReadingF8840(&myTemp, FLUKE8840,GPIBBRIDGE1); if (!i) printf("Fluke = %E\n",myTemp);else printf("Status %d\n",i); } for (k=0; k<10; k++){ myTemp = (float)k * 12.2; i = setSorensen120Volts(myTemp,SORENSEN120,GPIBBRIDGE1); printf("Setting Sorensen %.1f\t",myTemp); delay(200); i = getSorensen120Volts(&myVolts,SORENSEN120,GPIBBRIDGE1); i = getSorensen120Amps(&myTemp,SORENSEN120,GPIBBRIDGE1); printf("Measured: %.2fV\t %.3fA\t %.1fW\n",myVolts,myTemp,myVolts*myTemp); delay(200); } i = setSorensen120Volts(0.0,SORENSEN120,GPIBBRIDGE1); setRS485ServoPosition(SERVO1, 0, 0); */ for (i=0;i<8;i++){ getADC(i,&valueADC); printf("ADC: %d\t",valueADC); delay(100); } return 0 ; }
ChessBoard::ChessBoard() { initializeBoard(); }
int main(int argc, const char * argv[]) { //Interaction with the user (From the driver) Use the FILE pointer? //hasTurn is 1 when it is player 1, and 2 when it is player two int hasTurn = 1; int play = 1; int column, row; char board[3][3]; initializeBoard(board); while (play == 1) { while (hasTurn == 1) { printBoard(board); printf("Player 1 - Choose column 0 - 2 :\n"); scanf("%d", &column); printf("Player 1 - Choose row 0 - 2 :\n"); scanf("%d", &row); //Check if the column and row is allowed //Should be in a method if(moveAllowed(board, &column, &row) == 1) board[column][row] = 'X'; else printf("Column or row not valid - try again.\n"); //Check if player 1 won if (hasWon(board,hasTurn) == 1){ printf("%s", "Player 1 won!"); play = 0; } else hasTurn = 2; } //Do the same for player two - is there a way to do this without the loops? while (hasTurn == 2) { printBoard(board); printf("Player 2 - Choose column 0 - 2 :\n"); scanf("%d", &column); printf("Player 2 - Choose row 0 - 2 :\n"); scanf("%d", &row); //Check if the column and row is allowed if(moveAllowed(board, &column, &row) == 1) board[column][row] = '0'; else printf("Column or row not valid - try again.\n"); //Check if player 2 has won if (hasWon(board,hasTurn) == 1){ printf("%s", "Player 1 won!"); play = 0; } else hasTurn = 1; } } return 0; }
void TicTacToeGame::restartGame() { initializeBoard(); }
int main (int argc, char **argv) { int i; int upOrDown; int revolutions,dataPointsPerRevolution; time_t rawtime; float returnFloat; //float probeOffset,mag1Voltage,mag2Voltage; struct tm * timeinfo; char fileName[BUFSIZE], comments[BUFSIZE]; char dailyFileName[BUFSIZE]; char dataCollectionFileName[] = "/home/pi/.takingData"; FILE *fp,*dataCollectionFlagFile,*configFile; float angle=-99; float desiredAngle,tempChange; if (argc==4){ upOrDown=atof(argv[1]); desiredAngle=atof(argv[2]); strcpy(comments,argv[3]); } else { printf("usage '~$ sudo ./stepTemperatureWaitForRotationAngle <up or down (0 down, 1 up)> <desired Angle> <comments in quotes>'\n"); printf(" Don't forget to edit the config file! \n"); return 1; } // Indicate that data is being collected. dataCollectionFlagFile=fopen(dataCollectionFileName,"w"); if (!dataCollectionFlagFile) { printf("unable to open file:\t%s\n",dataCollectionFileName); exit(1); } revolutions=1; dataPointsPerRevolution=(int)STEPSPERREV/STEPSIZE; // Set up interfacing devices initializeBoard(); initializeUSB1208(); if(upOrDown==0){ tempChange=-.1; }else{ tempChange=.1; } do{ getPVCN7500(CN_RESERVE,&returnFloat); setSVCN7500(CN_RESERVE,returnFloat+tempChange); delay(1800000); //delay(180); configFile=fopen("/home/pi/RbControl/system.cfg","r"); if (!configFile) { printf("Unable to open config file\n"); exit(1); } // Get file name. Use format "FDayScan"+$DATE+$TIME+".dat" time(&rawtime); timeinfo=localtime(&rawtime); struct stat st = {0}; strftime(fileName,BUFSIZE,"/home/pi/RbData/%F",timeinfo); //INCLUDE if (stat(fileName, &st) == -1){ mkdir(fileName,S_IRWXU | S_IRWXG | S_IRWXO ); } strftime(fileName,BUFSIZE,"/home/pi/RbData/%F/FDayRotation%F_%H%M%S.dat",timeinfo); //INCLUDE strftime(dailyFileName,BUFSIZE,"/home/pi/RbData/%F/FDayRotation%F.dat",timeinfo); //INCLUDE printf("%s\n",fileName); printf("%s\n",comments); fp=fopen(fileName,"w"); if (!fp) { printf("Unable to open file: %s\n",fileName); exit(1); } fprintf(fp,"#Filename:\t%s\n#Comments:\t%s\n",fileName,comments); getIonGauge(&returnFloat); //printf("IonGauge %2.2E Torr \n",returnFloat); fprintf(fp,"#IonGauge(Torr):\t%2.2E\n",returnFloat); getConvectron(GP_N2_CHAN,&returnFloat); //printf("CVGauge(N2) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(N2)(Torr):\t%2.2E\n", returnFloat); getConvectron(GP_HE_CHAN,&returnFloat); //printf("CVGauge(He) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(He)(Torr):\t%2.2E\n", returnFloat); getPVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res:\t%f\n",returnFloat); getSVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res_set:\t%f\n",returnFloat); getPVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg:\t%f\n",returnFloat); getSVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg_set:\t%f\n",returnFloat); char line[1024]; fgets(line,1024,configFile); while(line[0]=='#'){ fprintf(fp,"%s",line); fgets(line,1024,configFile); } fclose(configFile); fprintf(fp,"#Revolutions:\t%d\n",revolutions); fprintf(fp,"#DataPointsPerRev:\t%d\n",dataPointsPerRevolution); fprintf(fp,"#NumVoltages:\t%d\n",1); fprintf(fp,"#PumpFrequency:\t%f\n",getPumpFrequency(&returnFloat)); //fprintf(fp,"#ProbeWavelength:\t%f\n",getProbeFreq()); // UNCOMMENT THE FOLLOWING LINES WHEN COLLECTING STANDARD DATA int photoDetectors[] = {PUMP_LASER,PROBE_LASER,REF_LASER}; char* names[]={"PMP","PRB","REF"}; // UNCOMMENT THE FOLLOWING LINES WHEN USING THE FLOATING PD //int photoDetectors[] = {PROBE_LASER,PUMP_LASER,REF_LASER}; //char* names[]={"PRB","PMP","REF"}; int numPhotoDetectors = 3; int motor = PROBE_MOTOR; // Write the header for the data to the file. fprintf(fp,"STEP"); for(i=0;i<numPhotoDetectors;i++){ fprintf(fp,"\t%s\t%ssd",names[i],names[i]); } fprintf(fp,"\n"); fclose(fp); fp=fopen(fileName,"a"); homeMotor(motor); angle=collectDiscreteFourierData(fp, photoDetectors, numPhotoDetectors, motor, revolutions); printf("The measured angle was: %3.1f\n",angle); fclose(fp); printf("Processing Data...\n"); analyzeData(fileName, 1, revolutions, dataPointsPerRevolution,FOI); }while(angle > desiredAngle + .4 || angle < desiredAngle -.4); closeUSB1208(); // Remove the file indicating that we are taking data. fclose(dataCollectionFlagFile); remove(dataCollectionFileName); return 0; }
int main (int argc, char **argv) { float value, returnFloat, wavelength; int revolutions; /* Variables for generating a file name with date and time */ time_t rawtime; struct tm * timeinfo; char fileName[BUFSIZE], comments[BUFSIZE]; char dailyFileName[BUFSIZE]; char dataCollectionFileName[] = "/home/pi/.takingData"; FILE *fp,*dataCollectionFlagFile,*configFile; if (argc==2){ strcpy(comments,argv[1]); } else { printf("usage '~$ sudo ./faradayScan <comments in quotes>'\n"); return 1; } // Indicate that data is being collected. dataCollectionFlagFile=fopen(dataCollectionFileName,"w"); if (!dataCollectionFlagFile) { printf("unable to open file:\t%s\n",dataCollectionFileName); exit(1); } revolutions=1; // Set up interfacing devices initializeBoard(); initializeUSB1208(); // Get file name. Use format "FDayScan"+$DATE+$TIME+".dat" time(&rawtime); timeinfo=localtime(&rawtime); struct stat st = {0}; strftime(fileName,BUFSIZE,"/home/pi/RbData/%F",timeinfo); //INCLUDE if (stat(fileName, &st) == -1){ mkdir(fileName,S_IRWXU | S_IRWXG | S_IRWXO ); } strftime(fileName,BUFSIZE,"/home/pi/RbData/%F/FDayScan%F_%H%M%S.dat",timeinfo); //INCLUDE strftime(dailyFileName,BUFSIZE,"/home/pi/RbData/%F/FDayScan%F.dat",timeinfo); //INCLUDE printf("%s\n",fileName); printf("%s\n",comments); fp=fopen(fileName,"w"); if (!fp) { printf("Unable to open file: %s\n",fileName); fflush(stdout); exit(1); } configFile=fopen("/home/pi/RbControl/system.cfg","r"); if (!configFile) { printf("Unable to open config file\n"); fflush(stdout); exit(1); } fprintf(fp,"#Filename:\t%s\n#Comments:\t%s\n",fileName,comments); /** Record System Stats to File **/ /** Pressure Gauges **/ getIonGauge(&returnFloat); printf("IonGauge %2.2E Torr \n",returnFloat); fprintf(fp,"#IonGauge(Torr):\t%2.2E\n",returnFloat); getConvectron(GP_N2_CHAN,&returnFloat); printf("CVGauge(N2) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(N2)(Torr):\t%2.2E\n", returnFloat); getConvectron(GP_HE_CHAN,&returnFloat); printf("CVGauge(He) %2.2E Torr\n", returnFloat); fprintf(fp,"#CVGauge(He)(Torr):\t%2.2E\n", returnFloat); /** Temperature Controllers **/ //getPVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res:\t%f\n",returnFloat); //getSVCN7500(CN_RESERVE,&returnFloat); fprintf(fp,"#T_res_set:\t%f\n",returnFloat); //getPVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg:\t%f\n",returnFloat); //getSVCN7500(CN_TARGET,&returnFloat); fprintf(fp,"#T_trg_set:\t%f\n",returnFloat); /** End System Stats Recording **/ char line[1024]; fgets(line,1024,configFile); while(line[0]=='#'){ fprintf(fp,"%s",line); fgets(line,1024,configFile); } fclose(configFile); /* int numDet=18,j; float scanDet[]={-33,-30,-19,-18,-9,-5,-4.5,-4,-3.5,6,6.5,7,7.5,11,20,21,30,33}; */ int numDet=10,j; float scanDet[]={-30,-27,-19,-18,-9,11,20,21,30,33}; fprintf(fp,"#Revolutions:\t%d\n",revolutions); fprintf(fp,"#DataPointsPerRev:\t%f\n",DATAPTSPERREV); fprintf(fp,"#NumVolts:\t%d\n",numDet); fprintf(fp,"#StepSize:\t%d\n",STEPSIZE); // Write the header for the data to the file. fprintf(fp,"STEP\tPUMP\tPUMPsd\tPRB\tPRBsd\tREF\tREFsd\n"); fclose(fp); printf("Homing motor...\n"); homeMotor(PROBE_MOTOR); // int numPd=3; // int pd[] = {PUMP_LASER,PROBE_LASER,REF_LASER}; int numPd=2; int pd[] = {BOTLOCKIN,TOPLOCKIN}; fp=fopen(fileName,"a"); setProbeDetuning(scanDet[0]); delay(10000); for(j=0;j<numDet;j++){ setProbeDetuning(scanDet[j]); getVortexPiezo(&value); delay(1000); getProbeFrequency(&wavelength); // wavelength=-1; fprintf(fp,"\n\n#VOLT:%f(%f)\n",value,wavelength); printf("VOLT:%f(%f)\t",value,wavelength); fflush(stdout); quickHomeMotor(PROBE_MOTOR); collectDiscreteFourierData(fp,pd,numPd /*numPhotoDet*/,PROBE_MOTOR,revolutions); }//end for Volt fclose(fp); //printf("Processing Data...\n"); //analyzeData(fileName, numDet, revolutions, dataPointsPerRevolution, FOI); char* extensionStart; extensionStart=strstr(fileName,".dat"); strcpy(extensionStart,"RotationAnalysis.dat"); //printf("Plotting Data...\n"); //plotData(fileName); //printf("Calculating number density...\n"); //calculateNumberDensity(fileName, 0, 0); //printf("Recording number density to file...\n"); //recordNumberDensity(fileName); closeUSB1208(); // Remove the file indicating that we are taking data. fclose(dataCollectionFlagFile); remove(dataCollectionFileName); return 0; }
RHD2000Thread::RHD2000Thread(SourceNode* sn) : DataThread(sn), chipRegisters(30000.0f), numChannels(0), deviceFound(false), isTransmitting(false), dacOutputShouldChange(false), acquireAdcChannels(false), acquireAuxChannels(true), fastSettleEnabled(false), dspEnabled(true), desiredDspCutoffFreq(0.5f), desiredUpperBandwidth(7500.0f), desiredLowerBandwidth(1.0f), boardSampleRate(30000.0f), savedSampleRateIndex(16), cableLengthPortA(0.914f), cableLengthPortB(0.914f), cableLengthPortC(0.914f), cableLengthPortD(0.914f), // default is 3 feet (0.914 m), audioOutputL(-1), audioOutputR(-1) { evalBoard = new Rhd2000EvalBoard; dataBlock = new Rhd2000DataBlock(1); dataBuffer = new DataBuffer(2, 10000); // start with 2 channels and automatically resize // Open Opal Kelly XEM6010 board. // Returns 1 if successful, -1 if FrontPanel cannot be loaded, and -2 if XEM6010 can't be found. File executable = File::getSpecialLocation(File::currentExecutableFile); #if defined(__APPLE__) const String executableDirectory = executable.getParentDirectory().getParentDirectory().getParentDirectory().getParentDirectory().getFullPathName(); #else const String executableDirectory = executable.getParentDirectory().getFullPathName(); #endif std::cout << executableDirectory << std::endl; String dirName = executableDirectory; libraryFilePath = dirName; libraryFilePath += File::separatorString; libraryFilePath += okLIB_NAME; if (openBoard(libraryFilePath)) { // upload bitfile and restore default settings initializeBoard(); // automatically find connected headstages scanPorts(); // things would appear to run more smoothly if this were done after the editor has been created if (0) { evalBoard->setContinuousRunMode(true); evalBoard->run(); } } }
UltimateBoard::UltimateBoard(int r, int c, int n) : Board(r, c, n) { initializeBoard(); initializeGame(); }
TicTacToeBoard::TicTacToeBoard() :Board(3, 3, 3) { initializeBoard(); }
int main (int argc, char **argv) { int dwell; int VHe; /* (V)oltage of (He)lium Target */ float leakageCurrent; int ammeterScale; char analysisFileName[80],backgroundFileName[80],rawDataFileName[80],comments[1024]; char configFileName[]="/home/pi/RbControl/system.cfg"; char buffer[1024]; char dataCollectionFileName[] = "/home/pi/.takingData"; // Variables for getting time information to identify // when we recorded the data time_t rawtime; struct tm * timeinfo; float returnFloat; char* extension; // Setup time variables time(&rawtime); timeinfo=localtime(&rawtime); struct stat st = {0}; // Get parameters. if (argc==6){ VHe=atoi(argv[1]); dwell=atoi(argv[2]); ammeterScale=atof(argv[3]); leakageCurrent=atof(argv[4]); strcpy(comments,argv[5]); strcpy(backgroundFileName,"NONE"); } else { printf("There is one option for using this program: \n\n"); printf("usage '~$ sudo ./polarization <voltage for He target> <dwell> <ammeterScale> <leakageCurrent> <comments_in_double_quotes>'\n"); printf(" (0-120) (1-5)s (assumed neg.) (just mantissa, \n"); printf(" assumed neg.) \n"); return 1; } // Indicate that data is being collected. FILE* dataCollectionFlagFile; dataCollectionFlagFile=fopen(dataCollectionFileName,"w"); if (!dataCollectionFlagFile) { printf("unable to open file \n"); exit(1); } initializeBoard(); initializeUSB1208(); // RUDAMENTARIY ERROR CHECKING if (VHe<0) VHe=0; if (VHe>1023) VHe=1023; // Create Directory for the day strftime(analysisFileName,80,"/home/pi/RbData/%F",timeinfo); if (stat(analysisFileName, &st) == -1){ mkdir(analysisFileName,S_IRWXU | S_IRWXG | S_IRWXO ); sprintf(buffer,"%s/img",analysisFileName); mkdir(analysisFileName,S_IRWXU | S_IRWXG | S_IRWXO ); extension = strstr(buffer,"/img"); strcpy(extension,"/anl"); mkdir(analysisFileName,S_IRWXU | S_IRWXG | S_IRWXO ); } // Create file name. Use format "EX"+$DATE+$TIME+".dat" strftime(rawDataFileName,80,"/home/pi/RbData/%F/POL%F_%H%M%S.dat",timeinfo); strcpy(analysisFileName,rawDataFileName); extension = strstr(analysisFileName,".dat"); strcpy(extension,"analysis.dat"); printf("\n%s\n",analysisFileName); FILE* rawData; // Write the header for the raw data file. rawData=fopen(rawDataFileName,"w"); if (!rawData) { printf("Unable to open file: %s\n", rawDataFileName); exit(1); } fprintf(rawData,"#File\t%s\n",rawDataFileName); fprintf(rawData,"#Comments\t%s\n",comments); printf("Comments:\t%s\n",comments); getIonGauge(&returnFloat); printf("IonGauge %2.2E Torr \n",returnFloat); fprintf(rawData,"#IonGauge(Torr):\t%2.2E\n",returnFloat); getConvectron(GP_N2_CHAN,&returnFloat); printf("CVGauge(N2) %2.2E Torr\n", returnFloat); fprintf(rawData,"#CVGauge(N2)(Torr):\t%2.2E\n", returnFloat); getConvectron(GP_HE_CHAN,&returnFloat); printf("CVGauge(He) %2.2E Torr\n", returnFloat); fprintf(rawData,"#CVGauge(He)(Torr):\t%2.2E\n", returnFloat); returnFloat=-1.0; //getPVCN7500(CN_RESERVE,&returnFloat); fprintf(rawData,"#T_res:\t%f\n",returnFloat); //getSVCN7500(CN_RESERVE,&returnFloat); fprintf(rawData,"#T_res_set:\t%f\n",returnFloat); //getPVCN7500(CN_TARGET,&returnFloat); fprintf(rawData,"#T_trg:\t%f\n",returnFloat); //getSVCN7500(CN_TARGET,&returnFloat); fprintf(rawData,"#T_trg_set:\t%f\n",returnFloat); fprintf(rawData,"#V_he:\t%d\n",VHe); fprintf(rawData,"#LEAKCURR:\t%f\n",leakageCurrent); fprintf(rawData,"#SCALE:\t%d\n",ammeterScale); fprintf(rawData,"#AOUTCONV:\t%2.6f\n",HPCAL); fprintf(rawData,"#REV:\t%d\n",REVOLUTIONS); fprintf(rawData,"#DATAPPR:\t%d\n",DATAPOINTSPERREV); fprintf(rawData,"#STPPERREV:\t%d\n",STEPSPERREV); fprintf(rawData,"#DATPTS:\t%d\n",DATAPOINTS); fprintf(rawData,"#DWELL(s):\t%d\n",dwell); getCommentLineFromFile(configFileName,"#PumpQWPAngle(step):",buffer); fprintf(rawData,"#QWP(STEP):\t%s\n",buffer); fclose(rawData); // Collect raw data getPolarizationData(rawDataFileName, VHe, dwell, leakageCurrent); plotData(rawDataFileName); processFileWithBackground(analysisFileName,backgroundFileName,rawDataFileName,DATAPOINTSPERREV,REVOLUTIONS,1); closeUSB1208(); // Remove the file indicating that we are taking data. fclose(dataCollectionFlagFile); remove(dataCollectionFileName); return 0; }
int main (int argc, char **argv) { // Variables for recording the time. time_t rawtime; struct tm * timeinfo; // Variables for describing the scan. float startvalue,endvalue,stepsize; // Variables for storing text char fileName[BUFSIZE],comments[BUFSIZE]; // A file used to indicate that we are collecting data. char dataCollectionFileName[] = "/home/pi/.takingData"; // Used to store error codes int err; FILE *dataCollectionFlagFile, *fp; /* Check to make sure that the proper arguments were supplied. */ if (argc==5) { startvalue=atof(argv[1]); endvalue=atof(argv[2]); stepsize=atof(argv[3]); strcpy(comments,argv[4]); } else { printf("Usage:\n"); printf("$ sudo ./RbAbsorbScan <begin> <end> <step> <comments>\n"); printf(" (0.0 - 117.5) \n"); return 0; } // Indicate that data is being collected. dataCollectionFlagFile=fopen(dataCollectionFileName,"w"); if (!dataCollectionFlagFile) { printf("Unable to open file: %s\n",dataCollectionFileName); exit(1); } initializeBoard(); initializeUSB1208(); if (endvalue>117.5) endvalue=117.5; if (startvalue>117.5) endvalue=117.5; if (startvalue<0) startvalue=0; if (endvalue<0) endvalue=0; if (startvalue>endvalue) { printf("error: startvalue > endvalue.\nYeah, i could just swap them in code.. or you could just enter them in correctly. :-)\n"); return 1; } // Get file name. use format "RbAbs"+$DATE+$TIME+".dat" time(&rawtime); timeinfo=localtime(&rawtime); struct stat st = {0}; strftime(fileName,BUFSIZE,"/home/pi/RbData/%F",timeinfo); if (stat(fileName, &st) == -1){ // Create the directory for the Day's data mkdir(fileName,S_IRWXU | S_IRWXG | S_IRWXO ); } strftime(fileName,BUFSIZE,"/home/pi/RbData/%F/RbAbs%F_%H%M%S.dat",timeinfo); printf("\n%s\n",fileName); writeFileHeader(fileName, comments); fp=fopen(fileName,"a"); if (!fp) { printf("unable to open file: %s\n",fileName); exit(1); } err=setMirror(0); if(err>0) printf("Error Occured While setting Flip Mirror: %d\n",err); collectAndRecordData(fileName, startvalue, endvalue, stepsize); setVortexPiezo(45.0); // Return Piezo to 45.0 V closeUSB1208(); graphData(fileName); fclose(dataCollectionFlagFile); remove(dataCollectionFileName); return 0; }