DisplayScreen::DisplayScreen(ExportScreen* _export_screen, int _screen_width, int _screen_height): window_height(420), window_width(337), paused(false), export_screen(_export_screen), screen_height(_screen_height), screen_width(_screen_width) { // Initialise SDL Video */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(window_width,window_height, 0, SDL_HWPALETTE|SDL_DOUBLEBUF|SDL_RESIZABLE); if (screen == NULL) { fprintf(stderr, "Couldn't Initialize Screen: %s\n", SDL_GetError()); exit(-1); } // Set the screen title SDL_WM_SetCaption("A.L.E. Viz", NULL); // Initialize our screen matrix for (int i=0; i<screen_height; ++i) { IntVect row; for (int j=0; j<screen_width; ++j) row.push_back(-1); screen_matrix.push_back(row); } // Register ourselves as an event handler registerEventHandler(this); fprintf(stderr, "Screen Display Active. Press 'h' for help.\n"); }
// the contents of v are blown out void ExplicitBitVect::getOnBits (IntVect& v) const { unsigned int nOn = getNumOnBits(); if(!v.empty()) IntVect().swap(v); v.reserve(nOn); for(unsigned int i=0;i<d_size;i++){ if((bool)(*dp_bits)[i]) v.push_back(i); } };
void TestSortTable() { { typedef std::pair<int, int> IntPair; typedef std::vector<IntPair> IntVect; typedef IntVect::iterator IntVectIter; IntVect test; IntVect checked; test.push_back(make_pair(10, 0)); test.push_back(make_pair(9, 1)); test.push_back(make_pair(3, 2)); test.push_back(make_pair(3, 3)); test.push_back(make_pair(5, 4)); test.push_back(make_pair(5, 5)); test.push_back(make_pair(5, 6)); test.push_back(make_pair(1, 7)); checked.push_back( make_pair(1, 7)); checked.push_back( make_pair(3, 2)); checked.push_back( make_pair(3, 3)); checked.push_back( make_pair(5, 4)); checked.push_back( make_pair(5, 5)); checked.push_back( make_pair(5, 6)); checked.push_back( make_pair(9, 1)); checked.push_back( make_pair(10, 0)); stable_sort(test.begin(), test.end()); bool res = std::equal(test.cbegin(), test.cend(), checked.cbegin(), [](const IntPair& left, const IntPair& right)->bool { return (left.first == right.first) && (left.second == right.second); } ); CHECK_RESULTS(res); } }
/* *************************************************************************** * This is a temporary method, used for preparing a demo video. * It should be pretty much ignored! * ***************************************************************************/ Action SearchAgent::tmp_prepare_demo_vid(void) { if (i_frame_counter < 1250) { return PLAYER_A_NOOP; } if (i_frame_counter < 1300) { return PLAYER_A_DOWN; } str_curr_state = save_state(); // initilize the screen_matrix if (pm_sim_scr_matrix == NULL) { pm_sim_scr_matrix = new IntMatrix; assert(i_screen_height > 0); assert(i_screen_width > 0); for (int i = 0; i < i_screen_height; i++) { IntVect row; for (int j = 0; j < i_screen_width; j++) { row.push_back(-1); } pm_sim_scr_matrix->push_back(row); } } char buffer [50]; ostringstream filename; MediaSource& mediasrc = p_osystem->console().mediaSource(); for (int a = 0; a < i_num_actions; a++) { load_state(str_curr_state); GameController::apply_action(p_sim_event_obj, PLAYER_A_NOOP, PLAYER_B_NOOP); p_osystem->myTimingInfo.start = p_osystem->getTicks(); mediasrc.update(); Action curr_act = (*p_game_settings->pv_possible_actions)[a]; filename.str(""); filename << "action_" << action_to_string(curr_act) << "_00.png"; p_osystem->p_export_screen->save_png(pm_sim_scr_matrix, filename.str()); for (int i = 0; i < 15; i++) { GameController::apply_action(p_sim_event_obj, curr_act, PLAYER_B_NOOP); p_osystem->myTimingInfo.start = p_osystem->getTicks(); mediasrc.update(); copy_simulated_framebuffer(); sprintf (buffer, "%02d", i + 1); filename.str(""); filename << "action_" << action_to_string(curr_act) << "_" << buffer << ".png"; p_osystem->p_export_screen->save_png(pm_sim_scr_matrix, filename.str()); } } end_game(); return UNDEFINED; }
/* ********************************************************************* Initilizes the Simulation Engine This involves generating a new OSystem and loadign settings for it ******************************************************************** */ void SearchAgent::init_simulation_engine() { p_sim_event_obj = p_osystem->event(); p_sim_console = &(p_osystem->console()); p_sim_system = &(p_sim_console->system()); // Initilize the screen matrix and RAM vector if (p_game_settings->b_uses_screen_matrix) { pm_sim_scr_matrix = new IntMatrix; assert(i_screen_height > 0); assert(i_screen_width > 0); for (int i = 0; i < i_screen_height; i++) { IntVect row; for (int j = 0; j < i_screen_width; j++) { row.push_back(-1); } pm_sim_scr_matrix->push_back(row); } } else { pm_sim_scr_matrix = NULL; } pv_sim_ram_content = new IntVect(RAM_LENGTH); }