Example #1
0
void RoboPult::Right()
  {
     
      if(askStena->isChecked () ){emit hasRightWall(); askStena->setChecked(false);switchButt();return;};
      if(askFree->isChecked () ){emit noRightWall(); askFree->setChecked(false);switchButt();return;};
  emit goRight();
      switchButt();
  };
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 */
}
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);

				}
			}
		}
	}
}