Example #1
0
	//a pointer to the list that will hold the player's letters.
	list<string> *getTiles(int howManyTiles)
	{
		//create a new list for the player to hold his/her letters.
		list<string> *tilesToSend = new list<string>();
		
		//check if the letters needed by the player are less than the letters in the sack(letterList).
		if(letterList->size() >= howManyTiles)
		{
			//take out one letter at a time from the sack(letterList).
			for(int i = 1 ; i<= howManyTiles ; i++)
			{
				//a pointer to the sack(letterList).
				list<string> *iter = FirstInstance->letterList;
				
				//get the first letter from the sack and add it to player's list.
				tilesToSend->push_back((*(*iter).begin()));
				
				//delete that letter from the sack(letterList).
				letterList->erase(letterList->begin());
			}
			
			return tilesToSend;
		}
		
		else 
		{
			cout<<"Not Enough Tiles"<<endl;
			return NULL;
		}
		
	}
Example #2
0
                RegExp(long unsigned int currentSatProcess, RegExpDag * d, reg_exp_type t, reg_exp_t r1, reg_exp_t r2 = 0) {
                    count = 0;
                    nevals = 0;
                    if(t == Extend || t == Combine) {
                        type = t;
                        assert(r1.get_ptr() != 0 && r2.get_ptr() != 0);
                        value = r1->value->zero();
                        children.push_back(r1);
                        children.push_back(r2);
                    } else if(t == Star) {
                        type = Star;
                        assert(r1.get_ptr() != 0);
                        value = r1->value->zero();
                        children.push_back(r1);
                    } else {
                        assert(0);
                    }
#if defined(PUSH_EVAL)
                    // Not thread safe? Constructor isn't done yet, and some
                    // outside has a pointer to the object.
                    // (pprabhu, 2/20/2013): The best solution I know is to create an init() and
                    // call init after the constructor. To heavy handed to implement right now.
                    dirty = true;
                    r1->parents.insert(static_cast<RegExp*>(this));
                    if(!(r2 == NULL))
                      r2->parents.insert(static_cast<RegExp*>(this));
#endif
                    last_change = 0;
                    last_seen = 0;
                    uptodate = false;
                    samechange = differentchange = 0;
                    lastchange=-1;
                    satProcess = currentSatProcess;
                    dag = d;
                }
Point MissionPanel::DrawList(const list<Mission> &list, Point pos) const
{
	const Font &font = FontSet::Get(14);
	Color highlight = *GameData::Colors().Get("faint");
	Color unselected = *GameData::Colors().Get("medium");
	Color selected = *GameData::Colors().Get("bright");
	Color dim = *GameData::Colors().Get("dim");
	
	for(auto it = list.begin(); it != list.end(); ++it)
	{
		if(!it->IsVisible())
			continue;
		
		pos.Y() += 20.;
		
		bool isSelected = (it == availableIt || it == acceptedIt);
		if(isSelected)
			FillShader::Fill(
				pos + Point(.5 * SIDE_WIDTH - 5., 8.),
				Point(SIDE_WIDTH - 10., 20.),
				highlight);
		
		bool canAccept = (&list == &available ? it->HasSpace(player) : IsSatisfied(*it));
		font.Draw(it->Name(), pos,
			(!canAccept ? dim : isSelected ? selected : unselected));
	}
	
	return pos;
}
Example #4
0
void makeGrid( const Pt3dr &aP0, const Pt3dr &aSize, unsigned int aPointsPerAxis, const cMasqBin3D &aMask, list<Pt3dr> &oPoints )
{
	ELISE_DEBUG_ERROR(aSize.x <= 0. || aSize.y <= 0. || aSize.z <= 0., "makeGrid", "invalid box size = " << aSize);

	oPoints.clear();
	if (aPointsPerAxis == 0) return;

	Pt3dr pace = aSize / (REAL)(aPointsPerAxis - 1), p;
	const Pt3dr p1 = aP0 + aSize;
	REAL z = aP0.z;
	while (z <= p1.z)
	{
		REAL y = aP0.y;
		while (y <= p1.y)
		{
			REAL x = aP0.x;
			while (x <= p1.x)
			{
				p.x = x;
				p.y = y;
				p.z = z;
				if (aMask.IsInMasq(p)) oPoints.push_back(p);

				x += pace.x;
			}
			y += pace.y;
		}
		z += pace.z;
	}
}
Example #5
0
void Dodaj::wykonaj(list<string> param)
{
	map<string, Polecenie*>::iterator iterMap;
	iterMap = Parser::getInstance()->Polecenia.begin();
	list<string>::iterator iterList = param.begin();
	if (param.size() != 3)
	{
		cout << "   Zle parametry lub niewlasciwa ich ilosc" << endl;
		Dodaj::pomoc();
	}
	else
	{
		int licznikId = Kartoteka::getInstance()->getLicznikId();
		Osoba ludzik;
		string imie, nazwisko;
		ludzik.setId(licznikId);
		iterList++;
		ludzik.setImie(*iterList);
		iterList++;
		ludzik.setNazwisko(*iterList);
		licznikId++;
		Kartoteka::getInstance()->setLicznikId(licznikId); //dostep do klasy w singletone
		Kartoteka::getInstance()->lista.push_back(ludzik);
		cout << "\nPomyslnie dodano wpis do bazy." << endl;
	}
}
string align_second(string s, list<table_element*> & path)
{
	string s_aligned = "";
	int previous_r, current_r, cnt(0);
	for (list<table_element*>::iterator it=path.begin(); it!=path.end(); it++)
	{
		if (it==path.begin())
		{
			previous_r = (*it)->row;
		}
		else
		{
			current_r = (*it)->row;
			if (current_r==previous_r)
			{
				s_aligned += "_";
			}
			else
			{
				s_aligned += s.at(cnt);
				cnt++;
			}
			previous_r = current_r;
		}
	}
	return s_aligned;
}
Example #7
0
// REMOVES TRIS COINCIDENT WITH PLANE FROM toSPLIT
// AND PLACES THEM IN coincidentTRIS
void removeCoincidentTris( Plane plane, list<PhantomTriangle*> & toSplit, list<PhantomTriangle*> & coincidentTris )
{
  //static Vector call = 0 ;
  //call.y+=.01;
  for( list<PhantomTriangle*>::iterator iter = toSplit.begin() ; iter != toSplit.end() ; )
  {
    PhantomTriangle* pTri = *iter ;
    
    int aV = plane.iSide( pTri->a ) ;
    int bV = plane.iSide( pTri->b ) ;
    int cV = plane.iSide( pTri->c ) ;
    
    // a really bad case is |aV|, |bV|, and |cV| all
    // near 0. this means the points of the triangle are
    // all shavingly close to the plane (ie almost parallel).
    //if( IsNear(aV,0.0,1e-11) && IsNear(bV,0.0,1e-11) && IsNear(cV,0.0,1e-11) )
    if( aV==0&&bV==0&&cV==0 )
    {
      // Do not split this triangle on this plane. take it out.
      coincidentTris.push_back( pTri ) ; 
      //drawTri( call, pTri, Vector(1,0,1) ) ;
      iter = toSplit.erase( iter ) ; // ADVANCES ITER
    }
    else
    {
      //drawTri( call, pTri, Vector(0,0,1) ) ;
      ++iter ;
    }
  }
}
Example #8
0
void GameScene::removeBlock( list<int> blockTags, kBlock blockType )
{
    bool first = true;

    list<int>::iterator it = blockTags.begin();
    while( it != blockTags.end() ) {
        m_blockTags[blockType].remove( *it );
        CCNode* block = m_background->getChildByTag( *it );
        if ( block ) {
            CCScaleTo* scale = CCScaleTo::create( REMOVE_TIME, 0 );
            CCCallFuncN* func = CCCallFuncN::create( this, callfuncN_selector( GameScene::removingBlock ));
            CCFiniteTimeAction* sequence = CCSequence::create( scale, func, NULL );
            CCFiniteTimeAction* action;
            if ( first ) {
                CCPlaySE* playSe = CCPlaySE::create( MP3_REMOVE_BLOCK );
                action = CCSpawn::create( sequence, playSe, NULL );
                first = false;
            } else {
                action = sequence;
            }

            block->runAction( action );
        }
        it++;
    }
    SimpleAudioEngine::sharedEngine()->playEffect( MP3_REMOVE_BLOCK );
}
Example #9
0
void OnReceiveChilds(const int& i, const list<int>& L)
{
    cout << "After node " << i << " expanding one gets";
    for(list<int>::const_iterator n =  L.begin(); n != L.end(); ++n)
        cout << *n << " ";
    cout << '\n';
}
Example #10
0
static void mdlTerminate(SimStruct *S) {
  UNUSED(S);
  if (!lcm) ssSetErrorStatus(S, "Invalid LCM object.");

  lcm_destroy(lcm);
  lcm = NULL;

  char *log_variable_name = mxArrayToString(ssGetSFcnParam(S, 1));

  //  mexPrintf("Writing LCM log with %d records to
  //  %s\n", message_log.size(), log_variable_name);

  const char *fieldnames[] = {"simtime", "channel", "data"};

  mxArray *pData = mxCreateStructMatrix(message_log.size(), 1, 3, fieldnames);

  int i = 0;
  for (list<LCMMessage>::iterator iter = message_log.begin();
       iter != message_log.end(); iter++) {
    mxSetFieldByNumber(pData, i, 0, mxCreateDoubleScalar(iter->simtime));
    mxSetFieldByNumber(pData, i, 1, mxCreateString(iter->channel.c_str()));
    mxSetFieldByNumber(pData, i, 2, iter->data);
    i++;
  }

  mexPutVariable("base", log_variable_name, pData);

  message_log.clear();
  mxFree(log_variable_name);
}
Example #11
0
void NiAlphaController::Write( ostream& out, const map<NiObjectRef,unsigned int> & link_map, list<NiObject *> & missing_link_stack, const NifInfo & info ) const {
    //--BEGIN PRE-WRITE CUSTOM CODE--//
    //--END CUSTOM CODE--//

    NiFloatInterpController::Write( out, link_map, missing_link_stack, info );
    if ( info.version <= 0x0A010000 ) {
        if ( info.version < VER_3_3_0_13 ) {
            WritePtr32( &(*data), out );
        } else {
            if ( data != NULL ) {
                map<NiObjectRef,unsigned int>::const_iterator it = link_map.find( StaticCast<NiObject>(data) );
                if (it != link_map.end()) {
                    NifStream( it->second, out, info );
                    missing_link_stack.push_back( NULL );
                } else {
                    NifStream( 0xFFFFFFFF, out, info );
                    missing_link_stack.push_back( data );
                }
            } else {
                NifStream( 0xFFFFFFFF, out, info );
                missing_link_stack.push_back( NULL );
            }
        }
    };

    //--BEGIN POST-WRITE CUSTOM CODE--//
    //--END CUSTOM CODE--//
}
Example #12
0
int main()
{
   int i, n, tot_len, tmp;
   while(cin >> n && n > 0) {
      stick.clear();
      for(tot_len = i = 0; i < n; i++) {
         cin >> tmp;
         if(tmp > 50) continue;
         tot_len += tmp;
         stick.push_back(tmp);
      }
      if(tot_len == 0) {
         cout << 0 << endl;
         continue;
      }
      stick.sort();
      for(i = 1; i < tot_len; i++) {
         if(tot_len % i != 0) continue;
         yeah = dfs(i, i);
         if(yeah) break;
      }
      cout << i << endl;
   }
   return 0;
}
Example #13
0
list<float> Mochila (int lim_peso, list<Objeto> & objetos) {
    list<float> sol;
    int peso_actual = 0;
    list<Objeto>::iterator rit;

    for (rit=objetos.begin(); rit!=objetos.end() && lim_peso > peso_actual; ++rit) {
        if ((peso_actual + (*rit).peso) <= lim_peso) {
            sol.push_back(1);
            peso_actual += (*rit).peso;
        }

        else {
            float ben = (float)(lim_peso-peso_actual)/((*rit).peso);
            sol.push_back(ben);
            peso_actual = lim_peso;
        }
    }

    while (rit != objetos.end()){
        sol.push_back(0);
        ++rit;
    }

    return sol;
}
Example #14
0
bool ProcessingChainBase::set_plugin_list(const list<Plugin*> &p) {
    if (lists_equal(p, modules, &next_commit_needs_ramp)) {
	return false;
    }
    wait_latch();
    if (check_release()) {
	release();
    }
    typedef set<const char*, stringcomp> pchar_set;
    pchar_set new_ids;
    for (list<Plugin*>::const_iterator i = p.begin(); i != p.end(); ++i) {
	new_ids.insert((*i)->get_pdef()->id);
    }
    for (list<Plugin*>::const_iterator i = modules.begin(); i != modules.end(); ++i) {
	if (!(*i)->get_pdef()->activate_plugin) {
	    continue;
	}
	pchar_set::iterator r = new_ids.find((*i)->get_pdef()->id);
	if (r == new_ids.end()) {
	    to_release.push_back(*i);
	}
    }
    modules = p;
    return true;
}
Example #15
0
void Preprocessor::setSymbols(const list<string>& symbols)
{
    uint nb_symbols = symbols.size();
    this->symbols.resize(nb_symbols);

#ifdef PREPROC_KEEP_ORIGINAL_SYMBOLS
    this->original_symbols.resize(nb_symbols);
#endif

    uint i=0;
    list<string>::const_iterator it_end = symbols.end();

    for(list<string>::const_iterator it = symbols.begin() ;
            it != it_end ;
            it++, i++)
    {
        this->symbols[i].name = (*it);
        this->symbols[i].value = "";

#ifdef PREPROC_KEEP_ORIGINAL_SYMBOLS
        this->original_symbols[i].name = (*it);
        this->original_symbols[i].value = "";
#endif
    }
}
Example #16
0
	int get(int key) {
		if (cacheMap.find(key) == cacheMap.end())
			return -1;
		cacheList.splice(cacheList.begin(), cacheList, cacheMap[key]);
		cacheMap[key] = cacheList.begin();
		return cacheMap[key]->value;
	}
string align_first(string s, list<table_element*> & path)
{
	string s_aligned = "";
	int previous_c, current_c, cnt(0);
	for (list<table_element*>::iterator it=path.begin(); it!=path.end(); it++)
	{
		if (it==path.begin())
		{
			previous_c = (*it)->column;
		}
		else
		{
			current_c = (*it)->column;
			if (current_c==previous_c)
			{
				s_aligned += "_";
			}
			else
			{
				s_aligned += s.at(cnt);
				cnt++;
			}
			previous_c = current_c;
		}
	}
	return s_aligned;
}
void BSFrustumFOVController::Write( ostream& out, const map<NiObjectRef,unsigned int> & link_map, list<NiObject *> & missing_link_stack, const NifInfo & info ) const {
	//--BEGIN PRE-WRITE CUSTOM CODE--//

	//--END CUSTOM CODE--//

	NiTimeController::Write( out, link_map, missing_link_stack, info );
	if ( info.version < VER_3_3_0_13 ) {
		WritePtr32( &(*interpolator), out );
	} else {
		if ( interpolator != NULL ) {
			map<NiObjectRef,unsigned int>::const_iterator it = link_map.find( StaticCast<NiObject>(interpolator) );
			if (it != link_map.end()) {
				NifStream( it->second, out, info );
				missing_link_stack.push_back( NULL );
			} else {
				NifStream( 0xFFFFFFFF, out, info );
				missing_link_stack.push_back( interpolator );
			}
		} else {
			NifStream( 0xFFFFFFFF, out, info );
			missing_link_stack.push_back( NULL );
		}
	}

	//--BEGIN POST-WRITE CUSTOM CODE--//

	//--END CUSTOM CODE--//
}
Example #19
0
bool tryPutAway( list<PhantomTriangle*>& pTris,
  vector<AABB>& aabbCandChildren,
  map< AABB*, list<PhantomTriangle*> >& aabbsAndTheirContainedItems )
{
  // try and put away the new tris into the
  // child aabbs.
  bool allAway = true ;
  for( list<PhantomTriangle*>::iterator iter = pTris.begin() ; iter != pTris.end() ; )
  {
    if( tryPutAway( *iter, aabbCandChildren, aabbsAndTheirContainedItems ) )
    {
      // it put away.
      // these 2 lines aren't strictly necessary but I need
      // to know the tris that didn't place for debug purposes.
      // they actually get put back in root (if there are problems for whatever reason)
      // if they don't get put away
      iter = pTris.erase( iter ) ;// remove it
      //info( "Tri put away, %d remain", pTris.size() ) ;
    }
    else
    {
      allAway = false ;  // at least one didn't get put away into a child box
      ++iter;
    }
  }

  //info( "Total tris remain: %d", pTris.size() ) ;
  return allAway ;
}
void CConfigurableElement::listDomains(const list<const CConfigurableDomain*>& configurableDomainList, string& strResult, bool bVertical) const
{
    if (bVertical && configurableDomainList.empty()) {

        strResult = "\n";
    }

    // Fill list
    ConfigurableDomainListConstIterator it;
    bool bFirst = true;

    // Browse all configurable domains for comparison
    for (it = configurableDomainList.begin(); it != configurableDomainList.end(); ++it) {

        const CConfigurableDomain* pConfigurableDomain = *it;

        if (!bVertical && !bFirst) {

            strResult += ", ";
        }

        strResult += pConfigurableDomain->getName();

        if (bVertical) {

            strResult += "\n";
        } else {

            bFirst = false;
        }
    }
}
Example #21
0
void printList(list<int>& number) {
    list<int>::iterator it;
    for (it = number.begin(); it != number.end(); it++) {
        cout << *it << " ";
    }
    cout << endl;
}
//--------------------------------------------------------------------------------------- 
// Funcion que inserta un nuevo registro segĂșn la matricula ingresada
//---------------------------------------------------------------------------------------
void inserta_orden()
{
    int matricula1, x=-1,y;

    printf("\nMatricula a insertar: ");
    scanf("%d",&matricula1);

    for(i=l.begin(); i!=l.end(); i++)
    {
        if (i->matricula<matricula1){
            i++;
            x=y;
        }
    }

    if(x!=-1)
    {
        struct alumno *p=new(struct alumno);
        cout<<"\nNombre: ";
        scanf("%s", p->nombre);
        cout<<"\nSaldo: ";
        scanf("%d", &p->saldo);
        cout<<"\nLicenciatura: ";
        scanf("%s", p->licenciatura);
        cout<<"\nMatricula: ";
        scanf("%d", &p->matricula);

        l.insert(i,*p);
    }
}
Example #23
0
bool writePly( const list<Pt3dr> &aPoints, const string &aFilename )
{
	ofstream f(aFilename.c_str());

	if ( !f) return false;

	f << "ply" << endl;
	f << "format ascii 1.0" << endl;
	f << "element vertex " << aPoints.size() << endl;
	f << "property float x" << endl;
	f << "property float y" << endl;
	f << "property float z" << endl;
	f << "property uchar red" << endl;
	f << "property uchar green" << endl;
	f << "property uchar blue" << endl;
	f << "element face 0" << endl;
	f << "property list uchar int vertex_indices" << endl;
	f << "end_header" << endl;

	list<Pt3dr>::const_iterator itPoint = aPoints.begin();
	while (itPoint != aPoints.end())
	{
		const Pt3dr &p = *itPoint++;
		f << p.x << ' ' << p.y << ' ' << p.z << " 128 128 128" << endl;
	}

	return true;
}
    /** Decrements an existing key by 1. If Key's value is 1, remove it from the data structure. */
    void dec(string key) {
        if (strmap.find(key) == strmap.end()) {
            return;
        } else {
            auto row = strmap[key].first;
            auto col = strmap[key].second;
            if (row->val == 1) {
                row->strs.erase(col);
                if (row->strs.empty()) {
                    matrix.erase(row);
                    strmap.erase(key);
                }
                return;
            }

            auto nextrow = row;
            ++nextrow;
            if (nextrow == matrix.end() || nextrow->val != row->val - 1) {
                auto newrow = matrix.emplace(nextrow, key, row->val - 1);
                strmap[key] = make_pair(newrow, newrow->strs.begin());
            } else {
                auto newrow = nextrow;
                newrow->strs.push_front(key);
                strmap[key] = make_pair(newrow, newrow->strs.begin());
            }
            row->strs.erase(col);
            if (row->strs.empty())
                matrix.erase(row);
        }
    }
Example #25
0
int AdRedisCli::AdRedisHkeys(string& key, list<string>& res)
{
	unsigned int i = 0;
	redisReply *reply = NULL;

	res.clear();

	if (key.empty() || NULL == (reply = (redisReply *)redisCommand(m_pGtCli,"HKEYS %s", key.c_str())) )
	{
		return AD_FAILURE;
	}

	if(reply->type == REDIS_REPLY_ARRAY)
	{
		for(i = 0; i < reply->elements; i++)
		{
			res.push_back(reply->element[i]->str);
		}
		freeReplyObject(reply);
		return AD_SUCCESS;
	}
	else if(reply->type == REDIS_REPLY_NIL)
	{
		freeReplyObject(reply);
		return AD_SUCCESS;
	}

	freeReplyObject(reply);
	return AD_FAILURE;
}
void remove_covering_region(string /*event*/, map<string,EvTRel *> &tr_map, const SS &sr, Region &partition, const SS &/*state_space*/,
                            list<Region *> &localRegs,set<string> localEvs,map<string,int> &flow_map)
{
    list<Region *>::iterator it;
    for(it=localRegs.begin(); it!=localRegs.end(); ++it)
    {
        if (sr <= (*it)->sup())
        {
            break;
        }
    }
    if (it != localRegs.end())
    {
        SS rsup = (*it)->sup();
        partition.additive_substraction(**it);
        localRegs.erase(it);
        set<string>::const_iterator ite;
        for(ite=localEvs.begin(); ite!=localEvs.end(); ++ite)
        {
            if (tr_map[*ite]->get_er() <= rsup)
            {
                flow_map[*ite]++;
            }
            if (tr_map[*ite]->get_sr() <= rsup)
            {
                flow_map[*ite]--;
            }
        }
    }
}
Example #27
0
int main(void) {
    generate_primes();

    long long n;
    long long result;

    while (~scanf("%lld", &n)) {
        result = n;
        bool prime = true;

        for(list<long long>::iterator it = primes.begin(); it != primes.end() && *it <= n; it++) {
            if (n % *it == 0) {
                result /= *it;
                result *= *it - 1;

                while (n % *it == 0) n /= *it;
            }
        }

        if (n > 1) {
            result /= n;
            result *= n - 1;
        }

        long long n_coprimes = result;
        long long n_stars    = n_coprimes/2;

        printf("%lld\n", n_stars);
    }

    return 0;
}
 static std::string to_string(const list<osm_id_t> &ids) {
   stringstream ostr;
   ostr << "{";
   std::copy(ids.begin(), ids.end(), infix_ostream_iterator<osm_id_t>(ostr, ","));
   ostr << "}";
   return ostr.str();
 }
Example #29
0
void ispisiListu(list<pair<int, int> > L)
{
    list<pair<int, int> >::iterator it;

    for(it = L.begin(); it != L.end(); it++)
        cout << it->first << " " << it->second << " ";
}
Example #30
0
void SearchFilterListF(const json_t* node, list<ConnectionPtr>& conlist) {
    list<int> items;
    list<ConnectionPtr> tokeep;
    size_t size = json_array_size(node);
    for (size_t i = 0; i < size; ++i) {
        json_t* jn = json_array_get(node, i);
        if (json_is_string(jn)) {
            items.push_back((int) atoi(json_string_value(jn)));
        } else if (json_is_integer(jn)) {
            items.push_back((int) json_integer_value(jn));
        }
    }

    for (list<ConnectionPtr>::const_iterator i = conlist.begin(); i != conlist.end(); ++i) {
        bool found = true;
        for (list<int>::const_iterator n = items.begin(); n != items.end(); ++n) {
            if ((*i)->kinkList.find((*n)) == (*i)->kinkList.end()) {
                found = false;
                break;
            }
        }

        if (found)
            tokeep.push_back((*i));
    }

    conlist = tokeep;
}