Esempio n. 1
0
void RoboPult::Left()
  {
      
      if(askStena->isChecked () ){emit hasLeftWall(); askStena->setChecked(false);switchButt();return;};
      if(askFree->isChecked () ){emit noLeftWall(); askFree->setChecked(false);switchButt();return;};
  emit goLeft();
      switchButt();
  };
void evaluatePaths() {
	// looking for labyrinth exit

	int x,y;
	for (x = 0; x < getWorldWidth(); x++){
		for (y = 0; y < getWorldHeight(); y++){
			if (hasBaggle(x,y)){
				setIndication(x, y, 0);
			}
		}
	}

	int changed = 1;
	while (changed) {
		changed = 0;
		for (x = 0; x < getWorldWidth(); x++) {
			for (y = 0; y < getWorldHeight(); y++) {
				int indication = getIndication(x, y);
				if (indication != 9999) {
					if (! hasBottomWall(x,y))
						changed |= setValueIfLess(x, (y + 1) % getWorldHeight(), indication + 1);

					if (! hasRightWall(x,y))
						changed |= setValueIfLess((x + 1) % getWorldWidth(), y, indication + 1);

					if (! hasTopWall(x,y))
						changed |= setValueIfLess(x, (y+getWorldHeight() - 1) % getWorldHeight(), indication + 1);

					if (! hasLeftWall(x,y))
						changed |= setValueIfLess((x +getWorldWidth() - 1) % getWorldWidth(), y, indication + 1);

				}
			}
		}
	}
}
void followShortestPath() {
	while (! isOverBaggle()) {

		int x = getX();
		int y = getY();

		int topValue = 9999;
		int bottomValue = 9999;
		int leftValue = 9999;
		int rightValue = 9999;

		if (! hasTopWall(x, y))
			topValue = getIndication(x, (y + getWorldHeight() - 1) % getWorldHeight());

		if (! hasBottomWall(x, y))
			bottomValue = getIndication(x, (y+1) % getWorldHeight());

		if (! hasLeftWall(x, y))
			leftValue = getIndication((x +getWorldWidth() - 1) % getWorldWidth(), y);

		if (! hasRightWall(x, y))
			rightValue = getIndication((x + 1) % getWorldWidth(), y);

		if (topValue <= bottomValue && topValue <= leftValue && topValue <= rightValue)
			setDirection(NORTH);
		else if (rightValue <= topValue && rightValue <= bottomValue && rightValue <= leftValue)
			setDirection(EAST);
		else if (leftValue <= rightValue && leftValue <= bottomValue && leftValue <= topValue)
			setDirection(WEST);
		else if (bottomValue <= topValue && bottomValue <= rightValue && bottomValue <= leftValue)
			setDirection(SOUTH);

		forward(1);
	}
	/* END SOLUTION */
}
// tools functions
int hasRightWall(int x, int y) {
	return hasLeftWall((x + 1) % getWorldWidth(), y);
}