-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathox.php
More file actions
144 lines (106 loc) · 2.89 KB
/
ox.php
File metadata and controls
144 lines (106 loc) · 2.89 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
function win($array) {
if ( ($arr[0][0] && $arr[0][1] && $arr[0][2] == "x") || ($arr[1][0]&&$arr[1][1]&&$arr[1][2]=="x") || ($arr[2][0] && $arr[2][1] && $arr[2][2] =="x") || ($arr[0][0] && $arr[1][0] && $arr[2][0]=="x") || ($arr[0][1] && $arr[1][1] && $arr[1][2]=="x") || ($arr[2][0] && $arr[1][2] && $arr[2][2]=="x") || ($arr[0][0] && $arr[1][1] && $arr[2][2]=="x") || ($$arr[0][2] && $arr[1][1] && $arr[2][0]=="x")) {
echo "X-Team Win!";
}
elseif ( ($arr[0][0] && $arr[0][1] && $arr[0][2] == "o") || ($arr[1][0]&&$arr[1][1]&&$arr[1][2]=="o") || ($arr[2][0] && $arr[2][1] && $arr[2][2] =="o") || ($arr[0][0] && $arr[1][0] && $arr[2][0]=="o") || ($arr[0][1] && $arr[1][1] && $arr[1][2]=="o") || ($arr[2][0] && $arr[1][2] && $arr[2][2]=="o") || ($arr[0][0] && $arr[1][1] && $arr[2][2]=="o") || ($arr[0][2] && $arr[1][1] && $arr[2][0]=="o") ) {
echo "O-Team Win!";}
else {echo "Win Friendship :)";}
}
$fullfield = ["","","","","","","","",""];
$field = array_chunk($fullfield,3);
function playX($arr) {
start:
echo "choose field\n";
$handler = fopen("php://stdin","r");
$choise = fgets($handler);
if ($choise ==1) {
$arr [0][0] = "x";
}
elseif($choise==2) {
$arr[0][1] = "x";
}
elseif($choise==3) {
$arr[0][2] = "x";
}
elseif($choise==4) {
$arr[1][0] = "x";
}
elseif($choise==5) {
$arr[1][1] = "x";
}
elseif($choise==6) {
$arr[1][2] = "x";
}
elseif($choise==7) {
$arr[2][0] = "x";
}
elseif($choise==8) {
$arr[2][1] = "x";
}
elseif($choise==9) {
$arr[2][2] = "x";
}
else {
echo 'enter again field!';
goto start;
}
return $arr;
}
function playO($arr) {
start:
echo "choose field\n";
$handler = fopen("php://stdin","r");
$choise = fgets($handler);
if ($choise ==1) {
$arr[0][0] = "o";
}
elseif($choise == 2) {
$arr[0][1] = "o";
}
elseif($choise==3) {
$arr[0][2] = "o";
}
elseif($choise==4) {
$arr[1][0] = "o";
}
elseif($choise==5) {
$arr[1][1] = "o";
}
elseif($choise==6) {
$arr[1][2] = "o";
}
elseif($choise==7) {
$arr[2][0] = "o";
}
elseif($choise==8) {
$arr[2][1] = "o";
}
elseif($choise==9) {
$arr[2][2] = 'o';
}
else {
echo 'enter again field!';
goto start;
}
return $arr;
}
$step1 = playX($field);
$field = $step1;
$step2 = playO($field);
$field = $step2;
$step3 = playX($field);
$field = $step3;
$step4 = playO($field);
$field = $step4;
$step5 = playX($field);
$field = $step5;
$step6 = playO($field);
$field = $step6;
$step7 = playX($field);
$field = $step7;
$step8 = playO($field);
$field = $step8;
$step9 = playX($field);
$field = $step9;
var_dump($field);