-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathRPS_v1_old.py
101 lines (82 loc) · 2.45 KB
/
RPS_v1_old.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import serpent
from pyethereum import tester, utils, abi
serpent_code = '''
data winnings_table[3][3]
def init():
#If 0, tie
#If 1, player 1 wins
#If 2, player 2 wins
#0 = rock
#1 = paper
#2 = scissors
self.winnings_table[0][0] = 0
self.winnings_table[1][1] = 0
self.winnings_table[2][2] = 0
#Rock beats scissors
self.winnings_table[0][2] = 1
self.winnings_table[2][0] = 2
#Scissors beats paper
self.winnings_table[2][1] = 1
self.winnings_table[1][2] = 2
#Paper beats rock
self.winnings_table[1][0] = 1
self.winnings_table[0][1] = 2
self.storage["MAX_PLAYERS"] = 2
self.storage["WINNINGS"] = 0
#adds players who send value to the contract to the game
def add_player():
if not self.storage["player1"]:
if msg.value == 1000:
self.storage["WINNINGS"] = self.storage["WINNINGS"] + msg.value
self.storage["player1"] = msg.sender
return(1)
return (0)
elif not self.storage["player2"]:
if msg.value == 1000:
self.storage["WINNINGS"] = self.storage["WINNINGS"] + msg.value
self.storage["player2"] = msg.sender
return(2)
return (0)
else:
return(0)
#stores input "choice" as the respective player's choice
def input(choice):
if self.storage["player1"] == msg.sender:
self.storage["p1value"] = choice
return(1)
elif self.storage["player2"] == msg.sender:
self.storage["p2value"] = choice
return(2)
else:
return(0)
def check():
#If player 1 wins
if self.winnings_table[self.storage["p1value"]][self.storage["p2value"]] == 1:
send(100,self.storage["player1"], self.storage["WINNINGS"])
return(1)
#If player 2 wins
elif self.winnings_table[self.storage["p1value"]][self.storage["p2value"]] == 2:
send(100,self.storage["player2"], self.storage["WINNINGS"])
return(2)
#If no one wins
else:
send(100,self.storage["player1"], self.storage["WINNINGS"]/2)
send(100,self.storage["player2"], self.storage["WINNINGS"]/2)
return(0)
def balance_check():
log(self.storage["player1"].balance)
log(self.storage["player2"].balance)
'''
s = tester.state()
c = s.abi_contract(serpent_code)
o = c.add_player(value=1000,sender=tester.k0)
print("Player 1 Added: {}").format(o)
o = c.add_player(value=1000,sender=tester.k1)
print("Player 2 Added: {}\n").format(o)
o = c.input(2, sender=tester.k0)
print("Player one chooses 2 which is: Scissors")
o = c.input(1, sender=tester.k1)
print("Player two chooses 1 which is: Paper\n")
o = c.check(sender=tester.k1)
print("Check says player {} wins\n").format(o)
c.balance_check(sender=tester.k1)