forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asjordi.java
50 lines (33 loc) · 1.61 KB
/
asjordi.java
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
import java.util.*;
public class RockPaperScissorsLizardSpock {
public static void main(String[] args) {
RockPaperScissorsLizardSpock r = new RockPaperScissorsLizardSpock();
String[][] games = new String[][]{{"piedra", "tijera"}, {"tijera", "piedra"}, {"papel", "tijera"}};
// String[][] games = new String[][]{{"piedra", "piedra"}};
// String[][] games = new String[][]{{"piedra", "piedra"}, {"piedra", "piedra"}, {"piedra", "piedra"}, {"piedra", "piedra"}};
// String[][] games = new String[][]{{"spock", "piedra"}, {"tijeras", "papel"}, {"piedra", "piedra"}, {"lagarto", "spock"}};
}
public String playGame(String[][] games) {
int winsPlayerOne = 0;
int winsPlayerTwo = 0;
Map<String, String[]> rules = new HashMap<>();
rules.put("piedra", new String[] {"tijera", "lagarto"});
rules.put("papel", new String[] {"piedra", "spock"});
rules.put("tijera", new String[] {"papel", "lagarto"});
rules.put("lagarto", new String[] {"spock", "papel"});
rules.put("spock", new String[] {"piedra", "tijera"});
for (String[] g : games){
String p1 = g[0];
String p2 = g[1];
if (!Objects.equals(p1, p2)) {
String res = Arrays.toString(rules.get(p1));
if (res != null && res.contains(p2)) {
winsPlayerOne ++;
} else {
winsPlayerTwo ++;
}
}
}
return winsPlayerOne == winsPlayerTwo ? "Tie": winsPlayerOne > winsPlayerTwo ? "Player 1" : "Player 2";
}
}