bounties icon indicating copy to clipboard operation
bounties copied to clipboard

Rock Paper Scissors Example dApp in Python

Open JoshOrndorff opened this issue 6 years ago • 18 comments

Benefit to RChain

Incoming developers need example dApps to look at when learning the RChain platform. There are a few available like

  • https://github.com/JoshOrndorff/nth-caller-game
  • https://github.com/JoshOrndorff/Rchain-Status (incomplete)
  • https://github.com/BlockSpaces/coin-faucet/ (incomplete)

None of these dapps are written in python which is a very popular language. Writing one in python will allow us to reach a broader developer base as well as test tooling in our own ecosystem. Completing this bounty will almost certainly require some tweaking to the python version of RChain-API.

Budget and Objective

This bounty is to complete the rholang contract, user-interfaces, and supporting python code for an interactive rock-paper-scissors dapp where players can challenge one another and be told who wins.

Estimated Budget of Task: $4500 Estimated Timeline Required to Complete the Task: 4 weeks How will we measure completion? Committed code and Video of two people playing the dapp successfully.

Scope

The big picture architecture will match that of nth caller (linked above) with an RNode, a middleware running a python version of rchain-api, and a browser-based frontend. Flask may be a good tool to serve the UI. A second text-based UI is also available so users can play the game without the browser or middleware. Both UIs will use the python rchain-api.

Contract Architecture

Alice initiates a game by calling the factory contract and providing:

  • A channel on which she will be told the winner
  • A channel on which the opponent should be contacted
  • A commitment to her play -- a hash of eg ("rock", 231413) where the number is chosen randomly
  • A return channel on which she will receive a reveal capability

The opponent (we'll call him Bob) receives a channel from the contract. He accepts Alice's challenge by sending

  • A channel on which he will be told the winner
  • A commitment to his play
  • A return channel on which he will receive a reveal capability

When both players have committed to the plays, the contract sends the reveal capability to each player. They then send in the original play ("rock", 231413) and the contract confirms that it corresponds to their commitment. The contract then tells the result to each player individually.

See CONTRIBUTING.md for details on budget and reward process.

Legal

Task Submitter shall not submit Tasks that will involve RHOC being transacted in any manner that (i) jeopardizes RHOC’s status as a software access token or other relevant and applicable description of the RHOC as an “asset”—not a security— or (2) violates, in any manner, applicable U.S. Securities laws.

JoshOrndorff avatar Oct 06 '18 04:10 JoshOrndorff

Hi, I want to take a shot at this.

goodyduru avatar Oct 08 '18 10:10 goodyduru

I'm a python developer that was introduced to rchain through one of the meetups in Nigeria. I can learn more about rchain by working on one of its issues and this is perfect for me.

goodyduru avatar Oct 08 '18 11:10 goodyduru

hey @goodyduru, I'd like to assist you with this project. been working with rholang for a few weeks and been less than creative on a good first dapp. This fits it for me.

Are you on discord? My username is wimm#0066. :)

whereyouatwimm avatar Oct 09 '18 00:10 whereyouatwimm

I would love to help too, I code with python

sypha999 avatar Oct 09 '18 07:10 sypha999

@whereyouatwimm am daton#4414 on discord

sypha999 avatar Oct 09 '18 07:10 sypha999

Perhaps we could steal this user interface: https://www.youtube.com/watch?v=lYRurlnTcLk Some previous work on interacting with RNode from python: https://github.com/proof-media/rchain-grpc

JoshOrndorff avatar Oct 09 '18 16:10 JoshOrndorff

@sypha999 @whereyouatwimm @goodyduru Thanks for expressing interest. Have any of you started work yet? I'd love to take a look.

JoshOrndorff avatar Oct 09 '18 16:10 JoshOrndorff

@JoshOrndorff, I have contacted @goodyduru and hopefully he would be present in colab's rholang office hours today where we would work on the rholang contract for this.

@goodyduru is a friend I met through one of our past meetups ( I was very keen to get onboard since he is a very good Python/AI developer), I am happy he is interested to work on this.

@sypha999 @whereyouatwimm please try to attend today's rholang office hours section at CoLab 4pm New York time.

David405 avatar Oct 09 '18 17:10 David405

@David405 Thanks for the intro, will definitely join the colab's rholang office hours today.

@whereyouatwimm yeah, I'm on discord. My username is goodyduru and your assist is appreciated.

goodyduru avatar Oct 09 '18 19:10 goodyduru

@goodyduru how is work with the web socket going?

David405 avatar Oct 22 '18 19:10 David405

This video from the proof team may help explain how to interact with an RNode through python. https://youtu.be/H_pmVff7c3Q

JoshOrndorff avatar Oct 23 '18 01:10 JoshOrndorff

@JoshOrndorff @David405 I have been able to implement the frontend and flask side of this project. Currently trying to use the casper library for connecting to my standalone rnode instance but I'm getting a "maximum recursive depth exceeded" error. The project is here.

goodyduru avatar Oct 28 '18 17:10 goodyduru

@goodyduru Glad to hear you're making progress. That library is written by the proof team. Please update the issue I just opened.

@David405 @Valentine-Mario How is the rholang portion coming?

JoshOrndorff avatar Oct 29 '18 03:10 JoshOrndorff

@JoshOrndorff here is my implementation of the game logic new print(rho:io:stdout`), game, player_option, opponent_option in {

//Game Logic
    for (@{{player_option!("paper") | _} /\ {opponent_option!("paper") | _}} <= game) {
        print!("Game is a tie")   
    }
    |
    for (@{{player_option!("paper") | _} /\ {opponent_option!("scissors") | _}} <= game) {
        print!("opponent wins")
    }
    |
    for (@{{player_option!("paper") | _} /\ {opponent_option!("rock") | _}} <= game) {
        print!("David wins")
    }
    |  
    for (@{{player_option!("scissors") | _} /\ {opponent_option!("paper") | _}} <= game) {
        print!("David wins")
    }
    |
    for (@{{player_option!("scissors") | _} /\ {opponent_option!("scissors") | _}} <= game) {
        print!("Game is a tie")
    }
    |
    for (@{{player_option!("scissors") | _} /\ {opponent_option!("rock") | _}} <= game) {
        print!("opponent wins")
    |
    }
    for (@{{player_option!("rock") | _} /\ {opponent_option!("paper") | _}} <= game) {
        print!("opponent wins")
    |
    }
    for (@{{player_option!("rock") | _} /\ {opponent_option!("scissors") | _}} <= game) {
        print!("David wins")
    |
    }
    for (@{{player_option!("rock") | _} /\ {opponent_option!("rock") | _}} <= game) {
        print!("Game is a tie")
    |
    }
    //integration test
    game!(player_option!("paper") | opponent_option!("rock"))

}` whats your take on it?

David405 avatar Oct 29 '18 07:10 David405

It's a good start @David405 . Here are some suggestions:

  1. Remember you will need to support multiple games of RPS, you use the factory pattern.
  2. You will need to send the result back to the UI, not just to the terminal, so you'll need to send it on a name and then listen for data at that name.
  3. Have you remembered our plan for a commitment scheme where the players first submit a hash of their play and a random nonce?

JoshOrndorff avatar Oct 31 '18 02:10 JoshOrndorff

Yeah @JoshOrndorff the first are implemented but I am still trying to wrap my head around the third, probably we could discuss this at CoLab on Monday night?

@goodyduru I see that the issue you were experiencing is caused by the version of python you are/were using, have you resolved that yet?

David405 avatar Nov 05 '18 01:11 David405

I backed Joshy's $300 budget vote. I'm not sure I know the whole status here, but I guess some code has been shared, which is valuable in that anyone could pick it up and continue.

dckc avatar Nov 06 '18 21:11 dckc

Progress so far:

  • Resolved the maximum recursive depth reached error by updating python version

  • I've been able to create a successful connection to rnode

  • Been able to deploy and propose rholang code from the python client.

The project link is https://github.com/goodyduru/rchain-rock-paper-scissors

goodyduru avatar Nov 19 '18 00:11 goodyduru