Skip to content

Latest commit

 

History

History
88 lines (60 loc) · 1.42 KB

PEX_TODO.md

File metadata and controls

88 lines (60 loc) · 1.42 KB

Create a RPS Nada Program

We'll use the nada tool to create a new project

https://docs.nillion.com/nada

  1. Create an rps nada project
nada init rps
  1. Go into the rps folder
cd rps
  1. Write the RPS program in main.py (if you get stuck, check nada/src/main.py)
  • Initialize 2 parties: computer and player
party_computer = Party(name="Computer")
party_player = Party(name="Player")
  • Add each player's choice as a named SecretInput
choice_computer = SecretInteger(Input(name="choice_computer", party=party_computer))
choice_player_2 = SecretInteger(Input(name="choice_player_2", party=party_player))

  • Adjust choice values (original secrets can't be 0 values)
adjusted_choice_computer = (choice_computer - Integer(10)) % Integer(3)
adjusted_choice_player_2 = (choice_player_2 - Integer(10)) % Integer(3)
  • Compute result
result = (adjusted_choice_computer - adjusted_choice_player_2 + Integer(3)) % Integer(3)
  • Determine winner
winner = (
    (result > Integer(0)).if_else(
        (result > Integer(1)).if_else(Integer(2), Integer(1)),
        Integer(0)
    )
)
  • Create an output variable
out = Output(winner, "game_result", party_computer)
  • Return the output
return [out]
  1. Build (compile) the program
nada build
  1. Generate a test file
nada generate-test --test-name test_r_p main
  1. Modify and run test
nada test test_r_p