-
Notifications
You must be signed in to change notification settings - Fork 0
/
funcs.h
55 lines (50 loc) · 1.58 KB
/
funcs.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
52
53
54
55
int userInput(void) {
int input = -1;
do {
printf("please enter column: ");
scanf("%i", &input);
} while ((input < 0) || (input > 6));
}
bool winCondition(char board[7][7]) {
//vertical win conditions
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if ((isalpha(board[j][i])) && (board[j][i] == board[j+1][i]) &&
(board[j][i] == board[j+2][i]) && (board[j][i] == board[j+3][i])) {
printf("%c has won!\n", board[j][i]);
return true;
}
}
}
//horizontal win conditions
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if ((isalpha(board[j][i])) && (board[j][i] == board[j][i+1]) &&
(board[j][i] == board[j][i+2]) && (board[j][i] == board[j][i+3])) {
printf("%c has won!\n", board[j][i]);
return true;
}
}
}
//diagonal down win conditions
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if ((isalpha(board[j][i])) && (board[j][i] == board[j+1][i+1]) &&
(board[j][i] == board[j+2][i+2]) && (board[j][i] == board[j+3][i+3])) {
printf("%c has won!\n", board[j][i]);
return true;
}
}
}
//diagonal up win conditions
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
if ((isalpha(board[j][i])) && (board[j][i] == board[j+1][i-1]) &&
(board[j][i] == board[j+2][i-2]) && (board[j][i] == board[j+3][i-3])) {
printf("%c has won!\n", board[j][i]);
return true;
}
}
}
return false;
}