The Shared Space Negotiator

Grade 6 MakeCode micro:bit Simulation first Finding Fair Compromise
Simulation lab
Board: BBC micro:bit
Open MakeCode ↗
Simulator preview
☀️ 80

Change the slider level and observe the 5x5 LED display.

📁 Tools ▴
  • Web browser (Chrome, Edge, Firefox)
  • Internet connection
  • MakeCode (micro:bit) online editor

🔧 Build Your Shared Space Negotiator

1 Create two integer variables: 'prefA' and 'prefB' representing roommate comfort levels (scale 1 to 5).
2 Program Button A to cycle through Roommate A's preferred ceiling fan speed.
3 Program Button B to cycle through Roommate B's preferred ceiling fan speed.
4 Program Button A+B to compute the mathematical midpoint: (prefA + prefB) / 2 and show the compromise!
🧩 Block plan / Starter code ▴
let prefA = 2
let prefB = 4

input.onButtonPressed(Button.A, function () {
    prefA = (prefA % 5) + 1
    basic.showString("A:" + prefA)
})

input.onButtonPressed(Button.B, function () {
    prefB = (prefB % 5) + 1
    basic.showString("B:" + prefB)
})

input.onButtonPressed(Button.AB, function () {
    let compromise = Math.round((prefA + prefB) / 2)
    basic.showIcon(IconNames.Heart)
    basic.pause(500)
    basic.showNumber(compromise)
})

Math.round calculates the nearest integer midpoint between conflicting preferences.

⚗️ Test your model

Test Condition / ActionExpected Result
Set A=2 and B=4Press A+B shows Heart then displays compromise speed 3
Set A=1 and B=5Press A+B shows Heart then displays compromise speed 3
Set A=4 and B=4Press A+B immediately confirms agreed speed 4
⚑ Try a challenge

If preferences differ by more than 3 units (e.g. 1 vs 5), display an animated 'Thinking' icon before showing the result!

❓ Quick check
Why does our Negotiator compute the mathematical average between Agent A and Agent B's preferences?

📖 Our Story & Concepts

In shared school dormitories, computer labs, and office spaces, people frequently disagree on environmental settings: one student wants the ceiling fan on maximum speed, while another feels cold and wants it on minimum speed.

In smart buildings, multi-agent negotiation algorithms resolve disputes automatically without arguments. By collecting individual inputs and computing the mathematical consensus, software builds harmony and fair sharing in communal spaces.

</> Full Annotated Code Walkthrough

// Complete Multi-Agent Compromise System
let prefA = 3
let prefB = 3

input.onButtonPressed(Button.A, function () {
    prefA = (prefA % 5) + 1
    basic.showString("A:" + prefA)
})

input.onButtonPressed(Button.B, function () {
    prefB = (prefB % 5) + 1
    basic.showString("B:" + prefB)
})

input.onButtonPressed(Button.AB, function () {
    let diff = Math.abs(prefA - prefB)
    if (diff >= 3) {
        basic.showIcon(IconNames.Confused)
        basic.pause(800)
    }
    let compromise = Math.round((prefA + prefB) / 2)
    basic.showIcon(IconNames.Happy)
    basic.pause(400)
    basic.showNumber(compromise)
})

Math.round calculates the nearest integer midpoint between conflicting preferences.

▷ Expected Results & Troubleshooting

Test Condition / ActionExpected Result
Set A=2 and B=4Press A+B shows Heart then displays compromise speed 3
Set A=1 and B=5Press A+B shows Heart then displays compromise speed 3
Set A=4 and B=4Press A+B immediately confirms agreed speed 4

⚑ Extension Challenges & Blueprints

⚑ Extension Challenges
  • Level 1: Add a third roommate (Roommate C) by tilting the micro:bit to set preference C.
  • Level 2: Give higher weight to a roommate who is studying for final exams.
  • Level 3: Display a warning if both roommates agree on extreme settings (1 or 5) that waste energy.

❓ Check Your Understanding

Question 1: Why does our Negotiator compute the mathematical average between Agent A and Agent B's preferences?

Question 2: On the BBC micro:bit, which two physical/virtual buttons are used to adjust the two agents' preferences?

Question 3: If Agent A wants light level 8 and Agent B wants light level 2, what negotiated level will the algorithm calculate?

Question 4: What gesture or input triggers the micro:bit to execute the negotiation algorithm and show the result?

Feedback appears after you check your answer.