//begin main int main (void) { char current[BOARD_SIZE][BOARD_SIZE] ; char future[BOARD_SIZE][BOARD_SIZE] ; initialize_board(current, ' ') ; initialize_board(future, ' ') ; char choice ; int stillgoing = 1; while (stillgoing) { printf("\033[2J\033[H") ; copy_board(current, future) ; print_board(current) ; printf("Please enter one of the following:\n a: to add a new cell\n r: to remove a cell\n n: to advance the simulation\n q: to quit\n p: to play the game forever\n") ; scanf("%c", &choice) ; stillgoing = user_action(current, future, choice) ; } return 0 ; } //end main
int main(void) { bool win = FALSE; int move, max_moves; int player; print_instructions(); max_moves = DIM * DIM; /* Maximum number of moves in a game */ while (TRUE) { initialize_board(); for (move = 1; move <= max_moves; move++) { player = move % 2 == 0 ? 2 : 1; win = do_move(player); print_board(); if (win) { printf("Player %d, you WON!\n\n", player); break; /* out of for loop */ } } /* * If we got here by falling through the loop, then it is a * tie game. */ if (!win) printf("Tie Game!\n\n"); if (!ask_yesno("Do you wish to play again?")) break; /* out of while loop */ } return 0; }
int main(void) { printf("\nwelcome to the Tic-Tac-Toe game. \n"); print_boardwithNum(); while(1) { initialize_board(); choose_difficulty(); if(whoisthefirst() == 0) { com = 'O'; user = '******'; } else { com = 'X'; user ='******'; } game_starts(); if(restart() != 1) break; } return 0; }
int main(int ac, char *av[]) { if ( initialize_board() == -1 ) { return 1; } game_loop(); return 0; }
int main(void) { uint8_t input = 0; initialize_board(); // for (int i = 0; i < 256; i++) { // spi_shift_out(i); // spi_latch(); // _delay_ms(100); // } while (1) { input = rs485_getc(); if (BYTE_IS_OUTPUT_COMMAND(input)) { process_output_command(); } else if (BYTE_IS_GENERIC_COMMAND(input)) { process_generic_command(); } else { // don't know what to do with this byte } } return 0; }
int main(void) { firmware_signature = FIRMWARE_SIGNATURE; initialize_board(); #if defined(BUSPIRATEV4) BP_LEDUSB_DIR = OUTPUT; BP_USBLED_ON(); #ifdef USB_INTERRUPTS EnableUsbPerifInterrupts(USB_TRN | USB_SOF | USB_UERR | USB_URST); EnableUsbGlobalInterrupt(); #endif /* USB_INTERRUPTS */ /* Wait until the USB interface is configured. */ do { #ifndef USB_INTERRUPTS usb_handler(); #endif /* !USB_INTERRUPTS */ } while (usb_device_state < CONFIGURED_STATE); BP_USBLED_OFF(); usb_register_sof_handler(CDCFlushOnTimeout); #endif /* BUSPIRATEV4 */ /* Starts processing user requests. */ serviceuser(); return 0; }
int main(int argc, char **argv){ int board[ROW][COL], newBoard[ROW][COL]; initialize_board(board); /*copy board into the new one*/ for (int i = 0; i < ROW; i++) { for (int j = 0; j < COL; j++) { newBoard[i][j] = board[i][j]; } } for (int i = 0; i < 100000; i++) { clear_terminal(); if (i % 2) { update_board(newBoard, board); print_board(newBoard); } else{ update_board(board, newBoard); print_board(board); } usleep(1000); } return EXIT_SUCCESS; }
/** thread_init(): Initialize a thread on Windows. This is written by Teemu Pudas. Created 071108; last modified 071108 **/ DWORD WINAPI thread_init(LPVOID arg) { board.id = *(int *)arg; initialize_board(NULL); initialize_hash(); board.split_ply = board.split_ply_stack; board.split_ply_stack[0] = -1; board.split_point = board.split_point_stack; board.split_point_stack[0] = NULL; idle_loop(board.id); return 0; }
int main () { int board[BOARD_WIDTH][BOARD_HEIGHT]; srand(pot.read_u16()); initialize_board (board); print (board); while (1) { print (board); play (board); wait_ms (500); } }
int main(int argc, char *argv[]){ char test_str[] = "Hello World"; int bytes = strlen(test_str); // get number of bytes in test string char buf[BUF_SIZE]; int ret; // return value int bus; // which bus to use // Parse arguments if(argc!=2){ //argc==2 actually means one argument given print_usage(); return -1; } else bus = atoi(argv[1]); if(!(bus==0||bus==1||bus==2||bus==5)){ print_usage(); return -1; } // Initialization initialize_board(); printf("\ntesting UART bus %d\n\n", bus); if(initialize_uart(bus, BAUDRATE, TIMEOUT_S)){ printf("Failed to initialize_uart%d\n", bus); cleanup_board(); return -1; } // Flush and Write printf("Sending %d bytes: %s \n", bytes, test_str); flush_uart(bus); uart_send_bytes(bus, bytes, &test_str[0]); // Read memset(buf, 0, BUF_SIZE); ret = uart_read_bytes(bus, bytes, &buf[0]); if(ret<0) printf("Error reading bus\n"); else if(ret==0)printf("timeout reached, %d bytes read\n", ret); else printf("Received %d bytes: %s \n", ret, buf); // close up close_uart(bus); cleanup_board(); return 0; }
void SYSTEM_init() { initialize_board(); // board configurations SCHEDULER_init(); uint8_t message[] = "hola"; // test message /*------------------------------------------------------------------------------ tasks inits ------------------------------------------------------------------------------*/ PC_LINK_init(115200); CLOCK_task_init(message); LED_toggle_task_init(); LED_toggle_task_init2(); modes_flag = NORMAL; button_state4 = BUTTON_UP; button_state3 = BUTTON_UP; button_state2 = BUTTON_UP; button_state1 = BUTTON_UP; buttonMefInit(button_state1); buttonMefInit(button_state2); buttonMefInit(button_state3); buttonMefInit(button_state4); }
int main(void) { unsigned int pot_value; unsigned int counter = 0; initialize_board(); initialize_led(); initialize_uart(); initialize_adc(MODE_ANALOG0); initialize_pwm(); uart_printf("Hello, world!\n"); while(1) { pot_value = adc_get_reading(); //UARTprintf ("Temperature = %3d*C \r", adc_get_temp ()); uart_printf ("AIN0 (PE3) = %3d Duty value = %d\r", pot_value, pot_value/4); led_toggle (GREEN_LED); counter += 100; if (counter > 1000) counter = 0; pwm_set_duty (pot_value/4); // // This function provides a means of generating a constant length // delay. The function delay (in cycles) = 3 * parameter. Delay // 250ms arbitrarily. // SysCtlDelay(SysCtlClockGet() / 12); } }
int main(int argc, char** argv) { check_input_count(argc); int x = parse_param(argv[1]); int y = parse_param(argv[2]); int initial_cells = parse_param(argv[3]); Board* board_struct = initialize_board_struct(x, y, initial_cells); initialize_board(board_struct); printf("------ Initial Board ------\n"); print_board(board_struct); printf("------ ------------- ------\n"); int i = 0; while (board_struct->current_cells > 0 && i < 50000) { printf("------ Step %d ------\n", i + 1); update_board_state(board_struct); print_board(board_struct); i++; } free_board(board_struct); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetRectMode(OF_RECTMODE_CENTER); ofSetBackgroundAuto(false); initialize_board(); gui.setup(); gui.add(speed.setup("speed", .5, 0, 1)); gui.add(frequency.setup("frequency", 0, -300, 300)); //Audio frequencyFloat = 440; amplitude = 1; phase = 0; //Background for(int i = 0; i < background_size; i++){ timers[i] = i; elapsedTimers[i] = &timers[i]; } //Leave at end of function ofSoundStreamSetup(2, 0, 48000, 512, 4); }
int main(){ initialize_board(); enable_motors(); // bring H-bridges of of standby set_led(GREEN,ON); set_led(RED,OFF); // Forward set_motor_all(SPEED); printf("\nAll Motors Forward\n"); sleep(2); // Reverse set_motor_all(-SPEED); printf("All Motors Reverse\n"); sleep(2); // Stop set_motor_all(0); disable_motors(); //put H-bridges into standby printf("All Motors Off\n\n"); cleanup_board(); return 0; }
// Constructor gameboard::gameboard() { initialize_board(); }
vector<vector<string>> solveNQueens(int n) { NQueens(initialize_board(n), 0, n); return solutions; }
/** pgn_open(): pgn_open opens a .pgn file and reads all games into the internal database. The number of games found is returned. Created 091407; last modified 091607 **/ int pgn_open(char *file_name) { char buffer[BUFSIZ]; char *c; char *b; int games; long last_offset; PGN_GAME *game; PGN_STATE state; /* Try opening the file. */ if (pgn_file != NULL) fclose(pgn_file); pgn_file = fopen(file_name, "rt"); if (pgn_file == NULL) { print("%s: file not found.\n", file_name); return -1; } /* First, quickly find the number of games. */ state = NEUTRAL; games = 0; while (fgets(buffer, BUFSIZ, pgn_file) != NULL) { switch (state) { case NEUTRAL: /* Stupid macros need an int cast... sigh */ if (isspace((int)buffer[0])) continue; state = HEADERS; case HEADERS: if (buffer[0] == '[') continue; state = MOVES; case MOVES: if (strstr(buffer, "1-0") || strstr(buffer, "0-1") || strstr(buffer, "1/2-1/2") || strstr(buffer, "*")) { games++; state = NEUTRAL; } } } /* Initialize the database. */ if (pgn_database.game != NULL) free(pgn_database.game); pgn_database.game_count = games; pgn_database.game = calloc(games, sizeof(PGN_GAME)); print("%i games loaded.\n", games); /* Read in all of the games. */ state = NEUTRAL; rewind(pgn_file); last_offset = 0; game = &pgn_database.game[0]; while (fgets(buffer, BUFSIZ, pgn_file)) { switch (state) { case NEUTRAL: /* Stupid macros need an int cast... sigh */ if (isspace((int)buffer[0])) continue; game->offset = last_offset; state = HEADERS; case HEADERS: if (buffer[0] == '[') { c = strtok(buffer, "\""); if (c == NULL) continue; c = strtok(buffer + strlen(c) + 1, "\""); if (c == NULL) continue; b = strtok(buffer + 1, " =\""); if (!strcmp(b, "Event")) strcpy(game->tag.event, c); if (!strcmp(b, "Site")) strcpy(game->tag.site, c); if (!strcmp(b, "Date")) strcpy(game->tag.date, c); if (!strcmp(b, "Round")) strcpy(game->tag.round, c); if (!strcmp(b, "White")) strcpy(game->tag.white, c); if (!strcmp(b, "Black")) strcpy(game->tag.black, c); if (!strcmp(b, "Result")) strcpy(game->tag.result, c); if (!strcmp(b, "FEN")) { strcpy(game->tag.fen, c); initialize_board(c); } continue; } state = MOVES; case MOVES: if (strstr(buffer, "1-0") || strstr(buffer, "0-1") || strstr(buffer, "1/2-1/2") || strstr(buffer, "*")) { game++; state = NEUTRAL; } } last_offset = ftell(pgn_file); } return games; }
int main(int argc, char* argv[]) { SDL_Surface* screen; SDL_Event event; if(SDL_Init(SDL_INIT_VIDEO) == -1) { return 1; } SDL_WM_SetCaption("Game of Life", NULL); screen = SDL_SetVideoMode(SCR_WIDTH, SCR_HEIGHT, 32, SDL_SWSURFACE); Uint32 bg_color = SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF); Uint32 live_color = SDL_MapRGB(screen->format, 0x33, 0x33, 0x33); int board1[BOARD_SIZE]; int board2[BOARD_SIZE]; initialize_board(board1); memcpy(board2, board1, BOARD_SIZE * sizeof(int)); Uint64 generation = 0; next_time = SDL_GetTicks() + TICK_INTERVAL; while(1) { int quit = 0; int* current; int* next; if (generation++ % 2) { current = board2; next = board1; } else { current = board1; next = board2; } while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_QUIT: quit = 1; break; case SDL_MOUSEBUTTONDOWN: if (event.button.button == SDL_BUTTON_LEFT) { if (event.button.y > (ROWS * CELL_SIZE)) break; int tx = floor(event.button.x / CELL_SIZE); int ty = floor(event.button.y / CELL_SIZE); add_glider(current, tx, ty); } break; default: continue; } } if (quit) { break; } draw_board(screen, current, bg_color, live_color); SDL_Delay(time_left()); next_time += TICK_INTERVAL; tick(current, next); } SDL_Quit(); return 0; }
/** pgn_load(): pgn_load loads a specific game from the opened pgn database. The board position is set to the last position in the game. Created 091407; last modified 111208 **/ void pgn_load(int game_number, POS_FUNC pos_func, void *pos_arg) { char buffer[BUFSIZ]; char move_buf[8]; char flag_buf[8]; int consumed; int braces; int x; POS_DATA pos_data; PGN_GAME *game; PGN_STATE state; NOTATION old_notation; if (pgn_database.game_count == 0) { print("No database loaded.\n"); return; } if (game_number < 1 || game_number > pgn_database.game_count) { print("Invalid game number: %i. Valid numbers are 1-%i\n", game_number, pgn_database.game_count); return; } /* Copy the PGN tags. */ game = &pgn_database.game[game_number - 1]; strcpy(pgn_game.tag.event, game->tag.event); strcpy(pgn_game.tag.site, game->tag.site); strcpy(pgn_game.tag.date, game->tag.date); strcpy(pgn_game.tag.round, game->tag.round); strcpy(pgn_game.tag.white, game->tag.white); strcpy(pgn_game.tag.black, game->tag.black); strcpy(pgn_game.tag.result, game->tag.result); strcpy(pgn_game.tag.fen, game->tag.fen); /* Initialize. */ if (strcmp(pgn_game.tag.fen, "") != 0) initialize_board(pgn_game.tag.fen); else initialize_board(NULL); /* Set the engine to force mode. */ zct->zct_side = EMPTY; old_notation = zct->notation; /* PGN uses SAN, of course... */ zct->notation = SAN; braces = 0; state = NEUTRAL; pos_data.type = POS_PGN; pos_data.pgn = game; /* Find the game in the PGN file and start reading. */ fseek(pgn_file, game->offset, SEEK_SET); while (fgets(buffer, sizeof(buffer), pgn_file)) { switch (state) { case NEUTRAL: /* Stupid macros need an int cast... sigh */ if (isspace((int)buffer[0])) continue; state = HEADERS; case HEADERS: if (buffer[0] == '[') continue; state = MOVES; case MOVES: /* Read the next line of input. Strip out all of the unneeded characters. */ set_cmd_input(buffer); cmd_parse(" \t.+#\r\n"); for (x = 0; x < cmd_input.arg_count; x++) { if (strchr(cmd_input.arg[x], '{')) braces++; if (strchr(cmd_input.arg[x], '}')) braces--; else if (braces == 0) { /* Pull out any flags in the move string and separate them. */ consumed = sscanf(cmd_input.arg[x], "%8[^?!=]%8[?!=]", move_buf, flag_buf); if (consumed == 2) strcpy(pos_data.flags, flag_buf); else strcpy(pos_data.flags, ""); /* Check if we have a valid move. If so, make it and call pos_func. */ if (input_move(move_buf, INPUT_CHECK_MOVE)) { input_move(move_buf, INPUT_USER_MOVE); /* Now execute the pos_func, which does any processing for this move, for example the book making routine which collects statistics. */ if (pos_func != NULL) if (pos_func(pos_arg, &pos_data)) goto end; } /* Check for end-of-game. */ else if (!strcmp(cmd_input.arg[x], "1-0") || !strcmp(cmd_input.arg[x], "0-1") || !strcmp(cmd_input.arg[x], "1/2-1/2") || !strcmp(cmd_input.arg[x], "*")) goto end; } } } } /* Look at the spaghetti code! How unreadable! ;) */ end: zct->notation = old_notation; }
/** epd_load(): Opens an EPD file and does processing on each position based on the POS_FUNC. This is usually used for running test suites. Created 110506; last modified 111208 **/ int epd_load(char *file_name, POS_FUNC pos_func, void *pos_arg) { FILE *epd_file; int x; int positions; char *s; char buffer[BUFSIZ]; MOVE move; EPD_POS epd; POS_DATA pos_data; if ((epd_file = fopen(file_name, "rt")) == NULL) { perror(file_name); return 0; } positions = 0; pos_data.epd = &epd; while (fgets(buffer, sizeof(buffer), epd_file) != NULL) { set_cmd_input(buffer); cmd_parse(" \t\n"); if (cmd_input.arg_count < 6) { print("Bad epd record at position %i: %s", positions, buffer); continue; } /* Grab the FEN portion of the EPD record and set up the board. */ strcpy(epd.fen, ""); for (x = 0; x < cmd_input.arg_count && x < 5 && strcmp(cmd_input.arg[x], "id") != 0 && strcmp(cmd_input.arg[x], "bm") != 0 && strcmp(cmd_input.arg[x], "am") != 0; x++) { strcat(epd.fen, cmd_input.arg[x]); strcat(epd.fen, " "); } initialize_board(epd.fen); generate_root_moves(); /* Parse the rest of the EPD record to find the other information: best move, avoid move, ID */ epd.solution_count = 0; for (x = 0; x < cmd_input.arg_count; x++) { /* Best move or avoid move. */ if (!strcmp(cmd_input.arg[x], "bm") || !strcmp(cmd_input.arg[x], "am")) { epd.type = (cmd_input.arg[x][0] == 'b' ? EPD_BEST_MOVE : EPD_AVOID_MOVE); /* Kinda hacky */ /* We could have multiple solutions for this EPD. Pull off each one, parse it, and att it to the list. */ while (TRUE) { x++; /* Pull off a semicolon from the end. Save the pointer, because it marks the end of the loop. */ if ((s = strchr(cmd_input.arg[x], ';')) != NULL) *s = '\0'; /* Try parsing the move. */ move = input_move(cmd_input.arg[x], INPUT_GET_MOVE); if (move == NO_MOVE) print("Illegal solution at position %i: %s\n", positions, cmd_input.arg[x]); else epd.solution[epd.solution_count++] = move; /* No more solutions... */ if (s != NULL) break; } } if (!strcmp(cmd_input.arg[x], "id")) strcpy(epd.id, cmd_input.arg[++x]); } /* Sanity check. */ if (epd.solution_count == 0) ;// print("No solutions given at position %i!!!\n", positions); if (pos_func != NULL) if (pos_func(pos_arg, &pos_data)) break; positions++; } fclose(epd_file); return positions; }