Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

v0 source pure

Package rps is the rock-paper-scissors move: parsing it, naming it, and deciding a throw. It holds no state, so every...

Readme View source

gno.land/p/moul/x/daily/rps/v0

The rock-paper-scissors move: Parse, Move.String, Beats. Stateless, so every realm that plays the game agrees on what "r" means and who wins.

1import "gno.land/p/moul/x/daily/rps/v0"
2
3m, ok := rps.Parse(" Paper ") // rps.Paper, true; "p" works too
4m.String()                    // "paper"
5rps.Beats(rps.Paper, rps.Rock) // 1: the first move wins (0 tie, 2 the second wins)

Move is ordered rock, paper, scissors so that (a - b) mod 3 is the verdict.

Consumers: rps, rpsmatch, rpsoracle, rpsduel, each of which carried its own copy of this logic before.


Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.

🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.

Overview

Package rps is the rock-paper-scissors move: parsing it, naming it, and deciding a throw. It holds no state, so every realm that plays the game agrees on what "r" means and who wins.

Imported by r/moul/x/daily/rps(/r/moul/x/daily/rps/v1), r/moul/x/daily/rpsmatch(/r/moul/x/daily/rpsmatch/v1), r/moul/x/daily/rpsoracle(/r/moul/x/daily/rpsoracle/v1) and r/moul/x/daily/rpsduel(/r/moul/x/daily/rpsduel/v1).

Constants 1

Functions 2

func Beats

1func Beats(a, b Move) int
source

Beats decides a throw: 0 for a tie, 1 if a beats b, 2 if b beats a. The three values are (a - b) mod 3, which is why Move is ordered as it is.

func Parse

1func Parse(s string) (Move, bool)
source

Parse reads a move, case-insensitively and ignoring surrounding spaces. The full name and its first letter are both accepted.

Types 1

type Move

ident
1type Move int
source

Move is one of rock, paper, or scissors, ordered so that (winner - loser + 3) % 3 == 1 for every winning pair.

Methods on Move

func String

method on Move
1func (m Move) String() string
source

String returns "rock", "paper" or "scissors", and "?" for anything else.

Dependencies

Imports 1

/p/g1magld5ptgzaktqcexxq0pgq5lmdf0kz6re8hlv/x/daily/rps/v0

Imported by indexer

Source Files 4