-
Notifications
You must be signed in to change notification settings - Fork 0
/
mylla2.cpp
54 lines (43 loc) · 1.24 KB
/
mylla2.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
#include <bits/stdc++.h>
using namespace std;
int main()
{
char board[3][3]; // Stores the board
// Get the board
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
cin >> board[i][j];
}
}
string win = ""; // The winner of the game
// Loop over all verticles and horizontals
for(int i = 0; i < 3; i++)
{
// Check horizontal
if((board[i][0] == board[i][1] && board[i][1] == board[i][2]) && (board[i][0] != '_'))
{
win = board[i][0] == 'O' ? "Jebb" : "Neibb";
}
// Check vertical
if((board[0][i] == board[1][i] && board[1][i] == board[2][i]) && (board[0][i] != '_'))
{
win = board[0][i] == 'O' ? "Jebb" : "Neibb";
}
}
// Check leading diagonal
if((board[0][0] == board[1][1] && board[1][1] == board[2][2]) && (board[0][0] != '_'))
{
win = board[0][0] == 'O' ? "Jebb" : "Neibb";
}
// Check other diagonal
if((board[0][2] == board[1][1] && board[1][1] == board[2][0]) && (board[0][2] != '_'))
{
win = board[0][2] == 'O' ? "Jebb" : "Neibb";
}
// If it's a draw
win = win == "" ? "Neibb" : win;
cout << win << endl;
return 0;
}