---
title: "Activity: Sumo III"
date: "2021-06-05"
categories: ["Activities", "All", "Simulator Activities"]
tags: ["Colour Sensors", "Branching", "Iteration", "Algorithm Design", "Ultrasonic", "IR", "Gyroscope", "Accelerometer", "Motors", "Functions", "Advanced"]
excerpt: "Master sumo with advanced strategies using the gyroscope for precise movement, the accelerometer for defensive tactics, and functions for clean code."
featuredImage: "/images/resources/sumo.png"
---

Create the ultimate sumo algorithm. Use every sensor on the rover to build an advanced strategy that combines precise movement with the gyroscope, defensive detection with the accelerometer, and organised code using functions.

Activity Demonstration

### Setup

Use the same sumo arena setup. For an extra challenge, try a smaller arena (40-50cm diameter) to force more aggressive and precise play.

### Building On Sumo II

In Sumo II we added IR sensors and a search pattern. Now we'll use the gyroscope for controlled turning, the accelerometer for defensive awareness, and functions to keep our code organised.

#### Stage 1: Precise Movement With The Gyroscope

Use the gyroscope to make controlled turns when searching for opponents. Instead of spinning wildly, rotate in measured increments (e.g. 30 degrees at a time) while checking sensors between each turn. This creates a systematic sweep of the arena.

#### Stage 2: Defensive Tactics With The Accelerometer

The accelerometer can detect when your rover is being pushed or tipped by an opponent. If a sudden acceleration is detected from behind or the side, the rover knows it's under attack. Program a defensive response: spin to face the attacker and counter-charge.

#### Stage 3: Organise With Functions

Create functions for each behaviour: `checkEdge`, `scanForOpponent`, `charge`, `defend`, and `searchPattern`. Your main loop should read as a clear sequence of decisions. This makes it much easier to test and tweak individual strategies.

#### Stage 4: Adaptive Strategy

Combine everything into an adaptive algorithm. Start with a search pattern, charge when an opponent is found, defend when being attacked, and always stay away from the edge. The priority order matters: edge avoidance should always come first, then defence, then attack, then search.

### Challenge

Battle the AI opponents in the Micromelon Robot Simulator. Can you defeat all three difficulty levels? Try designing a 3D printed attachment to give your rover an extra advantage.

[Activity: Sumo I](/resources/sumo)

[Activity: Sumo II](/resources/sumo-ii)
