-
Notifications
You must be signed in to change notification settings - Fork 54
/
checkWin.c
63 lines (50 loc) · 1.13 KB
/
checkWin.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
/*************************************************************************
> File Name: checkWin.c
> Author: CarlSun
> Mail:sunxiuyang04@gmail.com
> Created Time: Mon Aug 22 21:35:49 2016
************************************************************************/
#include"gomoku.h"
int checkWin(int x,int y,char gomoku[N][N],char flagWin){
int i,j,cou1=0,cou2=0;
for(i=y+1;i<N;i++)//->
if(gomoku[x][i]==flagWin)
cou1++;
else break;
for(i=y-1;i>0;i--)
if(gomoku[x][i]==flagWin)
cou1++;
else break;
if(cou1>=4) return 1;
cou1=0;
for(i=x+1;i<N;i++)
if(gomoku[i][y]==flagWin)
cou1++;
else break;
for(i=x-1;i>0;i--)
if(gomoku[i][y]==flagWin)
cou1++;
else break;
if(cou1>=4) return 1;
cou1=0;
for(i=x+1,j=y+1;i<N,y<N;i++,j++)
if(gomoku[i][j]==flagWin)
cou1++;
else break;
for(i=x-1,j=y-1;i>0,j>0;i--,j--)
if(gomoku[i][j]==flagWin)
cou1++;
else break;
if(cou1>=4) return 1;
cou1=0;
for(i=x-1,j=y+1;i>0,j<N;i--,j++)
if(gomoku[i][j]==flagWin)
cou1++;
else break;
for(i=x+1,j=y-1;i<N,j>0;i++,j--)
if(gomoku[i][j]==flagWin)
cou1++;
else break;
if(cou1>=4) return 1;
return 0;
}