[
"autonomous agent",
{
"messages": {
"cases": [
{
"if": "{
// RED vs BLUE the contentious game by
[email protected]
// how to play:
// 1) register to one or both $red / $blue "choose address AA"
// 2) wait for received payment from this AA and ...
// 3) send 25000 to request for a new round and go back to step 2)
// setup:
// 1) setup two "choose random address AA" and replace below $red and $blue addresses
$red = "
UQRQVOLKSAIDKV3PFTQNOQHWETJEDCX3";
$blue = "
XRNRERYBLKBXO6SGLN3E4FCTQMFE2TQT";
$minimum = 3;
if( !var[ $red ][ "count" ] AND !var[ $blue ][ "count" ]) bounce( "$red or $blue AA missing 'count'");
if( var[ $red ][ "count" ] < $minimum OR var[ $blue ][ "count" ] < $minimum ) bounce( "waiting for red=" || $red || " or blue=" || $blue || " sides to have " || $minimum || " players" );
if( trigger.data.needle ) bounce( "Round " || var[ 'round' ] || " Red = " || var[ 'red' ] || " vs Blue = " || var[ 'blue' ] );
$minimum
}",
"messages": {
"cases": [
{
"if": "{ // REQUEST NEW ROUND
if( !trigger.data.message AND trigger.output[[ asset=base ]] < 25000 ) bounce( "need to send 25000 to request a new round");
!trigger.data.message
}",
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ $red }",
"amount": 10000
},
{
"address": "{ $blue }",
"amount": 10000
}
]
}
},
{
"app": "data",
"payload": {
"message": "redvsblue",
"nosend": true
}
}
]
},
{
"if": "{ // START ROUND
( trigger.address == $red OR trigger.address == $blue ) AND trigger.data.message == "redvsblue" AND trigger.data.choosen
}",
"init": "{
if( trigger.address == $red AND var[ "blue" ] AND ( var[ "red" ] + 1 ) <= var[ "blue" ] ){
$round = var[ "red" ] + 1; // start round
$sendred = trigger.data.choosen;
$sendblue = var[ "b" || $round ];
}
if( trigger.address == $blue AND var[ "red" ] AND ( var[ "blue" ] + 1 ) <= var[ "red" ] ){
$round = var[ "blue" ] + 1; // start round
$sendred = var[ "r" || $round ];
$sendblue = trigger.data.choosen;
}
}",
"messages": [
{
"if": "{ $round }",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ $sendred }",
"amount": 10000
},
{
"address": "{ $sendblue }",
"amount": 10000
}
]
}
},
{
"if": "{ $round }",
"app": "data",
"payload": {
"message": "send 10000 back to this sender within 12 hours with data round",
"round ": "{$round}"
}
},
{
"app": "state",
"state": "{
if( trigger.address == $red ){
var[ "red" ] += 1;
var[ "r" || var[ "red" ] ] = trigger.data.choosen;
if( $round ) var[ "g" || var[ "red" ] ] = timestamp + 43200; // start countdown
}
if( trigger.address == $blue ){
var[ "blue" ] += 1;
var[ "b" || var[ "blue" ] ] = trigger.data.choosen;
if( $round ) var[ "g" || var[ "blue" ] ] = timestamp + 43200; // start countdown
}
}"
}
]
},
{
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "
HFNBIQTUNVMRM7PDP6NT2QRKLR62FOGR"
}
]
}
}
]
}
]
}
}
]
}
}
]