Skip to content

Instantly share code, notes, and snippets.

@JoshOrndorff
Last active August 27, 2018 23:59
Show Gist options
  • Save JoshOrndorff/8067a29bca02d08285b5d113f553d17e to your computer and use it in GitHub Desktop.
Save JoshOrndorff/8067a29bca02d08285b5d113f553d17e to your computer and use it in GitHub Desktop.
Rholang game where players compete to be the tenth caller.
new stdout(`rho:io:stdout`) in {
@"tenthCaller"!("Joshy", *stdout)
}
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