示例#1
0
// Set flag for field
void setFlag(int world[NOCOLS][NOROWS], struct coord field, int action){
	// TODO: REMOVE, testing only
	if(field.x <0 || field.y<0){
		printf("setFlag: Negative numbers!\n");
		exit(EXIT_FAILURE);
	}
	if(action == VISITED){
		delFlag(world, field, SAFE);
		delFlag(world, field, CAVESUS);
		delFlag(world, field, GLOWSUS);
		delFlag(world, field, WUMPUSSUS);
	}
	world[field.x][field.y] = world[field.x][field.y] | action;
}
示例#2
0
/**
 * Sets the highlight status of the entity. Highlighted entities 
 * usually indicate a feedback to a user action.
 */
void RS_Entity::setHighlighted(bool on) {
    if (on) {
        setFlag(RS2::FlagHighlighted);
    } else {
        delFlag(RS2::FlagHighlighted);
    }
}
示例#3
0
/**
 * Sets or resets the processed flag of this entity.
 *
 * @param on True to set, false to reset.
 */
void RS_Entity::setProcessed(bool on) {
    if (on) {
        setFlag(RS2::FlagProcessed);
    } else {
        delFlag(RS2::FlagProcessed);
    }
}
示例#4
0
void RS_Entity::setVisible(bool v) {
	if (v) {
		setFlag(RS2::FlagVisible);
	} else {
		delFlag(RS2::FlagVisible);
	}
}
示例#5
0
/**
 * Undoes or redoes an undoable.
 */
void RS_Undoable::setUndoState(bool undone) {
    if (undone) {
        setFlag(RS2::FlagUndone);
    } else {
        delFlag(RS2::FlagUndone);
    }
	undoStateChanged(isUndone());
}
示例#6
0
/**
 * Selects or deselects this entity.
 *
 * @param select True to select, false to deselect.
 */
bool RS_Entity::setSelected(bool select) {
    // layer is locked:
    if (select && isLocked()) {
        return false;
    }

    if (select) {
        setFlag(RS2::FlagSelected);
    } else {
        delFlag(RS2::FlagSelected);
    }

    return true;
}
示例#7
0
// Read sensors and update KB
void evaluateNeighbors(int agentWorld[NOCOLS][NOROWS], struct coord field){
	int z;
	struct coord neighbors[4];		// Neighbors coordinates
	// Get neighbors coordinates
	neighborFieldsCoords(field, neighbors);

	// Iterate all four neighbors to set suspect flags (ignore if neighbor SAFE and VISITED)
	for(z=0; z<4; z++){
		if	(	(
					((neighbors[z].y < NOROWS) && (z == 0))
					||
					((neighbors[z].x < NOCOLS) && (z == 1))
					||
					((neighbors[z].y >= 0) && (z == 2))
					||
					((neighbors[z].x >= 0) && (z == 3))
				)
				&&
				(testFlag(agentWorld, neighbors[z], SAFE) == 0)
				&&
				(testFlag(agentWorld, neighbors[z], VISITED) == 0)
			){



			/* If current field says breeze, CAVESUS marks all around. If one
			 * of the neighbors already has CAVESUS flag then put cave mark there.*/
			if(testFlag(agentWorld, field, BREEZE)){
				if(testFlag(agentWorld, neighbors[z], CAVESUS)){
					/* Cave must be there cause this this field is already
					 * marked with CAVESUS*/
					setFlag(agentWorld, neighbors[z], CAVE);
				}else{
					setFlag(agentWorld, neighbors[z], CAVESUS);
				}
			}

			if(testFlag(agentWorld, field, STENCH)){
				if(testFlag(agentWorld, neighbors[z], WUMPUSSUS)){
					setFlag(agentWorld, neighbors[z], WUMPUS);
				}else{
					setFlag(agentWorld, neighbors[z], WUMPUSSUS);
				}
			}

			if(testFlag(agentWorld, field, GLOWING)){
				if(testFlag(agentWorld, neighbors[z], GLOWSUS)){
					setFlag(agentWorld, neighbors[z], GLOW);
				}else{
					setFlag(agentWorld, neighbors[z], GLOWSUS);
				}
			}

			//If this field gives no sensor data, mark surrounding fields as SAFE
			if((testFlag(agentWorld, field, BREEZE) == 0) &&
				(testFlag(agentWorld, field, STENCH) == 0)){
				setFlag(agentWorld, neighbors[z], SAFE);

				// Delete all unnecessary flags
				delFlag(agentWorld, neighbors[z], CAVESUS);
				delFlag(agentWorld, neighbors[z], WUMPUSSUS);
				delFlag(agentWorld, neighbors[z], CAVE);
				delFlag(agentWorld, neighbors[z], WUMPUS);
			}

		}
	}
}