forked from HYanofsky/SOS-Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_sos.c
96 lines (85 loc) · 2.03 KB
/
find_sos.c
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
#include <stdio.h>
#include <sos.h>
char board[50][50];
int Player1, Player2, Computer, players, n;
int find_sos (int square, int player, char symbol)
{
int row,col,sos;
row = (square-1)/n;
col = (square-1)%n;
sos = 0;
if(symbol == 'S')
{
if ((board[row][col-2] == 'S') && (board[row][col-1] == 'O'))
{
sos++;
}
if ((board[row][col+1]== 'O') && (board[row][col+2] == 'S'))
{
sos++;
}
if((board[row+1][col] == 'O') && (board[row+2][col] == 'S'))
{
sos++;
}
if((board[row-1][col] == 'O') && (board[row-2][col] == 'S'))
{
sos++;
}
if((board[row+1][col+1] == 'O') && (board[row+2][col+2] == 'S'))
{
sos++;
}
if((board[row-1][col-1] == 'O') && (board[row-2][col-2] == 'S'))
{
sos++;
}
if((board[row+1][col-1] == 'O') && (board[row+2][col-2] == 'S'))
{
sos++;
}
if((board[row-1][col+1] == 'O') && (board[row-2][col+2] == 'S'))
{
sos++;
}
}
else if(symbol == 'O')
{
if((board[row+1][col] == 'S') && (board[row-1][col] == 'S'))
{
sos++;
}
if((board[row][col+1] == 'S') && (board[row][col-1] == 'S'))
{
sos++;
}
if((board[row+1][col+1] == 'S') && (board[row-1][col-1] == 'S'))
{
sos++;
}
if((board[row+1][col-1] == 'S') && (board[row-1][col+1] == 'S'))
{
sos++;
}
}
if (player == 1)
{
Player1= Player1+sos;
}
else if (player == 2)
{
Player2= Player2+sos;
}
else if (player == 3)
{
Computer= Computer+sos;
}
if (sos>0)
{
return 1;
}
else
{
return 0;
}
}