-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrps2.php
61 lines (61 loc) · 1.71 KB
/
rps2.php
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
<?php
$score = 0;
$rps = fopen("rps.txt", "r");
while (($line = fgets($rps)) !== false) {
$rpsarr = explode(" ", $line);
//var_dump($rpsarr);
$elf = $rpsarr[0];
$me = substr($rpsarr[1], 0, 1);
echo $elf." - ".$me;
if ($me == "X") { //Lose!
switch ($elf) {
case "A":
$me = "Z";
break;
case "B":
$me = "X";
break;
case "C":
$me = "Y";
}
} elseif ($me == "Y") { //tie!
switch ($elf) {
case "A":
$me = "X";
break;
case "B":
$me = "Y";
break;
case "C":
$me = "Z";
}
} else { //win!
switch ($elf) {
case "A":
$me = "Y";
break;
case "B":
$me = "Z";
break;
case "C":
$me = "X";
}
}
if (($elf == "A" && $me == "X") || ($elf == "B" && $me=="Y") || ($elf[0] == "C" && $me=="Z")){ //on tie add 3
echo " Tie!\n";
if ($me == "X") $score = $score+1+3;
if ($me == "Y") $score = $score+2+3;
if ($me == "Z") $score = $score+3+3;
} elseif (($elf == "A" && $me == "Z") || ($elf == "B" && $me == "X") || ($elf == "C" && $me == "Y")) { //Me lose add 6
echo " Lose\n";
if ($me == "X") $score = $score+1;
if ($me == "Y") $score = $score+2;
if ($me == "Z") $score = $score+3;
} else { //on Win
echo " Win\n";
if ($me == "X") $score = $score+1+6;
if ($me == "Y") $score = $score+2+6;
if ($me == "Z") $score = $score+3+6;
}
}
echo $score;