int main(int argc, char **argv) { t_env *e; int i; e = NULL; i = -1; if (argc != 2) { ft_putendl("Usage : ./fillit <filename>"); return (0); } e = new_env(e); e->file = argv[1]; read_file(e); c_pieces(e); while (++i < e->nb_piece && i < 26) e->t[i] = scan(e->buf, i); if (verif(e) == 1) return (0); new_square(e); resolve(e); display_grid(e); free(e); return (0); }
// <- FUNCTIONS -> // void display(void) { clear_bitmap(buffer); //clear the buffer display_grid(); //displays the blue check box display_text(); //displays the text display_marks(); //displays the X's and O's if(game_win == true) draw_sprite(buffer, WIN, mouse_x - ABOVE_MOUSE, mouse_y - ABOVE_MOUSE); else if(player == 0) //draws the pointer X or O as the mouse moves draw_sprite(buffer, O_MARK, mouse_x - ABOVE_MOUSE, mouse_y - ABOVE_MOUSE); //masked_blit(CIRCLE, buffer, 0, 0, mouse_x - ABOVE_MOUSE, mouse_y - ABOVE_MOUSE, SCREEN_W, SCREEN_H); else if(player == 1) //draws the pointer X or O as the mouse moves draw_sprite(buffer, X_MARK, mouse_x - ABOVE_MOUSE, mouse_y - ABOVE_MOUSE); blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H); }
int main(int argc, char *argv[]) { struct grid grid; int i; int x; int y; if (argc != 3) { my_putstr("Wrong number of arguments. Try `./demineur x_size y_size'.\n"); return 0; } x = my_getnbr(argv[2]); y = my_getnbr(argv[1]); if (x < 1 || y < 1) { my_putstr("Wrong arguments. Try `./demineur x_size y_size'.\n"); return 0; } srand((unsigned int)time(NULL)); init_grid(&grid, x, y); display_grid(&grid, true); for (i = 0; i < grid.x; i++) free(grid.cell[i]); free(grid.cell); return 0; }
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 start_game(t_grid *grid) { int random; int i; int winner; ft_putendl("starting the game"); srand(time(NULL)); random = rand() % 2; i = 0; while ((!(winner = check_winner(grid, 'X'))) && (!(winner = check_winner(grid, 'O'))) && (!(winner = tie(grid)))) { random ^= 1; if (random) { while (player_turn(grid) == 0) i++; } else ai_turn(grid); } display_grid(grid); call_winner(winner); }
int main(int argc, char **argv) { int nbr_tetris; char **grid; t_tetrimino *tetris; t_coord co; t_path path; path.square_size = -1; path.path = ft_strnew(27); co.x = 0; co.y = 0; nbr_tetris = -1; if (argc != 2 || !(is_valid_file(argv[1]))) write(1, "error\n", 6); else if (!(nbr_tetris = process_file(argv[1], 0, &tetris))) write(1, "error\n", 6); else { grid = create_grid(nbr_tetris); path = fill_grid(grid, tetris, co, nbr_tetris); ft_strrev(path.path); grid_from_str(path.path, grid, tetris, co); display_grid(grid); free_grid(grid); } return (0); }
void play(t_game *game, int turn) { ft_putstr(MSG_TURN); ft_putnbr(turn); ft_putchar('\n'); display_grid(game); player_play(game, turn); }
void display_filler(t_filler *f) { int i; i = 0; ft_putstr_fd("\nf->x: ", 1); ft_putnbr_fd(f->x, 1); ft_putstr_fd("\nf->y: ", 1); ft_putnbr_fd(f->y, 1); ft_putstr_fd("\nf->way: ", 1); ft_putnbr_fd(f->way, 1); ft_putstr_fd("\nf->all_id: ", 1); ft_putstr_fd(f->all_id, 1); ft_putstr_fd("\nf->my_id: ", 1); ft_putstr_fd(f->my_id, 1); ft_putchar_fd('\n', 1); display_grid(&f->form); display_grid(&f->grid); ft_putchar_fd('\n', 1); }
void displays_all(t_all *all) { getmaxyx(stdscr, all->env.col, all->env.row); check_valid_win(all); display_grid(all); display_scores(all); if (all->env.win) display_victory(all); attron(COLOR_PAIR(2)); display_edges(all); attroff(COLOR_PAIR(2)); }
void get_grid(int (**power)) { FILE *fp; int i, j; char str[80]; // int power[3][4]; printf("Filename: "); scanf("%s", str); fp = fopen(str, "r"); for (i = 0; i < 3; i++) //for every row you want to go to every column for (j = 0; j < 4; j++) //scan in the integer and store it in the array fscanf(fp, "%d", &power[i][j]); display_grid(power); return; } // read_file()
bool is_won(struct grid *grid) { bool win; int i; int j; win = true; for (i = 0 ; i < grid->x; i++) for (j = 0; j < grid-> y; j++) if (grid->cell[i][j].value != -1 && !grid->cell[i][j].visible) win = false; if (win == true) { my_putstr("You win !\n"); display_grid(grid, true); } for (i = 0 ; i < grid->x; i++) for (j = 0; j < grid-> y; j++) if (grid->cell[i][j].value == -1 && grid->cell[i][j].visible) win = true; return (win); }
/*program for the game "tank"*/ int main()/*begin finction main*/ { /*declare variables for this program*/ int size; int x; int y; int counter = 0; int check = 0; int checkpos; int antibomb = 1; printf("\nEnter the grid size: ");/*prompt user to enter a grid size*/ scanf("%d", &size);/*assign value to the variable size*/ srand(time(NULL));/*ranomize the function rand*/ initialize_grid(size);/*initialize the display array*/ set_bomb(size);/*set bombs and open spots on the grid*/ set_antibomb(size);/*set two antibombs on grid*/ while (counter < 5)/*begin game code for 5 rounds of safe tank moves*/ { check = 0;/*set check back to 0*/ while (check == 0) { printf("\nEnter the x position for tank: ");/*promt user to enter x postition to move tank to*/ scanf("%d", &x); printf("Enter the y position for tank: ");/*prompt user to enter y position to move tank to */ scanf("%d", &y); check = error_check(x, y, size); /*check to see that user entered correct coordnance to move tank to*/ } checkpos = check_position(x, y);/*check to see what lies where user chose to move tank*/ if (checkpos == 1)/*case user landed on a bomb*/ { --antibomb;/*remove antibomb*/ if (antibomb == 0)/*if no anti bombs, GAME OVER*/ { printf("\nTank was bombed\nYou lost the game\n\n"); play[y][x] = '$';/*mark where bomb was*/ display_grid(play, size);/*display play grid*/ printf("\n"); return 0;/*game over*/ } else { printf("Tank was bombed but but anti-bomb saved the tank\n\n");/*if user had an anti bomb, game continues*/ display_grid(display, size); } } else if (checkpos == 2)/*case user lands on antibomb*/ { ++antibomb;/*add an antibomb*/ printf("\nAntibomb collected\n\n");/*let user know they collected an antibomb*/ display_grid(display, size);/*display grid with moves marked*/ } else { counter++;/*add one to counter*/ display[y][x] = '+';/*add one to counter and mark spot that user has already moved to*/ printf("\n"); display_grid(display, size);/*display grid with move marked moves*/ } } printf("\nCongratulations you won the game.\nTank survived all the bomb attacks.\n\n");/*prompt the user that they have won the game*/ }/*end function main*/
int main(int argc, char **argv) { int rank; int world_size; /* * Initialization */ int thread_support; if (MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &thread_support) != MPI_SUCCESS) { fprintf(stderr,"MPI_Init_thread failed\n"); exit(1); } if (thread_support == MPI_THREAD_FUNNELED) fprintf(stderr,"Warning: MPI only has funneled thread support, not serialized, hoping this will work\n"); if (thread_support < MPI_THREAD_FUNNELED) fprintf(stderr,"Warning: MPI does not have thread support!\n"); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &world_size); starpu_srand48((long int)time(NULL)); parse_args(rank, argc, argv); int ret = starpu_init(NULL); STARPU_CHECK_RETURN_VALUE(ret, "starpu_init"); /* We disable sequential consistency in this example */ starpu_data_set_default_sequential_consistency_flag(0); starpu_mpi_init(NULL, NULL, 0); STARPU_ASSERT(p*q == world_size); starpu_cublas_init(); int barrier_ret = MPI_Barrier(MPI_COMM_WORLD); STARPU_ASSERT(barrier_ret == MPI_SUCCESS); /* * Problem Init */ init_matrix(rank); fprintf(stderr, "Rank %d: allocated (%d + %d) MB = %d MB\n", rank, (int)(allocated_memory/(1024*1024)), (int)(allocated_memory_extra/(1024*1024)), (int)((allocated_memory+allocated_memory_extra)/(1024*1024))); display_grid(rank, nblocks); TYPE *a_r = NULL; // STARPU_PLU(display_data_content)(a_r, size); TYPE *x, *y; if (check) { x = calloc(size, sizeof(TYPE)); STARPU_ASSERT(x); y = calloc(size, sizeof(TYPE)); STARPU_ASSERT(y); if (rank == 0) { unsigned ind; for (ind = 0; ind < size; ind++) x[ind] = (TYPE)starpu_drand48(); } a_r = STARPU_PLU(reconstruct_matrix)(size, nblocks); if (rank == 0) STARPU_PLU(display_data_content)(a_r, size); // STARPU_PLU(compute_ax)(size, x, y, nblocks, rank); } barrier_ret = MPI_Barrier(MPI_COMM_WORLD); STARPU_ASSERT(barrier_ret == MPI_SUCCESS); double timing = STARPU_PLU(plu_main)(nblocks, rank, world_size); /* * Report performance */ int reduce_ret; double min_timing = timing; double max_timing = timing; double sum_timing = timing; reduce_ret = MPI_Reduce(&timing, &min_timing, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); STARPU_ASSERT(reduce_ret == MPI_SUCCESS); reduce_ret = MPI_Reduce(&timing, &max_timing, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); STARPU_ASSERT(reduce_ret == MPI_SUCCESS); reduce_ret = MPI_Reduce(&timing, &sum_timing, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); STARPU_ASSERT(reduce_ret == MPI_SUCCESS); if (rank == 0) { fprintf(stderr, "Computation took: %f ms\n", max_timing/1000); fprintf(stderr, "\tMIN : %f ms\n", min_timing/1000); fprintf(stderr, "\tMAX : %f ms\n", max_timing/1000); fprintf(stderr, "\tAVG : %f ms\n", sum_timing/(world_size*1000)); unsigned n = size; double flop = (2.0f*n*n*n)/3.0f; fprintf(stderr, "Synthetic GFlops : %2.2f\n", (flop/max_timing/1000.0f)); } /* * Test Result Correctness */ if (check) { /* * Compute || A - LU || */ STARPU_PLU(compute_lu_matrix)(size, nblocks, a_r); #if 0 /* * Compute || Ax - LUx || */ unsigned ind; y2 = calloc(size, sizeof(TYPE)); STARPU_ASSERT(y); if (rank == 0) { for (ind = 0; ind < size; ind++) { y2[ind] = (TYPE)0.0; } } STARPU_PLU(compute_lux)(size, x, y2, nblocks, rank); /* Compute y2 = y2 - y */ CPU_AXPY(size, -1.0, y, 1, y2, 1); TYPE err = CPU_ASUM(size, y2, 1); int max = CPU_IAMAX(size, y2, 1); fprintf(stderr, "(A - LU)X Avg error : %e\n", err/(size*size)); fprintf(stderr, "(A - LU)X Max error : %e\n", y2[max]); #endif } /* * Termination */ barrier_ret = MPI_Barrier(MPI_COMM_WORLD); STARPU_ASSERT(barrier_ret == MPI_SUCCESS); starpu_cublas_shutdown(); starpu_mpi_shutdown(); starpu_shutdown(); #if 0 MPI_Finalize(); #endif return 0; }
static shell_state grid_disp_handle() { display_grid(); return GRID; }
extern void go_interactive() { display_grid(); shell(); }
int main(void) { int dir; srand(time(NULL)); uint8_t nb_empty_box, nb_merge; #if USE_BIN /* Creation of a grid */ grid_t grid = create_empty_grid_bin(); /* Grid backup */ grid_t saved_grid; /* Initialisation of the grid */ grid = init_grid_bin(grid, &nb_empty_box); /* Display the grid */ display_grid_bin(grid); /* Main loop for a game */ while (nb_empty_box > 0 || merge_possible_bin(grid)) { do { saved_grid = grid; /* While the move does not lead to a change on the grid */ // dir = random_move(); dir = best_move_bin(grid, nb_empty_box); /* Trying to play the move */ grid = move_bin(grid, dir, &nb_merge); nb_empty_box += nb_merge; } while (grid == saved_grid); /* Add tile */ grid = add_tile_bin(grid); nb_empty_box--; /* Display the new grid */ display_grid_bin(grid); printf("Empty boxes: %u\n", nb_empty_box); } #else /* Creation of a grid */ uint16_t **grid = create_empty_grid(); /* Initialisation of the grid */ init_grid(grid); /* Display the grid */ display_grid(grid); #if DEBUG printf("Value: %i\n", evaluate(grid)); #endif /* Main loop for a game */ while (!game_over(grid)) { /* While the move does not lead to a change on the grid */ do { #if IA #if RANDOM dir = random_move(); #else dir = best_move(grid); #endif #else dir = ask_dir(); #endif /* Trying to play the move */ } while (!move(grid, dir)); /* Add a new tile at the end of each round */ add_tile(grid); /* Display the new grid */ display_grid(grid); #if DEBUG printf("Value: %i\n", evaluate(grid)); #endif } #endif return 0; }
void print_game(struct grid *grid) { my_putstr("____________________________\n"); display_grid(grid, false); my_putnbr(grid->flags); my_putstr(" flags\n"); my_putnbr(grid->mines); my_putstr(" mines\n"); my_putstr("What do you want to do ?\n Check a cell : coord_x coord_y\n"); my_putstr("Set/Unset a flag : -f coord_x coord_y\n Give up : exit\n"); }