int main() { srand(time(NULL)); win[PLAYERONE] = win[PLAYERTWO] = 0; char grid[ROWS][COLS]; char input; int row = 4; int col = 4; int winning; int which_turn = rand_xoro(); //This is your turn counter, as requested int this_game_player; int player = this_game_player = rand_player(); do { winning = NOTHING; clear_grid(grid); player_prompt(player, which_turn); for(int i=0; !full(grid) && i < 9 && winning == NOTHING; i++) { int result; while ((result = test_input(input, grid, row, col, which_turn)) != 0) { if(result == 1) { printf("Invalid character, 1, 2, or 3 required\n"); read_everything(); } else if(result == 2) { printf("Invalid character, X or O required\n"); read_everything(); } else if(result == 3) { printf(" already taken\n"); read_everything(); } else if(result == 4) { printf("Invalid character\n"); read_everything(); } else if(result == 5) printf("\nNot enough characters!\n"); else if(result == 6) { printf("Invalid row or column selection\n"); read_everything(); } else if(result == 7) { printf("Invalid character selection for your player\n"); //Requested error message for invalid character read_everything(); } player_prompt(player, which_turn); } player = flip(player); which_turn = flip(which_turn); display_grid(grid); winning = test_winnings(grid); if(winning == NOTHING) player_prompt(player, which_turn); else if(winning == XWINS) { printf("Player1 total wins %i, Player 2 total wins %i\n", wins(PLAYERONE), wins(PLAYERTWO)); inc_wins(this_game_player); } else if(winning == OWINS) { inc_wins(this_game_player); printf("Player1 total wins %i, Player 2 total wins %i\n", wins(PLAYERONE), wins(PLAYERTWO)); } else if(winning == TIE) printf("Player1 total wins %i, Player 2 total wins %i\n", wins(PLAYERONE), wins(PLAYERTWO)); } this_game_player = flip(this_game_player); //Alternate players who go first each game. which_turn = rand_xoro(); //Randomize whether X or O comes first next game } while((winning == NOTHING) || (replay() == AGAIN)); }
void Grid_Container::clear() { clear_grid(); _array.clear(); }
//#### Member functions void Textgrafs::paint(){ //Used for continuous update //Refer to print for manual control if(next_tick()){ //Limit framerate print(); //Print out the current grid //save_old_grid(); } clear_grid(); //This empties the grid. You need to enter what you painted every frame }
int mainLoop( int argc, char *argv[] ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); glutInitWindowSize( winW, winH ); glutInitWindowPosition( 0, 0 ); if ( !glutCreateWindow( "tpldemo" ) ) { printf( "Couldn't open window.\n" ); return 1; } glutDisplayFunc( display ); glutIdleFunc( idlefunc ); glutMouseFunc( mouse ); glutMotionFunc( mouseMotion ); glutPassiveMotionFunc( mouseMotion ); glutKeyboardFunc( keyboard ); glutSpecialFunc( keyboard_special ); glutReshapeFunc( reshape ); glutSetCursor( GLUT_CURSOR_CROSSHAIR ); glEnable(GL_LIGHTING); GLfloat lightAmbient[] = {0.5f, 0.5f, 0.5f, 1.0f} ; glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lightAmbient); glEnable(GL_LIGHT0); GLfloat light0Position[] = {0.7f, 0.5f, 0.9f, 0.0f} ; GLfloat light0Ambient[] = {0.0f, 0.5f, 1.0f, 0.8f} ; GLfloat light0Diffuse[] = {0.0f, 0.5f, 1.0f, 0.8f} ; GLfloat light0Specular[] = {0.0f, 0.5f, 1.0f, 0.8f} ; glLightfv(GL_LIGHT0, GL_POSITION,light0Position) ; glLightfv(GL_LIGHT0, GL_AMBIENT,light0Ambient) ; glLightfv(GL_LIGHT0, GL_DIFFUSE,light0Diffuse) ; glLightfv(GL_LIGHT0, GL_SPECULAR,light0Specular) ; glEnable(GL_LIGHT1); GLfloat light1Position[] = {0.5f, 0.7f, 0.2f, 0.0f} ; GLfloat light1Ambient[] = {1.0f, 0.5f, 0.0f, 0.8f} ; GLfloat light1Diffuse[] = {1.0f, 0.5f, 0.0f, 0.8f} ; GLfloat light1Specular[] = {1.0f, 0.5f, 0.0f, 0.8f} ; glLightfv(GL_LIGHT1, GL_POSITION,light1Position) ; glLightfv(GL_LIGHT1, GL_AMBIENT,light1Ambient) ; glLightfv(GL_LIGHT1, GL_DIFFUSE,light1Diffuse) ; glLightfv(GL_LIGHT1, GL_SPECULAR,light1Specular) ; glCheckErrors(); clear_grid(); create_menu() ; glutMainLoop(); return 0; }
int main(int argc, char **argv) { log_options_t opts = LOG_OPTS_STDERR_ONLY; node_info_msg_t *node_info_ptr = NULL; node_info_msg_t *new_node_ptr = NULL; int error_code; int height = 40; int width = 100; int startx = 0; int starty = 0; int end = 0; int i; int rc; slurm_conf_init(NULL); log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL); parse_command_line(argc, argv); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_USER, NULL); } if (params.cluster_dims == 4) { min_screen_width = 92; } else if (params.cluster_dims == 3) min_screen_width = 92; /* no need for this if you are resolving */ while (slurm_load_node((time_t) NULL, &new_node_ptr, SHOW_ALL)) { if (params.resolve || (params.display == COMMANDS)) { new_node_ptr = NULL; break; /* just continue */ } error_code = slurm_get_errno(); printf("slurm_load_node: %s\n", slurm_strerror(error_code)); if (params.iterate == 0) exit(1); sleep(10); /* keep trying to reconnect */ } select_g_ba_init(new_node_ptr, 0); if (dim_size == NULL) { dim_size = get_cluster_dims(new_node_ptr); if ((dim_size == NULL) || (dim_size[0] < 1)) fatal("Invalid system dimensions"); } _init_colors(); if (params.resolve) { char *ret_str = resolve_mp(params.resolve, new_node_ptr); if (ret_str) { printf("%s", ret_str); xfree(ret_str); } _smap_exit(0); /* Calls exit(), no return */ } if (!params.commandline) { int check_width = min_screen_width; initscr(); init_grid(new_node_ptr, COLS); signal(SIGWINCH, (void (*)(int))_resize_handler); if (params.cluster_dims == 4) { height = dim_size[2] * dim_size[3] + dim_size[2] + 3; width = (dim_size[1] + dim_size[3] + 1) * dim_size[0] + 2; check_width += width; } else if (params.cluster_dims == 3) { height = dim_size[1] * dim_size[2] + dim_size[1] + 3; width = dim_size[0] + dim_size[2] + 3; check_width += width; } else { height = 10; width = COLS; } if ((COLS < check_width) || (LINES < height)) { endwin(); error("Screen is too small make sure the screen " "is at least %dx%d\n" "Right now it is %dx%d\n", check_width, height, COLS, LINES); _smap_exit(1); /* Calls exit(), no return */ } raw(); keypad(stdscr, true); noecho(); cbreak(); curs_set(0); nodelay(stdscr, true); start_color(); _set_pairs(); grid_win = newwin(height, width, starty, startx); max_display = (getmaxy(grid_win) - 1) * (getmaxx(grid_win) - 1); if (params.cluster_dims == 4) { startx = width; width = COLS - width - 2; height = LINES; } else if (params.cluster_dims == 3) { startx = width; width = COLS - width - 2; height = LINES; } else { startx = 0; starty = height; height = LINES - height; } text_win = newwin(height, width, starty, startx); } while (!end) { if (!params.commandline) { _get_option(); redraw: clear_window(text_win); clear_window(grid_win); move(0, 0); update_grid(new_node_ptr); main_xcord = 1; main_ycord = 1; } if (!params.no_header) print_date(); clear_grid(); switch (params.display) { case JOBS: get_job(); break; case RESERVATIONS: get_reservation(); break; case SLURMPART: get_slurm_part(); break; case COMMANDS: #ifdef HAVE_BG wclear(text_win); get_command(); #else error("Must be on a real BG SYSTEM to " "run this command"); if (!params.commandline) endwin(); _smap_exit(1); /* Calls exit(), no return */ #endif break; case BGPART: if (params.cluster_flags & CLUSTER_FLAG_BG) get_bg_part(); else { error("Must be on a BG SYSTEM to " "run this command"); if (!params.commandline) endwin(); _smap_exit(1); /* Calls exit(), no return */ } break; } if (!params.commandline) { box(text_win, 0, 0); wnoutrefresh(text_win); print_grid(); box(grid_win, 0, 0); wnoutrefresh(grid_win); doupdate(); node_info_ptr = new_node_ptr; if (node_info_ptr) { error_code = slurm_load_node( node_info_ptr->last_update, &new_node_ptr, SHOW_ALL); if (error_code == SLURM_SUCCESS) slurm_free_node_info_msg( node_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_node_ptr = node_info_ptr; } } else { error_code = slurm_load_node( (time_t) NULL, &new_node_ptr, SHOW_ALL); } if (error_code && (quiet_flag != 1)) { if (!params.commandline) { mvwprintw( text_win, main_ycord, 1, "slurm_load_node: %s", slurm_strerror( slurm_get_errno())); main_ycord++; } else { printf("slurm_load_node: %s", slurm_strerror( slurm_get_errno())); } } } if (params.iterate) { for (i = 0; i < params.iterate; i++) { sleep(1); if (!params.commandline) { if ((rc = _get_option()) == 1) goto redraw; else if (resize_screen) { resize_screen = 0; goto redraw; } } } } else break; } if (!params.commandline) { nodelay(stdscr, false); getch(); endwin(); } _smap_exit(0); /* Calls exit(), no return */ exit(0); /* Redundant, but eliminates compiler warning */ }
int main(int argc, char *argv[]) { log_options_t opts = LOG_OPTS_STDERR_ONLY; node_info_msg_t *node_info_ptr = NULL; node_info_msg_t *new_node_ptr = NULL; int error_code; int height = 40; int width = 100; int startx = 0; int starty = 0; int end = 0; int i; int rc; int mapset = 0; log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_DAEMON, NULL); parse_command_line(argc, argv); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_USER, NULL); } if (params.cluster_dims == 4) { min_screen_width = 92; } else if (params.cluster_dims == 3) min_screen_width = 92; while (slurm_load_node((time_t) NULL, &new_node_ptr, SHOW_ALL)) { error_code = slurm_get_errno(); printf("slurm_load_node: %s\n", slurm_strerror(error_code)); if (params.display == COMMANDS) { new_node_ptr = NULL; break; /* just continue */ } if (params.iterate == 0) _smap_exit(1); /* Calls exit(), no return */ sleep(10); /* keep trying to reconnect */ } _init_colors(); select_g_ba_init(new_node_ptr, 0); init_grid(new_node_ptr); if (params.resolve) { #if defined HAVE_BG_FILES && defined HAVE_BG_L_P #if 1 error("this doesn't work in the current 2.3 code. FIXME"); #else if (!have_db2) { printf("Required libraries can not be found " "to access the Bluegene system.\nPlease " "set your LD_LIBRARY_PATH correctly to " "point to them.\n"); goto part_fini; } if (!mapset) mapset = 1; if (params.resolve[0] != 'R') { i = strlen(params.resolve); i -= 3; if (i < 0) { printf("No real block was entered\n"); goto part_fini; } char *rack_mid = find_bp_rack_mid(params.resolve+i); if (rack_mid) { printf("X=%c Y=%c Z=%c resolves to %s\n", params.resolve[0+i], params.resolve[1+i], params.resolve[2+i], rack_mid); } else { printf("X=%c Y=%c Z=%c has no resolve\n", params.resolve[0+i], params.resolve[1+i], params.resolve[2+i]); } } else { uint16_t *coord = find_bp_loc(params.resolve); if (coord) { printf("%s resolves to X=%d Y=%d Z=%d\n", params.resolve, coord[0], coord[1], coord[2]); } else { printf("%s has no resolve.\n", params.resolve); } } part_fini: #endif #else printf("Must be physically on a BlueGene system for support " "of resolve option.\n"); #endif _smap_exit(0); /* Calls exit(), no return */ } if (!params.commandline) { int check_width = min_screen_width; signal(SIGWINCH, (void (*)(int))_resize_handler); initscr(); if (params.cluster_dims == 4) { height = dim_size[2] * dim_size[3] + dim_size[2] + 3; width = (dim_size[1] + dim_size[3] + 1) * dim_size[0] + 2; check_width += width; } else if (params.cluster_dims == 3) { height = dim_size[1] * dim_size[2] + dim_size[1] + 3; width = dim_size[0] + dim_size[2] + 3; check_width += width; } else { height = 10; width = COLS; } if ((COLS < check_width) || (LINES < height)) { endwin(); error("Screen is too small make sure the screen " "is at least %dx%d\n" "Right now it is %dx%d\n", check_width, height, COLS, LINES); _smap_exit(1); /* Calls exit(), no return */ } raw(); keypad(stdscr, TRUE); noecho(); cbreak(); curs_set(0); nodelay(stdscr, TRUE); start_color(); _set_pairs(); grid_win = newwin(height, width, starty, startx); max_display = grid_win->_maxy * grid_win->_maxx; if (params.cluster_dims == 4) { startx = width; COLS -= 2; width = COLS - width; height = LINES; } else if (params.cluster_dims == 3) { startx = width; COLS -= 2; width = COLS - width; height = LINES; } else { startx = 0; starty = height; height = LINES - height; } text_win = newwin(height, width, starty, startx); } while (!end) { if (!params.commandline) { _get_option(); redraw: clear_window(text_win); clear_window(grid_win); move(0, 0); main_xcord = 1; main_ycord = 1; } if (!params.no_header) print_date(); clear_grid(); switch (params.display) { case JOBS: get_job(); break; case RESERVATIONS: get_reservation(); break; case SLURMPART: get_slurm_part(); break; case COMMANDS: if (params.cluster_flags & CLUSTER_FLAG_BG) { if (!mapset) { mapset = 1; wclear(text_win); } get_command(); } else { error("Must be on a BG SYSTEM to " "run this command"); if (!params.commandline) endwin(); _smap_exit(1); /* Calls exit(), no return */ } break; case BGPART: if (params.cluster_flags & CLUSTER_FLAG_BG) get_bg_part(); else { error("Must be on a BG SYSTEM to " "run this command"); if (!params.commandline) endwin(); _smap_exit(1); /* Calls exit(), no return */ } break; } if (!params.commandline) { box(text_win, 0, 0); wnoutrefresh(text_win); print_grid(); box(grid_win, 0, 0); wnoutrefresh(grid_win); doupdate(); node_info_ptr = new_node_ptr; if (node_info_ptr) { error_code = slurm_load_node( node_info_ptr->last_update, &new_node_ptr, SHOW_ALL); if (error_code == SLURM_SUCCESS) slurm_free_node_info_msg( node_info_ptr); else if (slurm_get_errno() == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_node_ptr = node_info_ptr; } } else { error_code = slurm_load_node( (time_t) NULL, &new_node_ptr, SHOW_ALL); } if (error_code && (quiet_flag != 1)) { if (!params.commandline) { mvwprintw( text_win, main_ycord, 1, "slurm_load_node: %s", slurm_strerror( slurm_get_errno())); main_ycord++; } else { printf("slurm_load_node: %s", slurm_strerror( slurm_get_errno())); } } } if (params.iterate) { for (i = 0; i < params.iterate; i++) { sleep(1); if (!params.commandline) { if ((rc = _get_option()) == 1) goto redraw; else if (resize_screen) { resize_screen = 0; goto redraw; } } } } else break; } if (!params.commandline) { nodelay(stdscr, FALSE); getch(); endwin(); } _smap_exit(0); /* Calls exit(), no return */ exit(0); /* Redundant, but eliminates compiler warning */ }
int main(int argc, char *argv[]) { int blob_count = 0, i = 0; int main_channel = 2; /* red - botguy */ double time_of_snapshot = 0.0; double start = 0.0; printf("args: %d\n", argc); if (argc > 1) { if (argv[1][0] == '0') main_channel = 0; else if (argv[1][0] == '1') main_channel = 1; else if (argv[1][0] == '2') main_channel = 2; else if (argv[1][0] == '3') main_channel = 3; } for (i = 0; i < argc; i++) { printf("arg[%d] = %s\n", i, argv[i]); } printf("\n"); int area[NUM_TRACKING]; point2 center[NUM_TRACKING]; rectangle blob[NUM_TRACKING]; //int area1 = 0, areaX = 0; //point2 center; init_grid(); //wait_for_light(0); camera_open(); printf("Num channels: %d", get_channel_count()); camera_update(); time_of_snapshot = seconds(); msleep(300); start = seconds(); do { // Initialize memset(center, 0, sizeof(center)); memset(area, 0, sizeof(area)); clear_grid(); // Begin // Do not do anything with the camera until enough time has passed if (seconds() - time_of_snapshot >= 0.1) { camera_update(); time_of_snapshot = seconds(); blob_count = get_object_count(main_channel); //sprintf(msg, "#:%2d", blob_count); diag(); printf("#:%-2d ", blob_count); if (blob_count > count_of(area)) { blob_count = count_of(area); } if (blob_count > 0) { for (i = 0; i < blob_count; ++i) { area[i] = get_object_area(main_channel, i); center[i] = get_object_center(main_channel, i); blob[i] = get_object_bbox(main_channel, i); plot(&blob[i], i + '0'); } for (i = 0; i < blob_count; ++i) { printf(" %3d", blob[i].width * blob[i].height); } for (; i < count_of(blob); ++i) { printf(" "); } printf(" "); for (i = 0; i < blob_count; ++i) { printf(" %2dx%2d", blob[i].width, blob[i].height); } //show_xy(center[0].x, center[0].y); } //printf(" |%3d %4d <-> %4d %3d| %s\n", delta_left, left, right, delta_right, message); printf("%s\n", message); message[0] = 0; diag(); show_grid(); } //printf("The time is: %f %f\n", seconds(), seconds() - start); } while (seconds() - start <= 4.0); camera_close(); return 0; }