-
Notifications
You must be signed in to change notification settings - Fork 0
/
TicTac.php
121 lines (114 loc) · 3.8 KB
/
TicTac.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
/**
* Created by PhpStorm.
* User: Zver
* Date: 19.02.2019
* Time: 14:16
*/
class TicTac
{
public $array = array();
public $x;
public $y;
public $counter = 0;
public function simpleTicTack($n)
{
for ($i = 0; $i < $n; $i ++)
{
for ($j = 0; $j < $n; $j++)
{
$array[$i][$j] = ' ';
}
}
}
public function getStep()
{
$this->x = $_POST['x'];
$this->y = $_POST['y'];
$this->array[$this->x][$this->y] = 'X';
$this->counter ++;
echo 'Ход №'.$this->counter.' сделан: ('.$this->x.', '.$this->y.') <br>';
$n = 3;
echo '<table class="table table-bordered table-dark">';
echo '<thead>
<tr>
<th scope="col">#</th>
<th scope="col">0</th>
<th scope="col">1</th>
<th scope="col">2</th>
</tr>
</thead>';
echo '<tbody>';
for ($i = 0; $i < $n; $i++) {
echo '<tr><th scope="row">'.$i.'</th>';
for ($j = 0; $j < $n; $j++) {
echo '<td>' . $this->array[$i][$j]. '</td>';
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
// return $this->array;
}
public function getStepZeroPlayer()
{
$this->x = 3;
$this->y = 2;
$this->array[$this->x][$this->y] = 'O';
$this->counter ++;
echo 'Ход №'.$this->counter.' сделан: ('.$this->x.', '.$this->y.') <br>';
$n = 3;
echo '<table class="table table-bordered table-dark">';
echo '<thead>
<tr>
<th scope="col">#</th>
<th scope="col">0</th>
<th scope="col">1</th>
<th scope="col">2</th>
</tr>
</thead>';
echo '<tbody>';
for ($i = 0; $i < $n; $i++) {
echo '<tr><th scope="row">'.$i.'</th>';
for ($j = 0; $j < $n; $j++) {
echo '<td>' . $this->array[$i][$j]. '</td>';
}
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
}
/*
* Порядок игры:
* сначала пустое поле
* Ход первого игрока
* Оценка ситуации-> затем ход второго, проверка возможности походить(если даное поле не занято)
* Ход второго-> оценка ситуации -> ход
* Передача хода другому игроку
* 2 варианта игры Чел-Чел, Чел-Бот, Бот-Бот
*/
public function afterStep()
{
/*
* 00 01 02
* 10 11 12
* 20 21 22
*
* 8 вариантов трех значений подряд XXX || OOO
* условие победы - окончание игры
$endGame = false;
if (($this->array[0][0] == $this->array[0][1] && $this->array[0][1] == $this->array[0][2]) ||
($this->array[1][0] == $this->array[1][1] && $this->array[1][1] == $this->array[1][2]) ||
($this->array[2][0] == $this->array[2][1] && $this->array[2][1] == $this->array[2][2]) ||
($this->array[0][0] == $this->array[1][0] && $this->array[1][0] == $this->array[2][0]) ||
($this->array[0][1] == $this->array[1][1] && $this->array[1][1] == $this->array[2][1]) ||
($this->array[0][2] == $this->array[1][2] && $this->array[1][2] == $this->array[2][2]) ||
($this->array[0][0] == $this->array[1][1] && $this->array[1][1] == $this->array[2][2]) ||
($this->array[0][2] == $this->array[1][1] && $this->array[1][1] == $this->array[2][0])
)
{
$endGame = true;
}
*/
}
}