Exemple #1
0
/* writes a data base reference */
static void wrputref(CODEADDR ref, int Quote_illegal,
                     struct write_globs *wglb) {
  char s[256];
  wrf stream = wglb->stream;

  putAtom(AtomDBref, Quote_illegal, wglb);
#if defined(__linux__) || defined(__APPLE__)
  sprintf(s, "(%p," UInt_FORMAT ")", ref, ((LogUpdClause *)ref)->ClRefCount);
#else
  sprintf(s, "(0x%p," UInt_FORMAT ")", ref, ((LogUpdClause *)ref)->ClRefCount);
#endif
  wrputs(s, stream);
  lastw = alphanum;
}
Exemple #2
0
int thinkAI() {
	unsigned char x,y,size,owner;
	signed int tmp,score;
	unsigned int result;
	
	enableTurbo();
	
	size = SIZEX * SIZEY;
	// compute the field score for the opposing player
	score = -32000;
	for(x = 0; x < SIZEX; ++x) {
		for(y = 0; y < SIZEY; ++y) {
			owner = getOwner(field, x, y);
			if(owner == PLAYERAI || owner == 0) {
				// we can use this cell
				memcpy(fieldAI, field, size); // create working copy
				tmp = 0;
				
				// it makes little sense to add atoms to endangered cells
				// unless they can start a chain reaction
				if(computeDanger(fieldAI, PLAYERAI, x, y) > 0 && isCritical(fieldAI, x, y) == 0) {
					tmp -= 10;
				}

				// let the reaction run
				putAtom(fieldAI, PLAYERAI, x, y, 0);
				react(fieldAI, 0);
				
				// evaluate the resulting field constellation
				tmp += evaluateField(fieldAI, PLAYERAI);

				if(tmp > score || (tmp == score && (rand() & 0x01))) {
					score = tmp;
					result = (x << 8) | y;
				}
			}
		}
	}
	
	disableTurbo();
	
	return result;
}