Example #1
0
TrollJumper::TrollJumper(TrollScreen *scr, IShort sx, IShort sy,
  IUShort secrt, IUShort shft)
 : TrollStandardMonster(scr, secrt, 1)
{
 if ((sx == TROLL_XYRANDOM) && (sy == TROLL_XYRANDOM))
 {
  findOpen();
 }
 else
 {
  x = sx;
  y = sy;
 }
 sprite = TROLL_SPRITE_TOAD;
 shift = shft;
 facing = 0;
 direction = IRandom(4);
 frame = 0;
 hp = 1;
 time = IRandom(8) * 2;
 state = TROLL_JUMPER_SICKNESS;
}
bool loadBenchHypergraphStream(Graph &G, List<node>& hypernodes, List<edge>* shell, std::istream& fileStream) {
	G. clear();
	hypernodes.clear();
	if(shell) shell->clear();
	node si,so;
	
	char buffer[SIMPLE_LOAD_BUFFER_SIZE];
	
	bool readNodes = true;
	Array<node> indexToNode(1,250,0);

	HashArray<String,node> hm(0);
	
	if(shell) {
//		hypernodes.pushBack( si=G.newNode() );
//		hypernodes.pushBack( so=G.newNode() );
//		shell.pushBack( G.newEdge( si, so ) );		
		shell->pushBack( G.newEdge( si=G.newNode(), so=G.newNode() ) );
	}

	int line = 0;
	while(!fileStream.eof())
	{	
		++line;
		fileStream.getline(buffer, SIMPLE_LOAD_BUFFER_SIZE-1);
		size_t l = strlen(buffer);
		if( buffer[l-1]=='\r' ) { // DOS line
			buffer[l-1]='\0';
		}
		if(!strlen(buffer) || buffer[0]==' ' || buffer[0]=='#') continue;
		if(!strncmp("INPUT(",buffer,6)) {
			String s(extractIdentifierLength(buffer+6, line),buffer+6);
			node n = G.newNode();
			hm[s] = n;
			hypernodes.pushBack(n);
			if(shell) shell->pushBack( G.newEdge(si,n) );
//			cout << "input: " << s << " -> " << n->index() << "\n";					
		} else if(!strncmp("OUTPUT(",buffer,7)) {
			String s(extractIdentifierLength(buffer+7, line),buffer+7);
			node n = G.newNode();
			hm[s] = n;
			hypernodes.pushBack(n);
			if(shell) shell->pushBack( G.newEdge(n,so) );								
//			cout << "output: " << s << " -> " << n->index() << "\n";					
		} else {
			int p = extractIdentifierLength(buffer, line);
			String s(p,buffer); // gatename
			node m = hm[s]; // found as outputname -> refOut
			if(!m) {
				m = hm[inName(s)]; // found as innernode input.
				if(!m) { // generate it anew.
					node in = G.newNode();
					node out = G.newNode();
					hm[inName(s)] = in;
					hm[s] = out;
					hypernodes.pushBack(out);
					G.newEdge(in,out);
					m = in;
				}	
			}
			p = findOpen(buffer, line);
			do {
				++p;
				p += newStartPos(buffer+p, line);
				int pp = extractIdentifierLength(buffer+p, line);
				String s(pp,buffer+p);
				p += pp;
				node mm = hm[s];
				if(!mm) {
					// new
					node in = G.newNode();
					node out = G.newNode();
					hm[inName(s)] = in;
					hm[s] = out;
					hypernodes.pushBack(out);
					G.newEdge(in,out);
					mm = out;
				}
				G.newEdge(mm,m);
//				cout << "Edge: " << s << "(" << hm[s]->index() << ") TO " << m->index() << "\n";
			} while(buffer[p] == ',');			
		}		
	}	
	
	return true;
}