The Shared Space Negotiator
Change the slider level and observe the 5x5 LED display.
- Web browser (Chrome, Edge, Firefox)
- Internet connection
- MakeCode (micro:bit) online editor
🔧 Build Your Shared Space Negotiator
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 / Action | Expected Result |
|---|---|
| Set A=2 and B=4 | Press A+B shows Heart then displays compromise speed 3 |
| Set A=1 and B=5 | Press A+B shows Heart then displays compromise speed 3 |
| Set A=4 and B=4 | Press A+B immediately confirms agreed speed 4 |
If preferences differ by more than 3 units (e.g. 1 vs 5), display an animated 'Thinking' icon before showing the result!
📖 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 / Action | Expected Result |
|---|---|
| Set A=2 and B=4 | Press A+B shows Heart then displays compromise speed 3 |
| Set A=1 and B=5 | Press A+B shows Heart then displays compromise speed 3 |
| Set A=4 and B=4 | Press A+B immediately confirms agreed speed 4 |
⚑ Extension Challenges & Blueprints
- 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.