rchain / bounties

RChain Bounty Program
MIT License
90 stars 62 forks source link

Rock Paper Scissors Example dApp in Python #996

Open JoshOrndorff opened 5 years ago

JoshOrndorff commented 5 years ago

Benefit to RChain

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

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:

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

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.

goodyduru commented 5 years ago

Hi, I want to take a shot at this.

goodyduru commented 5 years ago

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.

whereyouatwimm commented 5 years ago

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

sypha999 commented 5 years ago

I would love to help too, I code with python

sypha999 commented 5 years ago

@whereyouatwimm am daton#4414 on discord

JoshOrndorff commented 5 years ago

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 commented 5 years ago

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

David405 commented 5 years ago

@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.

goodyduru commented 5 years ago

@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.

David405 commented 5 years ago

@goodyduru how is work with the web socket going?

JoshOrndorff commented 5 years ago

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

goodyduru commented 5 years ago

@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.

JoshOrndorff commented 5 years ago

@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?

David405 commented 5 years ago

@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?

JoshOrndorff commented 5 years ago

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?
David405 commented 5 years ago

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?

dckc commented 5 years ago

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.

goodyduru commented 5 years ago

Progress so far:

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