コード例 #1
0
ファイル: ai.c プロジェクト: maikmerten/c64-nuclearreaction
signed int evaluateField(char f[SIZEX][SIZEY], char p) {
	unsigned char x,y,owner,otherplayer,otherfields;
	int score = 0;
	otherfields = 0;
	otherplayer = p == 1 ? 2 : 1;
	for(x = 0; x < SIZEX; ++x) {
		for(y = 0; y < SIZEY; ++y) {
			owner = getOwner(f, x, y);
			if(owner == p) {
				 // the more cells, the better, but prefer corners and edges
				score += 4 - getCapacity(x, y);
				// small bonus for fields that are ready to explode
				score += isCritical(f, x, y);
			} else {
				++otherfields;
			}
		}
	}
	 // endangered cells are dangerous...
	score -= (countEndangered(f, p) << 1);
	// ... unless they belong to the other player
	score += countEndangered(f, otherplayer);
	
	// REALLY reward if no cells are left to the other guy
	if(otherfields == 0) {
		score += 1000;
	}
	
	return score;
}
コード例 #2
0
ファイル: Node.cpp プロジェクト: boy999/sample
void Node::markCritical() 
{
  if(!isCritical())
  { 
    mIsCriticalFlag = true; 
    getParentGraph()->addCriticalNode(this);
    if(getOriginalNode() != this)
      getOriginalNode()->markCritical();
  }
}
コード例 #3
0
ファイル: control.c プロジェクト: derkling/adcontrol
static void notifyChFault(uint8_t ch) {
	char *msg = cmdBuff;
	uint8_t len = 0;

	// Format SMS message
	len = ee_getSmsText(msg, MAX_MSG_TEXT);

	len += snprintf(msg+len,
			CMD_BUFFER_SIZE-len,
			"\r\nAnomalia: CH%s(%hd)\r\nSemaforo: ",
			isCritical(ch) ? " CRITICO" : "",
			ch+1);
	if (controlCriticalFaulted()) {
		len += snprintf(cmdBuff+len,
				CMD_BUFFER_SIZE-len,
				"in LAMPEGGIO");
	} else if (controlGetFaultedMask()) {
		len += snprintf(cmdBuff+len,
				CMD_BUFFER_SIZE-len,
				"GUASTO");
	} else {
		// This should never happens
		len += snprintf(cmdBuff+len,
				CMD_BUFFER_SIZE-len,
				"RFN FAULT?");
	}

#if CONFIG_REPORT_FAULT_LEVELS
#warning Reporting FAULTS LEVELS enabled
	if (len+27 < CMD_BUFFER_SIZE) {
		len += snprintf(msg+len,
				CMD_BUFFER_SIZE-len,
				"\r\n"
				"P: %8ld => %8ld\r\n",
				chData[ch].Pmax, chData[ch].Prms);
	}
	if (len+25 < CMD_BUFFER_SIZE) {
		len += snprintf(msg+len,
				CMD_BUFFER_SIZE-len,
				"I: %8ld => %8ld\r\n",
				chData[ch].Imax, chData[ch].Irms);
	}
	if (len+25 < CMD_BUFFER_SIZE) {
		len += snprintf(msg+len,
				CMD_BUFFER_SIZE-len,
				"V: %8ld => %8ld\r\n",
				chData[ch].Vmax, chData[ch].Vrms);
	}
#endif

	// Send message by SMS to all enabled destination
	notifyAllBySMS(msg);

}
コード例 #4
0
ファイル: bustrophedon.c プロジェクト: Medeah/P1
void bustrophedon(int busIndex, robot *r) {
  while (!isCritical(r)) {
    if (canStepUpVirtual(r))
      stepUp(r);
    else if (canStepDownVirtual(r))
      stepDown(r);
    else if (canStepRightVirtual(r))
      stepRight(r);
    else
      stepLeft(r);
    
    r->map->tiles[r->posX][r->posY]->bustrophedonIndex = busIndex;
  }
}
コード例 #5
0
ファイル: ai.c プロジェクト: maikmerten/c64-nuclearreaction
char computeDanger(char f[SIZEX][SIZEY], char p, char x, char y) {
	char tmp;
	char danger = 0;

	if(x > 0) {
		tmp = x - 1;
		if(getOwner(f, tmp, y) != p) danger += isCritical(f, tmp, y);
	}
	if(y > 0) {
		tmp = y - 1;
		if(getOwner(f, x, tmp) != p) danger += isCritical(f, x, tmp);
	}
	if(x < MAXX) {
		tmp = x + 1;
		if(getOwner(f, tmp, y) != p) danger += isCritical(f, tmp, y);
	}
	if(y < MAXY) {
		tmp = y + 1;
		if(getOwner(f, x, tmp) != p) danger += isCritical(f, x, tmp);
	}

	return danger;
}
コード例 #6
0
ファイル: validation.cpp プロジェクト: jamcole/mapcrafter
void ValidationMap::log(std::string logger) const {
    for (auto section_it = sections.begin(); section_it != sections.end(); ++section_it) {
        auto messages = section_it->second.getMessages();
        if (messages.empty())
            continue;

        if (isCritical()) {
            LOGN(ERROR, logger) << section_it->first << ":";
            for (auto it = messages.begin(); it != messages.end(); ++it)
                LOGN(ERROR, logger) << " - " << *it;
        } else {
            LOGN(WARNING, logger) << section_it->first << ":";
            for (auto it = messages.begin(); it != messages.end(); ++it)
                LOGN(WARNING, logger) << " - " << *it;
        }
    }
}
コード例 #7
0
ファイル: ai.c プロジェクト: maikmerten/c64-nuclearreaction
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;
}