예제 #1
0
파일: dumbAI.cpp 프로젝트: ikaikastine/OSU
/*********************************************************************
** Function: cleanFloor
** Description: dumb AI to clean the floor
** Parameters: Floor &floor
** Pre-Conditions: None
** Post-Conditions: None
*********************************************************************/ 
void dumbAI::cleanFloor(Floor &floor) {
	bool up = false;
	bool right = true;
	while (battery > 0) {
		floor.clean();

		if (up == true) {
			if (floor.up() == false) {
				if(right == true) {
					if(floor.right() == false) {
						right = false;
						floor.left();
					}
				}
				else {
					if(floor.left() == false) {
						right = true;
						floor.right();
					}
				}
				up = false;
			}
		}
		else if(up == false) {
			if (floor.down() == false) {
				if (right == true) {
					if (floor.right() == false) {
						right = false;
						floor.left();
					}
				}
				else {
					if (floor.left() == false) {
						right = true;
						floor.right();
					}
				}
				up = true;
			}
		}
		update(floor);
	}
}
예제 #2
0
/*********************************************************************
** Function: cleanFloor
** Description: Random AI to clean the floor
** Parameters: Floor &floor
** Pre-Conditions: None
** Post-Conditions: None
*********************************************************************/ 
void randomAI::cleanFloor(Floor &floor) {
	srand(time(NULL));

	while (battery > 0) {
		floor.clean();
		int x = rand() % 4 + 1;
		if (x == 1) {
			floor.up();
		}
		else if (x == 2) {
			floor.down();
		}
		else if (x == 3) {
			floor.right();
		}
		else if (x == 4) {
			floor.left();
		}
		update(floor);
	}
}