Repository navigation
Expand file tree
/
Copy pathrps.py
More file actions
88 lines (79 loc) · 2.42 KB
/
Copy pathrps.py
File metadata and controls
88 lines (79 loc) · 2.42 KB
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
import random
class RPSAgent:
def __init__(self, preferred_selection=1):
self.preferred_selection = preferred_selection
def getMove(self):
"""
This will get a move with some bias built in.
"""
randNumber = random.random()
if self.preferred_selection == 1:
if randNumber <= 0.6:
return 1
elif randNumber <= 0.8:
return 2
else:
return 3
elif self.preferred_selection == 2:
if randNumber <= 0.6:
return 2
elif randNumber <= 0.8:
return 3
else:
return 1
else:
if randNumber <= 0.6:
return 3
elif randNumber <= 0.8:
return 1
else:
return 2
agent = RPSAgent(random.randint(1,3))
score = {"wins": 0, "losses": 0, "ties": 0}
while True:
inp = input("\nWhat is your input (r/p/s): ")
computer_selection = agent.getMove()
if computer_selection == 1:
print ("\nComputer picks Rock")
elif computer_selection == 2:
print ("\nComputer picks Paper")
elif computer_selection == 3:
print ("\nComputer picks Scissors")
if inp == "q":
break
elif inp == "r":
if computer_selection == 1:
score["ties"] += 1
print ("Tie")
elif computer_selection == 2:
score["losses"] += 1
print ("Loss")
elif computer_selection == 3:
score["wins"] += 1
print ("Win")
elif inp == "p":
if computer_selection == 1:
score["wins"] += 1
print ("Win")
elif computer_selection == 2:
score["ties"] += 1
print ("Tie")
elif computer_selection == 3:
score["losses"] += 1
print ("Loss")
elif inp == "s":
if computer_selection == 1:
score["losses"] += 1
print ("Loss")
elif computer_selection == 2:
score["wins"] += 1
print ("Win")
elif computer_selection == 3:
score["ties"] += 1
print ("Tie")
elif inp == "score":
print("Wins: %d, Losses: %d, Ties: %d" % (score["wins"], score["losses"], score["ties"]))
elif inp == "agent":
print(agent.preferred_selection)
else:
print ("I did not recognize that command")