int grab_key5(int keycode, t_img *img) { if (keycode == 15) { set_plan(img); img->zoom = 1; img->flou = 0; img->nb_i = 50; clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } if (keycode == 69) { img->plan.x_a += img->plan.step_x * WIDTH / 4; img->plan.y_a += img->plan.step_y * HEIGHT / 4; img->plan.x_b -= img->plan.step_x * WIDTH / 4; img->plan.y_b -= img->plan.step_y * HEIGHT / 4; img->plan.step_x = (img->plan.x_b - img->plan.x_a) / WIDTH; img->plan.step_y = (img->plan.y_b - img->plan.y_a) / HEIGHT; clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } if (keycode == 3) img->flou = (img->flou) ? 0 : 1; return (0); }
int ft_keypress(int keycode, t_env *e) { if (keycode == 76) { clear_map(e); get_point(e); choose_fractal(e); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); } if (keycode == 69 || keycode == 78) increase_deacrease(keycode, e); if (keycode == 123 || keycode == 124) ft_keypress2(keycode, e); if (keycode == 126 || keycode == 125) ft_keypress2(keycode, e); if (keycode == 53) { clear_map(e); exit(0); } if (keycode == 12) e->loop = 1; if (keycode == 0) e->loop = 0; return (0); }
int grab_key4(int keycode, t_img *img) { if (keycode == 78) { img->plan.x_a -= img->plan.step_x * WIDTH / 2; img->plan.y_a -= img->plan.step_y * HEIGHT / 2; img->plan.x_b += img->plan.step_x * WIDTH / 2; img->plan.y_b += img->plan.step_y * HEIGHT / 2; img->plan.step_x = (img->plan.x_b - img->plan.x_a) / WIDTH; img->plan.step_y = (img->plan.y_b - img->plan.y_a) / HEIGHT; clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } if (keycode == 9) { if (img->c_value == 0) img->c_value = 1; else if (img->c_value == 1) img->c_value = 0; clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } return (0); }
int grab_key2(int keycode, t_img *img) { if (keycode == 53) { free(img); exit(0); } if (keycode == 8) { if (img->type == 's') img->type = 'm'; else if (img->type == 'm') img->type = 'j'; else if (img->type == 'j') img->type = 's'; set_plan(img); clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } if (keycode == 36) { img->start = 1; clear_map(img); grab_expose(img); } return (0); }
int main(int ac, char **av) { char before[SIZE_X][SIZE_Y]; char after[SIZE_X][SIZE_Y]; (void)ac; clear_map(before); clear_map(after); init_map(before, ft_atoi(av[1])); show_map(before); usleep(TURN_TIME); algo(before, after, ft_atoi(av[2])); return (0); }
void map_labels::clear(const std::string& team_name, bool force) { team_label_map::iterator i = labels_.find(team_name); if (i != labels_.end()) { clear_map(i->second, force); } i = labels_.find(""); if (i != labels_.end()) { clear_map(i->second, force); } }
void algo(char before[SIZE_X][SIZE_Y], char after[SIZE_X][SIZE_Y], int turn) { int i; int j; i = -1; j = -1; if (turn == 0) turn = -1; while (turn != 0) { while (++i < SIZE_X) { while (++j < SIZE_Y) { if (check_around(before, i, j) == 3) after[i][j] = 1; else if (check_around(before, i, j) == 2 && before[i][j] == 1) after[i][j] = 1; else after[i][j] = 0; } j = -1; } i = -1; copy_map(after, before); clear_map(after); ft_putstr("\033[H\033[2J"); show_map(before); usleep(TURN_TIME); if (turn != -1) --turn; } }
int ft_keypress2(int keycode, t_env *e) { if (keycode == 124) move_map(e, (double)WIN_W * 0.05, 0); if (keycode == 123) move_map(e, (double)WIN_W * -0.05, 0); if (keycode == 125) { if (e->title[0] == 'J' || e->title[0] == 'M') move_map(e, 0, (double)WIN_H * 0.05); if (e->title[0] == 'S') move_map(e, 0, (double)WIN_H * -0.05); } if (keycode == 126) { if (e->title[0] == 'J' || e->title[0] == 'M') move_map(e, 0, (double)WIN_H * -0.05); if (e->title[0] == 'S') move_map(e, 0, (double)WIN_H * 0.05); } clear_map(e); choose_fractal(e); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); return (0); }
void start_vaccum(t_map *game) { int cycle; bool info; t_biscuit *nodedab; t_biscuit *noderobby; cycle = 0; nodedab = game->bisc; noderobby = game->bisc; info = false; while (info != true) { if (system("clear") < 0) exit(EXIT_FAILURE); clear_map(game->map); add_dab_robby(game); aff_map(game); usleep(80000); cycle++; if (gere_dab(game, nodedab) == 1) if (nodedab->life == true) nodedab = nodedab->next; if (gere_robby(game, noderobby, &info) == 1) noderobby = noderobby->next; } printf("Nombre de cycle = %d\n", cycle); }
/** * Error codes: * 0: No error * -1: Unknown error * -2: Wrong map format * -3: Map file version too recent * -4: Could not open file */ int load_map( const char* filename ) { char* ff[4]; uint16_t version; int f = open(filename, O_RDONLY); if (f == -1) { return -4; } read(f,ff,4); if (strncmp((const char*)ff,"FMMF",4) != 0) { return -2; } read(f,&version,2); if (version > FMMF_VERSION) { return -3; } clear_map(); read(f,&map.w,sizeof(unsigned short)); read(f,&map.h,sizeof(unsigned short)); map.tile = (unsigned char*)malloc(map.w*map.h); read(f,map.tile,map.w*map.h); for (int i=0; i<FMMF_OBJECTS; ++i) { read(f,&map.object[i].type,1); read(f,&map.object[i].x,sizeof(unsigned short)); read(f,&map.object[i].y,sizeof(unsigned short)); read(f,&map.object[i].state,sizeof(unsigned int)); } close(f); return 0; }
/// Will clear the map of all elements, calling the deletion callback on each element if it is not NULL. bool DS_Hash_Map_clear(DS_Hash_Map_t *map, DS_delete_cb del){ MU_ARG_CHECK(logger, false, map, map && map->buckets, map && map->size); MU_COND_RWLOCK_WRLOCK(map->lock, logger); bool successful = clear_map(map, del); MU_COND_RWLOCK_UNLOCK(map->lock, logger); return successful; }
void check_vehicle_damage( std::string explosive_id, std::string vehicle_id, int range ) { // Clear map clear_map(); tripoint origin( 30, 30, 0 ); vehicle *target_vehicle = g->m.add_vehicle( vproto_id( vehicle_id ), origin, 0, -1, 0 ); std::vector<int> before_hp = get_part_hp( target_vehicle ); while( g->m.veh_at( origin ) ) { origin.x++; } origin.x += range; // Set off an explosion item grenade( explosive_id ); grenade.charges = 0; grenade.type->invoke( g->u, grenade, origin ); std::vector<int> after_hp = get_part_hp( target_vehicle ); // We don't expect any destroyed parts. CHECK( before_hp.size() == after_hp.size() ); for( unsigned int i = 0; i < before_hp.size(); ++i ) { INFO( target_vehicle->parts[ i ].name() ); if( target_vehicle->parts[ i ].name() == "windshield" || target_vehicle->parts[ i ].name() == "headlight" ) { CHECK( before_hp[ i ] >= after_hp[ i ] ); } else { CHECK( before_hp[ i ] == after_hp[ i ] ); } } }
/** * Initialize map's data. * @param xl Map width. * @param yl Map height. * @param px Player's X position. * @param py Player's Y position. */ void init_map_data(int xl, int yl, int px, int py) { if (xl != -1) { MapData.xlen = xl; } if (yl != -1) { MapData.ylen = yl; } if (px != -1) { MapData.posx = px; } if (py != -1) { MapData.posy = py; } if (xl > 0) { clear_map(); } }
void map_labels::clear_all() { for (team_label_map::value_type &m : labels_) { clear_map(m.second, true); } labels_.clear(); }
void check_lethality( std::string explosive_id, int range, float lethality, float epsilon ) { int num_survivors = 0; int num_subjects = 0; int num_wounded = 0; statistics<double> lethality_ratios; std::stringstream survivor_stats; int total_hp = 0; int average_hp = 0; float error = 0.0; float lethality_ratio = 0.0; do { // Clear map clear_map(); // Spawn some monsters in a circle. tripoint origin( 30, 30, 0 ); for( const tripoint monster_position : closest_tripoints_first( range, origin ) ) { if( rl_dist( monster_position, origin ) != range ) { continue; } num_subjects++; spawn_test_monster( "mon_zombie", monster_position ); } // Set off an explosion item grenade( explosive_id ); grenade.charges = 0; grenade.type->invoke( g->u, grenade, origin ); // see how many monsters survive std::vector<Creature *> survivors = g->get_creatures_if( []( const Creature & critter ) { return critter.is_monster(); } ); num_survivors += survivors.size(); for( Creature *survivor : survivors ) { survivor_stats << survivor->pos() << " " << survivor->get_hp() << ", "; num_wounded += ( survivor->get_hp() < survivor->get_hp_max() ) ? 1 : 0; total_hp += survivor->get_hp(); } if( num_survivors > 0 ) { survivor_stats << std::endl; average_hp = total_hp / num_survivors; } double survivor_ratio = static_cast<double>( num_survivors ) / num_subjects; lethality_ratio = 1.0 - survivor_ratio; lethality_ratios.add( lethality_ratio ); error = lethality_ratios.margin_of_error(); } while( lethality_ratios.n() < 5 || ( lethality_ratios.avg() + error > lethality && lethality_ratios.avg() - error < lethality ) ); INFO( "samples " << lethality_ratios.n() ); INFO( explosive_id ); INFO( "range " << range ); INFO( num_survivors << " survivors out of " << num_subjects << " targets." ); INFO( survivor_stats.str() ); INFO( "Wounded survivors: " << num_wounded ); INFO( "average hp of survivors: " << average_hp ); CHECK( lethality_ratio == Approx( lethality ).epsilon( epsilon ) ); }
void card_map::realloc_hero_map(const size_t size) { if (map_) { clear_map(); } map_size_ = size; map_ = (card**)malloc(size * sizeof(card*)); map_vsize_ = 0; }
void new_map(int w, int h) { clear_map(); map.w = w; map.h = h; map.tile = (unsigned char*)malloc(w*h); memset(map.tile,0,w*h); for (int i=0; i<FMMF_OBJECTS; ++i) { map.object[i].type = O_NONE; } }
int capture_mouse_pos(int x, int y, t_env *e) { if (ft_strcmp(e->title, "Jul") == 0) { clear_map(e); e->julia_x = e->point.x_1 + ((double)x * e->point.step_x); e->julia_y = e->point.y_1 + ((double)y * e->point.step_y); choose_fractal(e); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); } return (0); }
/* input: all sensor data output: map with obstacle information from the map, get obstacle position and target position */ STATUS update_map(int sensor[OBS_SENSOR], MAP* map) { /* 1st: caculate three points: center & 2 heads 2nd: */ POSITION header_1, header_2; //2 headers int width, height, index; float radius, cur_theta; float detect_vision; int w, h; clear_map(map); detect_vision = 15.0 /180.0 * PI; for(index=0; index<OBS_SENSOR; index++) { // theta used here is in common frame rather than robot frame // the right one is the first and the left is the last if( 0 == index ) { cur_theta = 0; header_1.x = sensor[index] * cos(cur_theta); header_1.y = sensor[index] * sin(cur_theta); cur_theta = 7.5 /180.0 * PI; header_2.x = sensor[index] * cos(cur_theta); header_2.y = sensor[index] * sin(cur_theta); } else if( 12 == index ) { cur_theta = (180.0 - 7.5)/180.0 * PI; header_1.x = sensor[index] * cos(cur_theta); header_1.y = sensor[index] * sin(cur_theta); cur_theta = 7.5 /180.0 * PI; header_2.x = sensor[index] * cos(cur_theta); header_2.y = sensor[index] * sin(cur_theta); } else { cur_theta = (15 * index - 7.5)/180.0 * PI; header_1.x = sensor[index] * cos(cur_theta); header_1.y = sensor[index] * sin(cur_theta); cur_theta = (15 * index + 7.5)/180.0 * PI; header_2.x = sensor[index] * cos(cur_theta); header_2.y = sensor[index] * sin(cur_theta); } draw_map(header_1, header_2, sensor[index], map); } return TRUE; }
// --------------------------------------------------------------- // class to find paths for adventure map // --------------------------------------------------------------- void t_combat_obstruction_finder::initialize() { if (m_initialized) return; // mark all points that can be entered by a 7x7 creature m_initialized = true; t_battlefield& battlefield = m_battlefield; t_combat_path_blockage blockage; t_combat_footprint const& footprint = get_combat_footprint( 7 ); blockage.blocked = false; blockage.in_tower = false; blockage.forbidden = false; blockage.has_wall = false; t_combat_path_blockage_map map( battlefield.get_size(), k_battlefield_cell_height, k_battlefield_logical_view_size, blockage ); map.mark_obstacles( battlefield ); clear_map( battlefield, map, footprint ); // find point to start seed t_map_point_2d point; int row_end; t_combat_path_data* ptr; // find the first point that can be entered point.row = m_data.get_size(); while (point.row--) { if (m_has_castle && point.row < k_castle_row) break; point.column = m_data.get_row_start( point.row ); row_end = m_data.get_row_end( point.row ); ptr = &m_data.get( point ); while (point.column < row_end) { if (!ptr->blocked) { push_first_point( point ); return; } ptr++; point.column++; } } }
int grab_key(int keycode, t_img *img) { if (keycode == 34) { img->nb_i += 50; if (img->nb_i > 1000) img->nb_i = 10; clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } if (keycode == 46) { img->reset = 0; clear_map(img); grab_expose(img); } grab_key2(keycode, img); grab_key3(keycode, img); grab_key4(keycode, img); grab_key5(keycode, img); return (0); }
int map_read_map_cmd(const char **s) { /* get new map */ strcpy(map_name, get_identifier(s)); map_width = get_num(s); map_height = get_num(s); printf("map '%s' (%ld x %ld)\n", map_name, map_width, map_height); map_init_code_pos = 0; clear_map(); return 1; }
void level1() { myprintf("Hey, 2048 is so difficult. Let's begin from 64. I think everyone can reach it...?\n"); myprintf("Press any key to start...\n"); getchar(); init_map(); if (play(64)) { myprintf("Congraz! You pass 64! XD\n"); clear_map(); CHEAT = 1; } else { myprintf("How can you lose? I can't believe it!\n"); exit(0); } }
void *worker(void *arg) { struct thread_data *data = (struct thread_data*)arg; while (1) { if (pthread_eqaul(data->_task->_turn, pthread_self())) { decode(data->_task->_queue.get(1)); } else { if (key2imsi.size() == 0) { pthread_cond_wait(_wait); } else { clear_map(); } } } }
int increase_deacrease(int keycode, t_env *e) { if (keycode == 69) { clear_map(e); if (e->title[0] == 'S') e->nb_i == 13 ? e->nb_i = 13 : e->nb_i++; if (e->title[0] == 'J' || (e->title[0] == 'M')) e->nb_i += 20; choose_fractal(e); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); } if (keycode == 78) { clear_map(e); if (e->title[0] == 'S') e->nb_i = (e->nb_i == 0 ? 0 : e->nb_i - 1); if (e->title[0] == 'J' || (e->title[0] == 'M')) e->nb_i = (e->nb_i == 50 ? 50 : e->nb_i - 20); choose_fractal(e); mlx_put_image_to_window(e->mlx, e->win, e->img, 0, 0); } return (0); }
int grab_key3(int keycode, t_img *img) { if (keycode == 123 || keycode == 124) { if (keycode == 123) move_map(img, (double)WIDTH * 0.05, 0); else move_map(img, (double)WIDTH * -0.05, 0); clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } if (keycode == 126 || keycode == 125) { if (keycode == 126) move_map(img, 0, (double)HEIGHT * 0.05); else move_map(img, 0, (double)HEIGHT * -0.05); clear_map(img); draw_map(img); mlx_put_image_to_window(img->mlx_ptr, img->win_ptr, img->img_ptr, 0, 0); } return (0); }
void init_world( WORLD *world, char *spr, int tile_index, int x, int y, int w, int h, int cw, int ch ) { init_world_map(world, w, h); /* Load tiles */ world->tiles=load_sprite(spr, WORLD_TILE_WIDTH, WORLD_TILE_HEIGHT); if (world->tiles == NULL) { fprintf(stderr, "Unable to load tiles %s\n", spr); exit(1); } world->map=new_map(WORLD_TILE_WIDTH, WORLD_TILE_HEIGHT, WORLD_NUM_TILES, w, h); if (world->map == NULL) { free_sprite(world->tiles); fprintf(stderr, "Unable to load create new map\n"); exit(1); } world->tile_base = tile_index; world->tile_width = WORLD_TILE_WIDTH; world->tile_height = WORLD_TILE_HEIGHT; world->width = world->tile_width * w; world->height = world->tile_height * h; world->map->tiles[world->tile_base + WORLD_EMPTY_TILE].type = 1; world->map->tiles[world->tile_base + WORLD_BLOCK_TILE_LO].type = 1; world->map->tiles[world->tile_base + WORLD_BLOCK_TILE_HI].type = 1; clear_map(world->map, world->tile_base + WORLD_EMPTY_TILE); init_world_terrain(world, x, y, cw, ch); }
void curses_clear_nhwin(winid wid) { WINDOW *win = curses_get_nhwin(wid); boolean border = curses_window_has_border(wid); if (wid == MAP_WIN) { clearok(win, TRUE); /* Redraw entire screen when refreshed */ clear_map(); } werase(win); if (border) { box(win, 0, 0); } }
void curses_putch(winid wid, int x, int y, int ch, int color, int attr) { int sx, sy, ex, ey; boolean border = curses_window_has_border(wid); nethack_char nch; static boolean map_initted = FALSE; if (wid == STATUS_WIN) { curses_update_stats(FALSE); } if (wid != MAP_WIN) { return; } if (!map_initted) { clear_map(); map_initted = TRUE; } map[y][x].ch = ch; map[y][x].color = color; map[y][x].attr = attr; nch = map[y][x]; (void)curses_map_borders(&sx, &sy, &ex, &ey, -1, -1); if ((x >= sx) && (x <= ex) && (y >= sy) && (y <= ey)) { if (border) { x++; y++; } write_wchar(mapwin, x - sx, y - sy, nch); } wrefresh(mapwin); }
TbBool load_map_data_file(LevelNumber lv_num) { struct Map *mapblk; unsigned long x,y; unsigned char *buf; unsigned long i; unsigned long n; unsigned short *wptr; long fsize; clear_map(); fsize = 2*(map_subtiles_y+1)*(map_subtiles_x+1); buf = load_single_map_file_to_buffer(lv_num,"dat",&fsize,LMFF_None); if (buf == NULL) return false; i = 0; for (y=0; y < (map_subtiles_y+1); y++) { for (x=0; x < (map_subtiles_x+1); x++) { mapblk = get_map_block_at(x,y); n = -lword(&buf[i]); mapblk->data ^= (mapblk->data ^ n) & 0x7FF; i += 2; } } LbMemoryFree(buf); // Clear some bits and do some other setup for (y=0; y < (map_subtiles_y+1); y++) { for (x=0; x < (map_subtiles_x+1); x++) { mapblk = get_map_block_at(x,y); wptr = &game.lish.subtile_lightness[get_subtile_number(x,y)]; *wptr = 32; mapblk->data &= 0xFFC007FFu; mapblk->data &= ~0x0F000000; mapblk->data &= ~0xF0000000; } } return true; }