Exemple #1
0
void MalcevSet::checkMembership(PolyWord& remainder) const {

  while( ! remainder.isEmpty() && theSet.bound( leader(remainder) ) ) {
    PolyWord curWord = theSet.valueOf( leader(remainder) );
    if( absPower(remainder) % absPower(curWord) != 0 ) 
      break;

    // The rest can be reduced. Do it.
    reduceWords( curWord, remainder );
  }
}
Exemple #2
0
int cmd_party(string str) {
    string com, extra;
/*    if(wizardp(this_player())) return 0;  */
    if(!str) {
        help();
        return 1;
    }
    if(sscanf(str, "%s %s", com, extra) == 2) {
        switch(com) {
            case "form": return form(extra); break;
            case "leave": return leave(); break;
            case "join": return join_party(extra); break;
            case "add": return add_member(extra); break;
            case "remove": return sub(extra); break;
            case "leader": return leader(extra); break;
            case "list": return list(); break;
            case "line": return party_line(extra); break;
            default: help(); return 1; break;
        }
    }
    else {
        if(str == "leave") return leave();
        else if(str == "list") return list();
        else {
            help();
            return 1;
        }
    }
}
Exemple #3
0
void World::buildScene()
{
    for (std::size_t i = 0; i < LayerCount; ++i)
    {
        SceneNode::Ptr layer(new SceneNode());
        mSceneLayers[i] = layer.get();

        mSceneGraph.attachChild(std::move(layer));
    }

    sf::Texture& texture = mTextures.get(Textures::ID::Desert);
    sf::IntRect textureRect(mWorldBounds);
    texture.setRepeated(true);

    std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
    backgroundSprite->setPosition(mWorldBounds.left, mWorldBounds.top);
    mSceneLayers[Layer::Background]->attachChild(std::move(backgroundSprite));

    std::unique_ptr<Aircraft> leader(new Aircraft(Aircraft::Type::Eagle, mTextures));
    mPlayerAircraft = leader.get();
    mPlayerAircraft->setPosition(mSpawnPosition);
    mPlayerAircraft->setVelocity(0.f, mScrollSpeed);
    mSceneLayers[Layer::Air]->attachChild(std::move(leader));

    std::unique_ptr<Aircraft> leftEscort(new Aircraft(Aircraft::Type::Raptor, mTextures));
    leftEscort->setPosition(-80.f, 50.f);
    mPlayerAircraft->attachChild(std::move(leftEscort));
    
    std::unique_ptr<Aircraft> rightEscort(new Aircraft(Aircraft::Type::Raptor, mTextures));
    rightEscort->setPosition(80.f, 50.f);
    mPlayerAircraft->attachChild(std::move(rightEscort));
}
Exemple #4
0
	void build_team_stage_one()
	{
		//initialize the context variables and flags, find relevant tags, set up everything
		init();

		//find out the correct qty of gold and handle gold carryover.
		gold();

		//create a new instance of team and push it to back of resources::teams vector
		new_team();

		assert(t_!=NULL);

		//set team objectives if necessary
		objectives();

		// If the game state specifies additional units that can be recruited by the player, add them.
		previous_recruits();

		//place leader
		leader();

		//prepare units, populate obvious recall lists elements
		prepare_units();

	}
void World::buildScene() {
    // Initialize the different layers
    for (std::size_t i = 0; i < Layer::count; i++) {
        SceneNode::Ptr layer(new SceneNode());
        sceneLayers[i] = layer.get();
        sceneGraph.attachChild(std::move(layer));
    }

    // Prepare the title background
    sf::Texture &texture = textures.get(Textures::Desert);
    sf::IntRect textureRect(worldBounds);
    texture.setRepeated(true);

    // Add the background sprite to the scene
    std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
    backgroundSprite->setPosition(worldBounds.left, worldBounds.top);
    sceneLayers[Background]->attachChild(std::move(backgroundSprite));

    // Add player's aircraft
    std::unique_ptr<Aircraft> leader(new Aircraft(Aircraft::Eagle, textures));
    playerAircraft = leader.get();
    playerAircraft->setPosition(spawnPosition);
    playerAircraft->setVelocity(40.f, scrollSpeed);
    sceneLayers[Air]->attachChild(std::move(leader));

    // Add two escorting aircrafts, placed relatively to the main plane
    std::unique_ptr<Aircraft> leftEscort(new Aircraft(Aircraft::Raptor, textures));
    leftEscort->setPosition(-80.f, 50.f);
    playerAircraft->attachChild(std::move(leftEscort));
    std::unique_ptr<Aircraft> rightEscort(new Aircraft(Aircraft::Raptor, textures));
    rightEscort->setPosition(80.f, 50.f);
    playerAircraft->attachChild(std::move(rightEscort));
}
Exemple #6
0
// adds w to the set
// returns true iff the set was changed
bool MalcevSet::addWord( const PolyWord& pw ) {

  bool wasChanged = false;
  PolyWord remainder = collect(pw);

  while( ! remainder.isEmpty() ) {
    Generator key = leader(remainder);

    // if there is no word with the same leader, include the remainder to the set

    if( ! theSet.bound(key) ) {
      theSet.bind( key, remainder );
      isBasis = false;
      isNormal = dontknow;
      return true;
    }

    // reduce the remainder

    PolyWord currentWord = theSet.valueOf(key);

    if( reduceWords( currentWord, remainder) ) {
      theSet.bind( key, currentWord );
      isBasis = false;
      isNormal = dontknow;
      wasChanged = true;
    }
  }
  return wasChanged;
}
Exemple #7
0
void restpolynomial::shift(int i){
    rest z(leader().mod);

   if (i > 0){
     for (int d =1 ; d<=i;d++){
         mons.push_front(z);
     }
   }
}
int main(int argc,char** argv){
		int found = 0, arrived_home = 0;
		int use_http = 0;
		char address[200];
		int port = 55555;
		strcpy(address, "localhost");
    
		if(argc >= 4){
            use_http = atoi(argv[1]);
            strncpy(address, argv[2], 200);
            port = atoi(argv[3]);
		}else{
            printf("[INFO] Usage: 'prog 1 address port' to start it with http connection\n");
		}

	    //initalization
		init(use_http, address, port);
	  
		//install signal handler to exit gently
		signal(SIGINT,sigint_handler);
    
		//scheduling
		while(!end_game && !arrived_home){
			if(robot_rank == 0){
				// Leader mode
				if(found == 0){ 
					found = leader();
                }else{
                    arrived_home = go_back_home();
                    send_lead(next);
                }
            }else{
                 // Follower mode
                 while(robot_rank > 0 && !end_game){
					follower();
				 }//######################aggiunger end game e stop anche nel leader e go back home etc
                 //follower call back called at each action messagge
            }
		}

		if(end_game){
            printf("[STATUS] Game ended\n");
		}else{
            printf("[STATUS] Back home\n");
		}
       
		reset_motors();
		destroy_sensors(); 
		destroy_motors();
		destroy_bluetooth();
		free(positions);
}
Exemple #9
0
void Client::updateLeader(xcb_connection_t* conn, xcb_get_property_cookie_t cookie)
{
    AutoPointer<xcb_get_property_reply_t> leader(xcb_get_property_reply(conn, cookie, 0));
    if (!leader || leader->type != XCB_ATOM_WINDOW || leader->format != 32 || !leader->length) {
        mGroup = ClientGroup::clientGroup(mWindow);
        mGroup->add(this);
        return;
    }

    const xcb_window_t win = *static_cast<xcb_window_t *>(xcb_get_property_value(leader));
    mGroup = ClientGroup::clientGroup(win);
    mGroup->add(this);
}
CString CompPinStruct::getSortableReference(const CString& reference)
{
   const char* p = reference;
   CString alpha;
   CString numeric;
   CString suffix;

   while (*p != '\0')
   {
      if (isdigit(*p))
      {
         break;
      }

      alpha += *(p++);
   }

   while (*p != '\0')
   {
      if (!isdigit(*p))
      {
         break;
      }

      numeric += *(p++);
   }

   suffix = p;

   CString leader("00000000");
   CString trailer("        ");

   alpha   += trailer;
   numeric  = leader + numeric;
   suffix  += trailer;

   CString sortableReference = alpha.Left(8) + numeric.Right(8) + suffix.Left(8);

   // Case dts0100408077 - The general construction of sortableRefDes as above causes 
   // collisions for refnames like C3 and C03, they both result in the same value.
   // Some features build component maps based on the sortableRefDes, and they are dropping entities when
   // such name collisions occur. So here we tack the original refname onto the end, thus making them
   // unique again. This keeps intact the basic overall "numerical" sorting portion of the game.
   sortableReference += "|" + reference;

   return sortableReference;
}
Exemple #11
0
int main(int argc, char **argv)
{
	init_raft(argv[1]);

	while (1) {
		switch (role) {
		case FOLLOWER:
			follower();
			break;
		case CANDIDATE:
			candidate();
			break;
		case LEADER:
			leader();
			break;
		default:
			break;
		}
	}
	return 0;
}
void World::buildScene()
{
	for (int i = 0; i < LayerCount; i++)
	{
		SceneNode::Ptr layer(new SceneNode());
		sceneLayers[i] = layer.get();
		sceneGraph.attachChild(std::move(layer));
	}
	
	sf::Texture& texture = data->rscStorage.getTextureRef("land");
	sf::IntRect textureRect(worldBounds);
	texture.setRepeated(true);
	
	unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
	backgroundSprite->setPosition(worldBounds.left, worldBounds.top);
	sceneLayers[Background]->attachChild(std::move(backgroundSprite));
	
	unique_ptr<Character> leader(new Character("greenalien", &data->animStorage));
	playerCharacter = leader.get();
	playerCharacter->setPosition(spawnPosition);
	playerCharacter->setVelocity(100.f, 0.f);
	sceneLayers[Surface]->attachChild(std::move(leader));
}
Exemple #13
0
void Vxls::insertSpillsAt(smart::vector<Vinstr>& code, unsigned& j,
                          const CopyPlan& spills, MemoryRef slots,
                          unsigned pos) {
  smart::vector<Vinstr> stores;
  for (auto src : spills) {
    auto ivl = spills[src];
    if (!ivl) continue;
    auto slot = ivl->leader()->slot;
    assert(slot >= 0 && src == ivl->reg);
    MemoryRef ptr{slots.r + PhysLoc::disp(slot)};
    if (src.isGP()) {
      stores.emplace_back(store{src, ptr});
    } else {
      // todo: t4764214: not all xmms are wide.
      stores.emplace_back(storedqu{src, ptr});
    }
  }
  code.insert(code.begin() + j, stores.size(), ud2{});
  for (auto& inst : stores) {
    code[j] = inst;
    code[j++].pos = pos;
  }
}
Exemple #14
0
void World::buildScene()
{
	// Initialize the different layers
	for (std::size_t i = 0; i < LayerCount; ++i)
	{
		SceneNode::Ptr layer(new SceneNode());
		mSceneLayers[i] = layer.get();

		mSceneGraph.attachChild(std::move(layer));
	}

	// Prepare the tiled background
	sf::Texture& texture = mTextures.get(Textures::Background);
	sf::IntRect textureRect(mWorldBounds);
	texture.setRepeated(true);

	// Add the background sprite to the scene
	std::unique_ptr<SpriteNode> backgroundSprite(new SpriteNode(texture, textureRect));
	backgroundSprite->setPosition(mWorldBounds.left, mWorldBounds.top);
	mBackgroundSprite = backgroundSprite.get();
	mSceneLayers[Background]->attachChild(std::move(backgroundSprite));


	// Add player's spaceship
	std::unique_ptr<Spaceship> leader(new Spaceship(Spaceship::Rocket, mTextures));
	mPlayerSpaceship = leader.get();
	mPlayerSpaceship->setPosition(mSpawnPosition);
	mSceneLayers[Space]->attachChild(std::move(leader));

	mBattlifieldBounds.setSize(sf::Vector2f(getBattlefieldBounds().width, getBattlefieldBounds().height));
	mBattlifieldBounds.setPosition(getBattlefieldBounds().left, getBattlefieldBounds().top);
	mBattlifieldBounds.setFillColor(sf::Color::Transparent);
	mBattlifieldBounds.setOutlineThickness(2.f);
	mBattlifieldBounds.setOutlineColor(sf::Color::Green);

	initialText();
}
Exemple #15
0
void Cocklebur::process() {

    CockLeaderElection cockLeaderElection(this);
    Leader leader(this);
    startCockServer( &leader );

    while(true) {

	switch( d_cur_node_mode ) { 

	case LOOKING:
	    cout<<"_DEBUG: Enter looking process."<<endl;
	    cockLeaderElection.lookForLeader(); 
	    break;
	case FOLLWING:
	    cout<<"_DEBUG: Enter following process."<<endl;
	    // apply lease from leader
	    {
		Follower follower(this);
		follower.following();
	    }
	    break;
	case LEADERING:
	    cout<<"_DEBUG: Enter leadering process."<<endl;
	    // recevie heartbeat from followers and observers
	    {
		leader.reset();
		leader.leadering();
	    }
	    break;
	default:
	    cout<<"_DEBUG: No match mode for "<<d_cur_node_mode<<endl;
	    break;
	}
    }
}
	virtual void run()
	{
        WIN32_FILE_ATTRIBUTE_DATA follower_attrs = {};
		if (!GetFileAttributesEx(m_followerPath.c_str(), GetFileExInfoStandard, &follower_attrs)) {
			printf("GetFileAttributesEx() failed: %d\n", GetLastError());
            m_logger.log(L"GetFileAttributesEx() failed", GetLastError() );
			return;
		}
		if (CompareFileTime(&follower_attrs.ftLastWriteTime, &m_lastModified) != 0) {
            WIN32_FILE_ATTRIBUTE_DATA leader_attrs = {};
			if (!GetFileAttributesEx(m_leaderPath.c_str(), GetFileExInfoStandard, &leader_attrs)) {
				printf("GetFileAttributesEx() failed: %d\n", GetLastError());
                m_logger.log(L"GetFileAttributesEx() failed", GetLastError() );
			}
			if (CompareFileTime(&leader_attrs.ftLastWriteTime, &follower_attrs.ftLastWriteTime) != 0) {
				if (!CopyFile(m_followerPath.c_str(),m_leaderPath.c_str(),FALSE)) {
					printf("CopyFile() failed: %d\n", GetLastError());
                    m_logger.log(L"CopyFile() failed", GetLastError() );
				} else {
					// Mirror the write time.
					auto_handle leader(CreateFile(m_leaderPath.c_str(), FILE_WRITE_ATTRIBUTES, 0,
                                                      NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
					if (INVALID_HANDLE_VALUE != leader.get()) {
						if (!SetFileTime(leader.get(), NULL, NULL, &follower_attrs.ftLastWriteTime)) {
							printf("SetFileTime() failed: %d\n", GetLastError());
                            m_logger.log(L"SetFileTime() failed", GetLastError());
						}
					} else {
						printf("CreateFile() failed: %d\n", GetLastError());
                        m_logger.log(L"CreateFile() failed", GetLastError() );
					}
				}
			}
		}
		m_lastModified = follower_attrs.ftLastWriteTime;
	}
Exemple #17
0
DSN_API dsn_address_t dsn_group_forward_leader(dsn_group_t g)
{
    auto grp = (::dsn::rpc_group_address*)(g);
    grp->leader_forward();
    return grp->leader().c_addr();
}
Exemple #18
0
DSN_API bool dsn_group_is_leader(dsn_group_t g, dsn_address_t ep)
{
    auto grp = (::dsn::rpc_group_address*)(g);
    return grp->leader() == ep;
}
Exemple #19
0
bool MalcevSet::decomposeWord(const PolyWord& w, PolyWord& decomp) const {

  if( ! isBasis )
    error("Attempt to use MalcevSet::decomposeWord before the set is full.");

  PolyWord remainder = theCollector.collect(w);
  decomp = PolyWord();

  // try to decompose the remainder

  while( ! remainder.isEmpty() && theSet.bound( leader(remainder) ) ) {
    PolyWord divisor = theSet.valueOf( leader(remainder) );
    if( absPower(remainder) % absPower(divisor) != 0 ) 
      break;

    // The remainder can be reduced. Do it.
    int divPower = power(remainder) / power(divisor);
    decomp.append( Letter( leader(remainder), divPower ) );

    if( divPower < 0 ) {
      divPower = - divPower;
    }
    else {
      divisor = theCollector.inverse(divisor);
    }

    for(int i = 0; i < divPower; i++) {
      remainder = theCollector.multiply(divisor, remainder);
    }

  }

  // if the remainder cannot be decomposed

  if( ! remainder.isEmpty() ) {
    decomp = PolyWord();
    return false;
  }
  
  // if the remainder initially was empty

  if( decomp.isEmpty() ) return true;

  // initially decomp is a series of letters (gen, power),
  // where gen is a leader of decomposition component and
  // power is its power

  // now translate decomp to Malcev basis terms: replace
  // gen with index of basis word having leader gen

  int curElement = 0;   // index of current basis element

  PolyWordIterator iter(decomp);
  iter.startFromLeft();

  for( int c = 1; c <= theCollector.commutators().theHirschNumber(); c++ ) {
    Generator theLeader(c);
    if( ! theSet.bound(theLeader) ) continue;
    ++curElement;

    if( iter.thisLetter().gen == theLeader ) {
      iter.thisLetter().gen = Generator(curElement);
      iter.stepRight();
      if( iter.done() ) break;
    }
  }
  return true;
}
Exemple #20
0
/* method to reset the progress */
void Levels::resetLevels()
{
    QString path = QDir::currentPath() + "/levels.txt";
    QFile * newFile = new QFile(path);
    QFile * file = new QFile(":/assets/Levels/levels.txt");
    QTextStream stream(newFile);
    QString line;
    QStringList list;
    levelArray.clear();
    /* boolean gets set if the newFile already exists*/
    //bool fileExists = newFile->exists();
    vector <int> rowVector(2);
    int row = 0;
    if(!file->open(QIODevice::ReadOnly| QIODevice::Text))
    {
        qDebug()<< "error opening levels";
        return;
    }

    if(newFile->open(QIODevice::ReadWrite | QIODevice::Text))
    {
        /*write all the content of file in newFile*/
        QTextStream in(file);
        QString leaderPath;

        while (!in.atEnd())
        {
            line = in.readLine();
            stream << line;
            stream << endl;

            row++;
            /* create leaderboard file for each level */
            leaderPath= QDir::currentPath() + "/leaderboard"+QString::number(row)+ ".txt";
            QFile * leaderBoard = new QFile(leaderPath);
            QTextStream leader(leaderBoard);
            /* opening a file that doesn't exist yet will creat this file */
            if(leaderBoard->open(QIODevice::WriteOnly | QIODevice::Text))
            {
              leader << endl;

            }
            leaderBoard->close();
        }
        stream.seek(0);
        row = 0;
        /*add the content of newFile to the levelArray*/
        while (!stream.atEnd())
        {
            line = stream.readLine();
            if (!line.isEmpty()&&!line.isNull()){
                list=line.split(" ");
                levelArray.push_back(rowVector);
                for(int col = 0; col < 2; col++){
                    levelArray[row][col] = list.at(col).toInt();
                }
                row++;
            }
        }
    }
    file->close();
    newFile->close();
}