TEST(Levels, load_nph) { Levels l; l.addPath("data/L00_title.nph"); ASSERT_EQ(1, l.numLevels()); ASSERT_STREQ("title", l.levelName(0).c_str()); }
TEST(Levels, load_nonexistent) { Levels l; l.addPath("/a/non/existent/path"); ASSERT_EQ(0, l.numLevels()); l.addPath("/a"); ASSERT_EQ(0, l.numLevels()); }
void Map::loadLevel(int level){ Levels levels; tile.clear(); std::cout << "Loading level " << level << "..." << std::endl; levels.getLevel(&tile, level); this->sizeY = tile.size(); this->sizeX = tile[0].size(); }
/** * Creates transitions from labelled edges of BA and passes them to the automaton structure. */ void addTransitions(AutomatonStructure & automaton, const StateID ID) const { const PropertyAutomaton::Edges & edges = property.getEdges(ID); // Transform each edge into transition and pass it to the automaton for (const PropertyAutomaton::Edge & edge : edges) { // Compute allowed values from string of constrains ConstraintParser * parser = new ConstraintParser(maxes.size(), *max_element(maxes.begin(), maxes.end())); parser->applyFormula(names, edge.cons.values); parser->addBoundaries(maxes, true); parser->addBoundaries(mins, false); automaton.addTransition(ID, { edge.target_ID, parser, edge.cons.transient, edge.cons.stable }); } }
/** Number the vertices of the forest. */ void renumber_vertices() { size_t id=0; for (size_t i=0; i<levels.size(); ++i) { for (Vertices::const_iterator vi=levels[i].vertices.begin(); vi!=levels[i].vertices.end(); ++vi) (*vi)->id = id++; } }
/** Print the entire forest for debugging output. */ void print(std::ostream &o) const { for (size_t i=0; i<levels.size(); ++i) { if (levels[i].vertices.empty()) { o <<"partition forest level " <<i <<" is empty.\n"; } else { size_t nsets = levels[i].vertices.size(); size_t nfuncs = 0; for (Vertices::const_iterator vi=levels[i].vertices.begin(); vi!=levels[i].vertices.end(); ++vi) nfuncs += (*vi)->functions.size(); o <<"partition forest level " <<i <<" contains " <<nfuncs <<" function" <<(1==nfuncs?"":"s") <<" in " <<nsets <<" set" <<(1==nsets?"":"s") <<"\n"; o <<" the following input was used to generate " <<(1==nsets?"this set":"these sets") <<":\n"; o <<StringUtility::prefixLines(levels[i].inputs.toString(), " "); int setno = 1; for (Vertices::const_iterator vi=levels[i].vertices.begin(); vi!=levels[i].vertices.end(); ++vi, ++setno) { Vertex *vertex = *vi; const Functions &functions = vertex->functions; o <<" set #" <<setno <<" contains " <<vertex->functions.size() <<" function" <<(1==vertex->functions.size()?"":"s") <<":\n"; for (Functions::const_iterator fi=functions.begin(); fi!=functions.end(); ++fi) { SgAsmFunction *func = *fi; o <<" " <<StringUtility::addrToString(func->get_entry_va()) <<" <" <<func->get_name() <<">\n"; } o <<" whose output was: {"; for (OutputValues::const_iterator oi=vertex->outputs.begin(); oi!=vertex->outputs.end(); ++oi) o <<" " <<*oi; o <<" }\n"; } } } }
int main() { window.create(sf::VideoMode(800, 600), "Breakfree"); window.setVerticalSyncEnabled(true); //, sf::Style::Close|sf::Style::Titlebar); if (!font.loadFromFile("Nirmala.ttf")) return EXIT_FAILURE; Levels lv; Paddle pad; InputManager input; while (window.isOpen()) { switch (level) { case 0: lv.loadLv0(); break; } while (playing) { input.ExecuteEvents(window); pad.Update(); window.clear(); // ------draw graphics here------- sf::Text text("Score: " + std::to_string(score), font, 20); text.setPosition(660, 220); window.draw(text); lv.Draw(window); window.draw(pad.sprite); window.draw(pad.ball); window.display(); // ----------------------- } } return 0; }
/** Dump the output sets to the DBMS. (FIXME: dumping SQL to a file instead; see dump())*/ void dump_outputsets(std::ostream &dbc) const { for (size_t i=0; i<levels.size(); ++i) { for (Vertices::const_iterator vi=levels[i].vertices.begin(); vi!=levels[i].vertices.end(); ++vi) { dbc <<"insert into outputsets (id) values (" <<(*vi)->id <<");\n"; for (OutputValues::const_iterator ni=(*vi)->outputs.begin(); ni!=(*vi)->outputs.end(); ++ni) dbc <<"insert into outputvalues (outputset_id, val) values (" <<(*vi)->id <<", " <<*ni <<");\n"; } } }
void printMe() { cout << "========================== UKS ==============================" << endl; cout << " --- Maxes --- " << endl << " "; for (int k = 0; k < maxes.size(); ++k) { cout << " " << maxes[k]; } cout << " --- Mins --- " << endl << " "; for (int k = 0; k < mins.size(); ++k) { cout << " " << mins[k]; } cout << " --- Range size --- " << endl << " "; for (int k = 0; k < range_size.size(); ++k) { cout << " " << range_size[k]; } cout << endl; cout << " ==== STATES ==== " << endl; for (int i = 0; i < states.size(); ++i) { TSStateProperty s = states[i]; cout << " State: " << s.ID << endl; cout << " - Levels: "; for (int k = 0; k < s.levels.size(); ++k) { cout << " " << s.levels[k]; } cout << endl; cout << " - Transitions: " << endl; for (int j = 0; j < s.transitions.size(); ++j) { TSTransitionProperty tr = s.transitions[j]; cout << " " << j << " Target: " << tr.target_ID << " step_size: " << tr.trans_const.step_size << " req_dir: " << tr.trans_const.req_dir << " comp_value: " << tr.trans_const.comp_value << endl; cout << " Targets: "; for (int k = 0; k < tr.trans_const.targets.size(); ++k) { cout << " " << tr.trans_const.targets[k]; } cout << endl; } } }
inline StateID getID(const Levels & levels) const { StateID result = 0; size_t factor = 1; for (size_t lvl_no = 0; lvl_no < levels.size(); lvl_no++) { result += (levels[lvl_no] - mins[lvl_no]) * factor; factor *= (range_size[lvl_no]); } return result; }
/** Returns the set of all leaf nodes in the forest. */ Vertices get_leaves() const { Vertices retval; for (size_t i=0; i<levels.size(); ++i) { const Vertices &vertices = vertices_at_level(i); for (Vertices::const_iterator vi=vertices.begin(); vi!=vertices.end(); ++vi) { if ((*vi)->children.empty()) retval.insert(*vi); } } return retval; }
StateID UnparametrizedStructure::computeID(const Levels & levels) const { StateID result = 0; size_t factor = 1; for (size_t lvl_no = 0; lvl_no < levels.size(); lvl_no++) { result += (levels[lvl_no] - get<0>(_bounds)[lvl_no]) * factor; factor *= (get<2>(_bounds)[lvl_no]); } return result; }
/** * Compute a vector of maximal levels and store information about states. */ void computeBoundaries() { // Compute naive bounds. for (const SpecieID ID : cscope(model.species)) { // Maximal values of species names.push_back(model.species[ID].name); maxes.push_back(model.species[ID].max_value); mins.push_back(0); } // Add experiment constraints. ConstraintParser * cons_pars = new ConstraintParser(model.species.size(), ModelTranslators::getMaxLevel(model)); cons_pars->addBoundaries(maxes, true); cons_pars->applyFormula(ModelTranslators::getAllNames(model), property.getExperiment()); cons_pars->status(); // Compute refined boundaries. mins = cons_pars->getBounds(false); maxes = cons_pars->getBounds(true); rng::transform(maxes, mins, back_inserter(range_size), [](const ActLevel max, const ActLevel min) { return max - min + 1; }); }
/** Dump inputsets to the DBMS. (FIXME: dumping SQL to a file instead; see dump()) */ void dump_inputsets(std::ostream &dbc) const { for (size_t i=0; i<levels.size(); ++i) { dbc <<"insert into inputsets (id) values(" <<i <<");\n"; const std::vector<uint64_t> &pointers = levels[i].inputs.get_pointers(); for (size_t j=0; j<pointers.size(); ++j) dbc <<"insert into inputvalues (inputset_id, vtype, pos, val)" <<" values (" <<i <<", 'P', " <<j <<", " <<pointers[j] <<");\n"; const std::vector<uint64_t> &integers = levels[i].inputs.get_integers(); for (size_t j=0; j<integers.size(); ++j) dbc <<"insert into inputvalues (inputset_id, vtype, pos, val)" <<" values (" <<i <<", 'N', " <<j <<", " <<integers[j] <<");\n"; } }
/** Insert a function into a vertex of the forest, or create a new vertex. The (new) vertex into which the function was * inserted is either a child of @p parent or a root node. The @p outputs are used to select the vertex into which the * function is inserted (all functions of a particular vertex produced the same output when run with the same input). */ void insert(SgAsmFunction *func, OutputValues outputs, PartitionForest::Vertex *parent) { Vertices candidates = parent ? parent->children : vertices_at_level(0); assert(!contains(candidates, func)); for (Vertices::iterator vi=candidates.begin(); vi!=candidates.end(); ++vi) { Vertex *vertex = *vi; if (outputs.size()==vertex->outputs.size() && std::equal(outputs.begin(), outputs.end(), vertex->outputs.begin())) { vertex->functions.insert(func); return; } } size_t lno = parent ? parent->get_level() + 1 : 0; assert(lno<levels.size()); levels[lno].vertices.insert(new Vertex(parent, func, outputs)); }
TEST(Levels, load_npz) { Levels l; l.addPath("data/C10_Standard.npz"); ASSERT_EQ(9, l.numLevels()); ASSERT_STREQ("plane sailing", l.levelName(0).c_str()); ASSERT_STREQ("the leap", l.levelName(1).c_str()); ASSERT_STREQ("nautilus", l.levelName(8).c_str()); ASSERT_EQ(1, l.numCollections()); ASSERT_EQ(9, l.collectionSize(0)); int indexInCol; ASSERT_EQ(0, l.collectionFromLevel(0, &indexInCol)); ASSERT_EQ(0, indexInCol); ASSERT_EQ(0, l.collectionFromLevel(1, &indexInCol)); ASSERT_EQ(1, indexInCol); }
LevelSelector(GameControl* game, int initialLevel) : m_game(game), m_levels(game->m_levels), m_collection(0), m_dispbase(0), m_dispcount(0) { m_scroll = new ScrollArea(); m_scroll->fitToParent(true); m_scroll->virtualSize(Vec2(SCREEN_WIDTH,SCREEN_HEIGHT)); m_content->add(m_scroll,0,0); fitToParent(true); int levelInC; m_collection = m_levels->collectionFromLevel(initialLevel,&levelInC); setCollection(m_collection, levelInC); }
/** Create a new (empty) level. This is the level into which the next higher level's vertices will be partitioned. The * return value is the new level number. */ size_t new_level(const InputValues &inputs) { levels.push_back(Level(inputs)); return levels.size()-1; }
void setCollection(int c, int levelInC) { if (c < 0 || static_cast<unsigned int>(c) >=m_levels->numCollections()) { return; } m_collection = c; m_dispbase = 0; m_dispcount = m_levels->collectionSize(c); m_scroll->virtualSize(Vec2(SCREEN_WIDTH,150+(SCREEN_HEIGHT/ICON_SCALE_FACTOR+40)*((m_dispcount+2)/3))); m_scroll->empty(); Box *vbox = new VBox(); vbox->add( new Spacer(), 10, 0 ); Box *hbox = new HBox(); Widget *w = new Button("<<",Event::PREVIOUS); w->border(false); hbox->add( w, BUTTON_WIDTH, 0 ); hbox->add( new Spacer(), 10, 0 ); Label *title = new Label(m_levels->collectionName(c)); title->font(Font::headingFont()); title->alpha(100); hbox->add( title, BUTTON_WIDTH, 4 ); w= new Button(">>",Event::NEXT); w->border(false); hbox->add( new Spacer(), 10, 0 ); hbox->add( w, BUTTON_WIDTH, 0 ); vbox->add( hbox, 64, 0 ); vbox->add( new Spacer(), 10, 0 ); hbox = new HBox(); hbox->add( new Spacer(), 0, 1 ); int accumw = 0; for (int i=0; i<m_dispcount; i++) { accumw += SCREEN_WIDTH / ICON_SCALE_FACTOR + 10; if (accumw >= SCREEN_WIDTH) { vbox->add(hbox, SCREEN_HEIGHT/ICON_SCALE_FACTOR+30, 4); vbox->add( new Spacer(), 10, 0 ); hbox = new HBox(); hbox->add( new Spacer(), 0, 1 ); accumw = SCREEN_WIDTH / ICON_SCALE_FACTOR; } m_thumbs[i] = new IconButton("--","",Event(Event::PLAY, //SELECT, m_levels->collectionLevel(c,i))); m_thumbs[i]->font(Font::blurbFont()); m_thumbs[i]->setBg(SELECTED_BG); m_thumbs[i]->border(false); hbox->add( m_thumbs[i], SCREEN_WIDTH / ICON_SCALE_FACTOR, 0 ); hbox->add( new Spacer(), 0, 1 ); } vbox->add(hbox, SCREEN_HEIGHT/ICON_SCALE_FACTOR+30, 4); vbox->add( new Spacer(), 110, 10 ); m_scroll->add(vbox,0,0); for (int i=0; i<THUMB_COUNT && i+m_dispbase<m_dispcount; i++) { Canvas temp( SCREEN_WIDTH, SCREEN_HEIGHT ); Scene scene( true ); unsigned char buf[64*1024]; int level = m_levels->collectionLevel(c,i); int size = m_levels->load( level, buf, sizeof(buf) ); if ( size && scene.load( buf, size ) ) { scene.draw( temp, FULLSCREEN_RECT ); m_thumbs[i]->text( m_levels->levelName(level) ); m_thumbs[i]->canvas( temp.scale( ICON_SCALE_FACTOR ) ); m_thumbs[i]->transparent(m_dispbase+i!=levelInC); } } }
/** Returns the number of levels in the partition forest. Levels are numbered starting at zero. The return value is one * more than the maximum level that contains a vertex. */ size_t nlevels() const { return levels.size(); }
TEST(Levels, empty) { Levels l; ASSERT_EQ(0, l.numLevels()); ASSERT_EQ(string("err"), l.levelName(0, false)); ASSERT_EQ(string("err"), l.levelName(0, true)); ASSERT_LT(l.findLevel("non-existent"), 0); ASSERT_EQ(0, l.numCollections()); ASSERT_LT(l.collectionFromLevel(0), 0); ASSERT_EQ(0, l.collectionSize(0)); ASSERT_EQ(0, l.collectionSize(1)); ASSERT_EQ(0, l.collectionLevel(0, 0)); ASSERT_FALSE(l.demoPath(0).empty()); ASSERT_FALSE(l.demoName(0).empty()); ASSERT_FALSE(l.hasDemo(0)); }
/** Return the list of vertices at a given level of the forest. */ const Vertices& vertices_at_level(size_t level) const { assert(level<levels.size()); return levels[level].vertices; }
int main(int argc, char* argv[]) { sf::RenderWindow WINDOW(sf::VideoMode(1280, 720, 32), "Arctic", sf::Style::Close); WINDOW.SetFramerateLimit(60); Levels* levels; levels->setLevels(); sf::Clock clock; float time = clock.GetElapsedTime(); state = Ingame; prevState = Menu; /* Main Menu Buttons */ BUTTON play(440, 200, "PLAY"); BUTTON options(440, 320, "OPTIONS"); BUTTON quit(440, 440, "QUIT"); /* Pause Buttons */ BUTTON resume(440, 200, "RESUME"); BUTTON pauseOptions(440, 320, "OPTIONS"); BUTTON quitToMenu(440, 440, "QUIT TO MENU"); /* Strings */ STRING str("Arctic - Sprite Testing", 5, 2, sf::Color(255, 255, 255)); while(WINDOW.IsOpened()) { sf::Event event; sf::Vector2i mouse(WINDOW.GetInput().GetMouseX(), WINDOW.GetInput().GetMouseY()); time = clock.GetElapsedTime(); while(WINDOW.GetEvent(event)) { switch(event.Type) { case sf::Event::Closed: WINDOW.Close(); break; case sf::Event::KeyPressed: if(event.Key.Code == sf::Key::Escape) { if(state == Menu) { WINDOW.Close(); } else if(state == Ingame) { state = Paused; prevState = Ingame; } else if(state == Options) { state = prevState; prevState = Options; } else if(state == Paused) { state = prevState; prevState = Paused; } } if(event.Key.Code == sf::Key::Space) { for(int i = 0; i < ice.size(); i++) { if(ice[i]->state != Ice::IceState::Rock) { ice[i]->state = Ice::IceState::Reg; } } } break; case sf::Event::MouseButtonReleased: if(event.MouseButton.Button == sf::Mouse::Button::Left) { if(state == Menu) { if(play.contains(mouse)) { state = Ingame; } else if(options.contains(mouse)) { state = Options; prevState = Menu; } else if(quit.contains(mouse)) { WINDOW.Close(); } } else if(state == Paused) { if(resume.contains(mouse)) { state = Ingame; } else if(pauseOptions.contains(mouse)) { state = Options; prevState = Paused; } else if(quitToMenu.contains(mouse)) { state = Menu; prevState = Paused; } } } break; } } WINDOW.Clear(sf::Color(80, 80, 80, 0)); /* DRAWING CODE */ if(state == Ingame) { /* Tiles */ levels->draw(currentLevel, WINDOW); /* HUD Elements */ str.Draw(WINDOW); } else if(state == Menu) { play.Draw(WINDOW); options.Draw(WINDOW); quit.Draw(WINDOW); play.Update(mouse); options.Update(mouse); quit.Update(mouse); } else if(state == Options) { } else if(state == Paused) { resume.Draw(WINDOW); pauseOptions.Draw(WINDOW); quitToMenu.Draw(WINDOW); resume.Update(mouse); pauseOptions.Update(mouse); quitToMenu.Update(mouse); } /* END OF DRAWING */ WINDOW.Display(); } return EXIT_SUCCESS; }