Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mvertes
Copy link
Contributor

@mvertes mvertes commented Jul 25, 2024

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.

Screenshot 2024-07-24 at 16 24 28
Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • [*] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • [*] No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • [*] Added references to related issues and PRs
  • [*] Provided any useful hints for running manual tests
  • Added new benchmarks to generated graphs, if any. More info here.

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.
@mvertes mvertes requested review from a team as code owners July 25, 2024 09:39
@mvertes mvertes requested review from jaekwon and ltzmaxwell and removed request for a team July 25, 2024 09:39
@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Jul 25, 2024
Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.99%. Comparing base (0e3c050) to head (e531a2f).

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     
Flag Coverage Δ
contribs/gnodev 25.65% <ø> (-0.35%) ⬇️
contribs/gnofaucet 14.46% <ø> (ø)
contribs/gnokeykc 0.00% <ø> (ø)
contribs/gnomd 0.00% <ø> (ø)
gno.land 64.15% <ø> (ø)
gnovm 60.20% <ø> (ø)
misc/autocounterd 0.00% <ø> (ø)
misc/genproto 0.00% <ø> (ø)
misc/genstd 80.54% <ø> (ø)
misc/goscan 0.00% <ø> (ø)
misc/logos 17.38% <ø> (ø)
misc/loop 0.00% <ø> (ø)
tm2 54.39% <ø> (-0.11%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@thehowl thehowl left a 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{}
Copy link
Member

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 {
Copy link
Member

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?

Comment on lines +60 to +67
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 {
Copy link
Member

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 :)

Comment on lines +79 to +80
* [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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* [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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🧾 package/realm Tag used for new Realms or Packages.
Projects
Status: In Progress
Status: In Review
Development

Successfully merging this pull request may close these issues.

None yet

2 participants