Level up your sumo Rover. In this intermediate challenge you’ll add the IR distance sensors to detect opponents from multiple directions and create a smarter search pattern to find and engage opponents faster.

Two Rovers facing off in a sumo arena
Setup
Use the same sumo arena as Sumo I, a circular arena with clear edge markings, 60–100 cm in diameter.
Building On Sumo I
In Sumo I we used the colour sensor to avoid the edge and the ultrasonic sensor to detect opponents ahead. This works, but the Rover can only find opponents directly in front of it. By adding the IR sensors we can detect opponents to the left and right as well.
Stage 1: Add IR Sensor Detection
After checking for the arena edge with the colour sensor, add ELSE IF conditions to check the left and right IR sensors. If an opponent is detected to the left, turn left and charge. If detected to the right, turn right and charge. This gives the Rover a much wider detection range.
EDGE_BRIGHTNESS = 200
OPPONENT_RANGE = 40 # cm
while True:
brightness = Colour.readSensor(option=Colour.CS.BRIGHT, sensor=1)
front = Ultrasonic.read()
left = IR.readLeft()
right = IR.readRight()
if brightness > EDGE_BRIGHTNESS:
# At the edge, back away and turn
Motors.write(-30)
delay(0.5)
Motors.turnDegrees(180)
elif front < OPPONENT_RANGE:
Motors.write(60) # Charge!
elif left < OPPONENT_RANGE:
Motors.turnDegrees(-45) # Opponent on the left
Motors.write(60)
elif right < OPPONENT_RANGE:
Motors.turnDegrees(45) # Opponent on the right
Motors.write(60)
else:
Motors.turn(15) # Search by spinningStage 2: Smarter Search Pattern
Instead of just driving forward when no opponent is detected, implement a search pattern: spin slowly on the spot while checking all three distance sensors. Once an opponent is detected in any direction, turn to face them and charge at full speed.
Stage 3: Edge Recovery
Improve the edge-avoidance behaviour. Instead of reversing and turning a fixed amount, reverse and then spin to scan for the opponent before moving forward again. This prevents the Rover from wasting time after hitting the edge.

