Last active
August 27, 2018 23:59
-
-
Save JoshOrndorff/8067a29bca02d08285b5d113f553d17e to your computer and use it in GitHub Desktop.
Rholang game where players compete to be the tenth caller.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new stdout(`rho:io:stdout`) in { | |
@"tenthCaller"!("Joshy", *stdout) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new countCh in { | |
// Count state channel starts at zero | |
countCh!(0)| | |
contract @"tenthCaller"(@name, result) = { | |
for(@oldCount <- countCh) { | |
match oldCount { | |
10 => { result!("The winner is: " ++ name) } | |
_ => { countCh!(oldCount + 1)| | |
result!("Sorry, try again.") } | |
} | |
} | |
} | |
} | |
/* | |
To test this, just call it up a bunch of times. | |
new stdout(`rho:io:stdout`) in { | |
@"tenthCaller"!("Joshy", *stdout) | |
} | |
Nice feature. When the 100th caller is reached, nothing is | |
written back to countCh, which means the for on line 7 | |
will never comm again. Callers who are too late are | |
not told to try again, and the game just dies. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment