-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicTacToec.cpp
76 lines (66 loc) · 1.12 KB
/
TicTacToec.cpp
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
#include "TicTacToe.h"
char TicTacToe::checkWinner()
{
char winner = EMPTY;
for(int i = 0; i <=2; ++i)
{
if(board.at(i) == board.at(i + 3) && board.at(i + 3) == board.at(i + 6))
{
if(board.at(i)!=EMPTY)
{
winner = board.at(i);
break;
}
}
if(board.at(3*i) == board.at(3*i + 1) && board.at(3*i + 1) == board.at(3*i + 2))
{
if(board.at(3*i)!=EMPTY)
{
winner = board.at(3*i);
break;
}
}
}
if(board.at(2) == board.at(4) && board.at(4) == board.at(6))
{
if(board.at(2)!=EMPTY)
{
winner = board.at(2);
}
}
if(board.at(0) == board.at(4) && board.at(4) == board.at(8))
{
if(board.at(0)!=EMPTY)
{
winner = board.at(0);
}
}
return winner;
}
void TicTacToe::makeMove()
{
char winner;
srand(time(NULL));
int rPos;
do
{
rPos = rand()%9;
}
while(board.at(rPos) != EMPTY);
board.at(rPos) = 'o';
}
/*
if(winner!=EMPTY)
{
switch(winner)
{
case 'x':
writeSocket("PRIVMSG #" + pb.input["room"] + ":You win! =[" + "\r\n");
break;
case 'o':
writeSocket("PRIVMSG #" + pb.input["room"] + ":I win! =]" + "\r\n");
break;
}
board.fill(EMPTY);
}
*/