-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheck_diag.pl
More file actions
32 lines (30 loc) · 841 Bytes
/
Copy pathCheck_diag.pl
File metadata and controls
32 lines (30 loc) · 841 Bytes
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
sub Check_diag {
# Checks if there's a match for diags
my (@myarray, $choice) = @_;
# This checks top-left to bottom-right to see if there is a diagonal win
if (($myarray[0][0] == $myarray[1][1]) &&
($myarray[1][1] == $myarray[2][2]) && $myarray[0][0] != 0) {
if ($choice == 1 && $myarray[2][2] == 2) {
print "CPU WON!\n";
}
else {
print "Player " . $myarray[2][2] . " WON!\n";
}
return 1; # Returns True
}
# This checks top-right to bottom-left to see if there is a diagonal win
elsif (($myarray[0][2] == $myarray[1][1]) &&
($myarray[1][1] == $myarray[2][0]) && $myarray[0][2] != 0) {
if ($choice == 1 && $myarray[2][0] == 2) {
print "CPU WON!\n";
}
else {
print "Player " . $myarray[2][0] . " WON!\n";
}
return 1; # Returns True
}
else {
return 0; # Returns False
}
}
1;