-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(examples): a shifumi (rock, paper, scissors) smart contract #2629
base: master
Are you sure you want to change the base?
Conversation
A very simple game as a smart contract. It's possible to play against yourself, or another opponent. UI could be improved. No provision against cheating, no gain or automatic action. Related to gnolang#611.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2629 +/- ##
==========================================
- Coverage 54.99% 54.99% -0.01%
==========================================
Files 595 595
Lines 79775 79775
==========================================
- Hits 43872 43871 -1
- Misses 32581 32584 +3
+ Partials 3322 3320 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a few suggestions for good practices
move1, move2 int // can be empty, rock, paper, or scissors | ||
} | ||
|
||
var games = []*game{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avl.Tree for scalability? can use seqid
to have a compatible index
then the Render() page could render the, say, last 100 games.
return output | ||
} | ||
|
||
func short(addr std.Address) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe use r/demo/users to resolve to a "shortname", but use the long address by default?
games = append(games, &game{player1: std.GetOrigCaller(), player2: player}) | ||
return len(games) - 1 | ||
} | ||
|
||
// Play executes a move for the game at index idx, where move can be: | ||
// 1 (rock), 2 (paper), 3 (scissors). | ||
func Play(idx, move int) { | ||
if err := games[idx].play(std.GetOrigCaller(), move); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/GetOrigCaller/PrevRealm().Addr()/g
otherwise, users can be impersonated by realms :)
* [NewGame](r/demo/games/shifumi?help&__func=NewGame) opponentAddress | ||
* [Play](r/demo/games/shifumi?help&__func=Play) gameIndex move (1=rock, 2=paper, 3=scissors) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* [NewGame](r/demo/games/shifumi?help&__func=NewGame) opponentAddress | |
* [Play](r/demo/games/shifumi?help&__func=Play) gameIndex move (1=rock, 2=paper, 3=scissors) | |
* [NewGame](shifumi?help&__func=NewGame) opponentAddress | |
* [Play](shifumi?help&__func=Play) gameIndex move (1=rock, 2=paper, 3=scissors) |
A very simple game as a smart contract. It's possible to play against yourself, or another opponent. UI could be improved.
No provision against cheating, no gain or automatic action.
Related to #611.
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description