-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevent.cpp
152 lines (146 loc) · 4.19 KB
/
event.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "event.h"
int CheckFunction(int IsWhiteMove, GamePlay BoardArray[8][8])
{
int i,j,arr[4],Check;
for (i=0; i<8; i++)
{
for(j=0; j<8; j++)
{
if(IsWhiteMove==0)
{
if(BoardArray[i][j].GetPieceId()==-6)
{
arr[2]=i;
arr[3]=j;
}
}
else
{
if(BoardArray[i][j].GetPieceId()==6)
{
arr[2]=i;
arr[3]=j;
}
}
}
}
for (i=0; i<8; i++)
{
for(j=0; j<8; j++)
{
if(IsWhiteMove==0)
{
if(BoardArray[i][j].GetPieceId()>0)
{
arr[0]=i;
arr[1]=j;
Check=Move(arr, BoardArray);
if(Check)
break;
}
}
else
{
if(BoardArray[i][j].GetPieceId()<0)
{
arr[0]=i;
arr[1]=j;
Check=Move(arr, BoardArray);
if(Check)
break;
}
}
}
}
return Check;
}
int StalemateFunction(int IsWhiteMove, GamePlay BoardArray[8][8], int Stalemate, int MoveSet[27][2])
{
int i,j,k,arr[4],size;
for (i=0; i<8; i++)
{
for(j=0; j<8; j++)
{
if(IsWhiteMove==0)
{
if(BoardArray[i][j].GetPieceId()<0)
{
arr[0]=i;
arr[1]=j;
size=MoveSetFunction(arr, MoveSet, BoardArray);
for(k=0; k<size; k++)
{
arr[2]=MoveSet[k][0];
arr[3]=MoveSet[k][1];
Stalemate=Move(arr, BoardArray);
if(Stalemate)
break;
}
}
}
else
{
if(BoardArray[i][j].GetPieceId()>0)
{
arr[0]=i;
arr[1]=j;
size=MoveSetFunction(arr, MoveSet, BoardArray);
for(k=0; k<size; k++)
{
arr[2]=MoveSet[k][0];
arr[3]=MoveSet[k][1];
Stalemate=Move(arr, BoardArray);
if(Stalemate)
break;
}
}
}
}
}
Stalemate = abs(Stalemate-1);
return Stalemate;
}
int CheckmateFunction(int Check, int Stalemate, int Checkmate)
{
if(Check==1 && Stalemate==1)
Checkmate==1;
return Checkmate;
}
int Castling(int Check, GamePlay Square1, GamePlay Square2, GamePlay BoardArray[8][8])
{
printf("\nIn castling");
int i,j;
if(Check==1)
{
return 0;
}
if(Square2.GetSquareIdY()>Square1.GetSquareIdY())
{
for(i=Square1.GetSquareIdY()+1; i<7; i++)
{
if(BoardArray[Square1.GetSquareIdX()][i].GetPieceId()!=0)
return 0;
}
j=1;
}
else
{
for(i=Square1.GetSquareIdY()-1; i>0; i--)
{
if(BoardArray[Square1.GetSquareIdX()][i].GetPieceId()!=0)
return 0;
}
j=-1;
}
if(abs(BoardArray[Square1.GetSquareIdX()][i].GetPieceId())==2 && BoardArray[Square1.GetSquareIdX()][i].GetHasMoved()==0)
{
BoardArray[Square1.GetSquareIdX()][Square1.GetSquareIdY()+j].SetPieceId(BoardArray[Square1.GetSquareIdX()][i].GetPieceId());
BoardArray[Square1.GetSquareIdX()][i].SetPieceId(0);
BoardArray[Square1.GetSquareIdX()][Square1.GetSquareIdY()+j].SetHasMoved(1);
BoardArray[Square1.GetSquareIdX()][Square1.GetSquareIdY()+(2*j)].SetPieceId(BoardArray[Square1.GetSquareIdX()][Square1.GetSquareIdY()].GetPieceId());
BoardArray[Square1.GetSquareIdX()][Square1.GetSquareIdY()].SetPieceId(0);
BoardArray[Square1.GetSquareIdX()][Square1.GetSquareIdY()+(2*j)].SetHasMoved(1);
return 1;
}
return 0;
}