-
Notifications
You must be signed in to change notification settings - Fork 0
/
medium.h
51 lines (48 loc) · 1.43 KB
/
medium.h
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
#ifndef MEDIUM_H
#define MEDIUM_H
#include "tic_tac_toe.h"
class medium : public tic_tac_toe
{
private:
virtual void move()
{
//массив с номерами пустых ячеек и их количество
int a[9], n = 0;
//ищем все свободные ячейки, в которых возможна победа
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
if (field[i][j] == '-')
{
a[n++] = (i) * 3 + (j + 1);
}
}
}
//выбираем случайную пустую ячейку
srand(time(NULL));
int num = a[rand() % n];
//делаем ход игрока
if (isCompFirst)
{
//если есть выиграшная ячейка, ставим туда
if (this->getWinCell('X'))
{
num = this->getWinCell('X');
}
field[num / 3][num % 3 - 1] = 'X';
}
else
{
//если есть выиграшная ячейка, ставим туда
if (this->getWinCell('O'))
{
num = this->getWinCell('O');
}
field[num / 3][num % 3 - 1] = 'O';
}
}
public:
medium() {}
};
#endif // MEDIUM_H