[
"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 10,000 payment from this AA and check the response unit
// which has data payload which indicates round, redplayer and blueplayer
// 3) use that 10,000 and round number and send a payment
// 4) 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 = "
BXJMVNCKRG3N5Q22R3ZSMNAZXMYUUMVN";
$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( " Red = " || var[ 'red' ] || " vs Blue = " || var[ 'blue' ] );
$minimum >= 3
}",
"messages": {
"cases": [
{
"if": "{ // REQUEST NEW ROUND
if( !trigger.data.message AND !trigger.data.round AND trigger.output[[ asset=base ]] < 25000 ) bounce( "need to send 25000 to request a new round");
( !trigger.data.message AND !trigger.data.round )
}",
"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 , only possible from $red or $blue
( trigger.address == $red OR trigger.address == $blue ) AND trigger.data.message == "redvsblue" AND trigger.data.choosen
}",
"init": "{
if( trigger.address == $red AND var[ "blueaddr" ] AND ( var[ "redaddr" ] + 1 ) <= var[ "blueaddr" ] ){
$round = var[ "redaddr" ] + 1; // start round at red
$sendred = trigger.data.choosen; // use message choose for red
$sendblue = var[ "b" || $round ]; // use blue at round
}
if( trigger.address == $blue AND var[ "redaddr" ] AND ( var[ "blueaddr" ] + 1 ) <= var[ "redaddr" ] ){
$round = var[ "blueaddr" ] + 1; // start round at blue
$sendred = var[ "r" || $round ];
$sendblue = trigger.data.choosen;
}
if( $round ) $message = "send 10,000 back to this sender within 12 hours with data { field: round , data: " || $round || " }";
}",
"messages": [
{
"if": "{ $round }",
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "{ $sendred }",
"amount": 10000
},
{
"address": "{ $sendblue }",
"amount": 10000
}
]
}
},
{
"if": "{ $round }",
"app": "data",
"payload": {
"message": "{$message}",
"round ": "{$round}",
"redplayer ": "{$sendred}",
"blueplayer ": "{$sendblue}"
}
},
{
"app": "state",
"state": "{
if( $round ){ // duplicate data payload as response
var[ "g" || $round ] = timestamp + 43200; // start countdown
response[ "message" ] = $message;
response[ "round" ] = $round;
response[ "redplayer" ] = $sendred;
response[ "blueplayer" ] = $sendblue;
}
if( trigger.address == $red ){
var[ "redaddr" ] += 1; // new red address
var[ "r" || var[ "redaddr" ] ] = trigger.data.choosen; // save red address
}
if( trigger.address == $blue ){
var[ "blueaddr" ] += 1; // new blue address
var[ "b" || var[ "blueaddr" ] ] = trigger.data.choosen;
}
}"
}
]
},
{
"if": "{ // VOTE IN ROUND
if( trigger.data.round ){
$round = trigger.data.round;
if( !var[ "g" || $round ] ) bounce( "not a valid round");
if( ( !var[ "r" || $round ] OR var[ "r" || $round ] != trigger.address ) AND
( !var[ "b" || $round ] OR var[ "b" || $round ] != trigger.address ) ) bounce( "not a player in this round" );
if( var[ "g" || $round ] < timestamp ) bounce( "round is already over" );
}
$round
}",
"messages": [
{
"app": "state",
"state": "{
if( var[ "r" || $round ] AND trigger.address == var[ "r" || $round ] ){
var[ "red" ] += 1;
var[ "r" || $round ] = false; // clear redaddr
}
if( var[ "b" || $round ] AND trigger.address == var[ "b" || $round ] ){
var[ "blue" ] += 1;
var[ "b" || $round ] = false; // clear blueaddr
}
response[ "red" ] = var[ "red" ];
response[ "blue" ] = var[ "blue" ];
//if( !var[ "r" || $round ] AND !var[ "b" || $round ] ) var[ "g" || $round ] = false; // both voted clear round
}"
}
]
},
{
"messages": [
{
"app": "payment",
"payload": {
"asset": "base",
"outputs": [
{
"address": "
HFNBIQTUNVMRM7PDP6NT2QRKLR62FOGR"
}
]
}
},
{
"app": "state",
"state": "{ if( !var[ "owner" ] ) var[ "owner" ] = "
HFNBIQTUNVMRM7PDP6NT2QRKLR62FOGR"; }"
}
]
}
]
}
}
]
}
}
]