Skip to content
This repository has been archived by the owner on Jun 17, 2020. It is now read-only.

Rock Paper Scissors Example dApp in Python #996

Open
JoshOrndorff opened this issue Oct 6, 2018 · 18 comments
Open

Rock Paper Scissors Example dApp in Python #996

JoshOrndorff opened this issue Oct 6, 2018 · 18 comments
Labels
developer-education guide: @JoshyOrndorff cf. #692 Sep 29

Comments

@JoshOrndorff
Copy link

JoshOrndorff commented Oct 6, 2018

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:

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

@Ojimadu Ojimadu added the developer-education guide: @JoshyOrndorff cf. #692 Sep 29 label Oct 6, 2018
@goodyduru
Copy link

Hi, I want to take a shot at this.

@goodyduru
Copy link

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

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

sypha999 commented Oct 9, 2018

I would love to help too, I code with python

@sypha999
Copy link

sypha999 commented Oct 9, 2018

@whereyouatwimm am daton#4414 on discord

@JoshOrndorff
Copy link
Author

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
Copy link
Author

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

@David405
Copy link

David405 commented Oct 9, 2018

@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
Copy link

@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
Copy link

David405 commented Oct 22, 2018

@goodyduru how is work with the web socket going?

@JoshOrndorff
Copy link
Author

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

@goodyduru
Copy link

@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
Copy link
Author

@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
Copy link

@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
Copy link
Author

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

David405 commented Nov 5, 2018

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
Copy link
Contributor

dckc commented Nov 6, 2018

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

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
developer-education guide: @JoshyOrndorff cf. #692 Sep 29
Projects
None yet
Development

No branches or pull requests

7 participants