-
Notifications
You must be signed in to change notification settings - Fork 0
/
challenge6_rock_paper_scissors_lizard_spock.py
107 lines (84 loc) · 3.43 KB
/
challenge6_rock_paper_scissors_lizard_spock.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
102
103
104
105
106
107
"""
Español
Crea un programa que calcule quien gana más partidas al piedra,
papel, tijera, lagarto, spock.
- El resultado puede ser: "Player 1", "Player 2", "Tie" (empate)
- La función recibe un listado que contiene pares, representando cada jugada.
- El par puede contener combinaciones de "🗿" (piedra), "📄" (papel),
"✂️" (tijera), "🦎" (lagarto) o "🖖" (spock).
- Ejemplo. Entrada: [("🗿","✂️"), ("✂️","🗿"), ("📄","✂️")]. Resultado: "Player 2".
- Debes buscar información sobre cómo se juega con estas 5 posibilidades.
Como explica Sheldon, "Tijeras cortan papel, papel cubre piedra, piedra aplasta lagarto,
lagarto envenena a Spock, Spock destruye tijeras, tijeras decapitan lagarto,
lagarto come papel, papel desaprueba a Spock, Spock vaporiza piedra, y como siempre,
piedra aplasta tijeras."
-------------------------------------------------------------------------------
English
Create a programme that calculates who wins more matches in rock, paper,
scissors, lizard, spock.
- The result can be: "Player 1", "Player 2", "Tie"
- The function receives a pair list, in representation of each play-
- The pair can contain combinations of "🗿" (rock), "📄" (paper),
"✂️" (scissors), "🦎" (lizard) o "🖖" (spock).
- For example. Entry: [("🗿","✂️"), ("✂️","🗿"), ("📄","✂️")]. Result: "Player 2".
As Sheldon explains, "Scissors cuts paper, paper covers rock, rock crushes lizard,
lizard poisons Spock, Spock smashes scissors, scissors decapitates lizard,
lizard eats paper, paper disproves Spock, Spock vaporizes rock, and as it always has,
rock crushes scissors."
-------------------------------------------------------------------------------
To solve this problem we are going to create a matrix with the possible options of the
Player 1 in the columns and the possible options of the Player 2 in the rows.
In each cell will be a number:
- 0: if tie
- 1: if wins Player_1
- 2: if wins Player_2
"""
def winner(puntuation_1, puntuation_2):
"""Function that prints the result of the game"""
print("Result of the game: ")
if puntuation_1 > puntuation_2:
return ("Player 1 wins!!")
elif puntuation_2 > puntuation_1:
return ("Player 2 wins!!")
else:
return ("Tie")
def update_score(play_result, array):
"""Funtion that update the game score after a play"""
if play_result == 1:
array[0] += 1
elif play_result == 2:
array[1] += 1
return
results = ([[0, 2, 1, 1, 2],
[1, 0, 2, 2, 1],
[2, 1, 0, 1, 2],
[2, 1, 2, 0, 1],
[1, 2, 1, 2, 0]])
options = {
"rock": 0,
"paper": 1,
"scissors": 2,
"lizard": 3,
"spock": 4
}
def rock_paper_scissors_lizard_spock(games):
puntuation = [0, 0]
for game in games:
play = results[options[f"{game[0]}"]][options[f"{game[1]}"]]
# update score after this last play
update_score(play, puntuation)
# print who wins
return f"{winner(puntuation[0], puntuation[1])}"
# lets play some matches
# Win Player 1
print("Match 1: ")
print(rock_paper_scissors_lizard_spock(
[("rock", "paper"), ("rock", "scissors"), ("scissors", "paper")]))
# Win Player 2
print("\nMatch 2: ")
print(rock_paper_scissors_lizard_spock(
[("rock", "spock"), ("scissors", "lizard"), ("spock", "lizard")]))
# Win
print("\nMatch 3: ")
print(rock_paper_scissors_lizard_spock(
[("paper", "paper"), ("spock", "rock"), ("rock", "paper")]))