-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmoveset.cpp
108 lines (98 loc) · 3.58 KB
/
moveset.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
#include "moveset.h"
int size;
int Displacement[8][2]={{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1}};
int DisplacementKnight[8][2]={{-2,-1},{-2,1},{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2}};
void PawnMoveSet(GamePlay Square1, int MoveSet[27][2], GamePlay BoardArray[8][8])
{
int i;
for(i=0; i<3; i++)
{
if(Square1.GetPieceId()>0)
{
MoveSet[i][0]=BoardArray[Square1.GetSquareIdX()-1][Square1.GetSquareIdY()-1+i].GetSquareIdX();
MoveSet[i][1]=BoardArray[Square1.GetSquareIdX()-1][Square1.GetSquareIdY()-1+i].GetSquareIdY();
}
else
{
MoveSet[i][0]=BoardArray[Square1.GetSquareIdX()+1][Square1.GetSquareIdY()-1+i].GetSquareIdX();
MoveSet[i][1]=BoardArray[Square1.GetSquareIdX()+1][Square1.GetSquareIdY()-1+i].GetSquareIdY();
}
}
size = i;
}
void RookMoveSet(GamePlay Square1, int MoveSet[27][2], GamePlay BoardArray[8][8])
{
int i,j=1;
for(i=0; i<4; i++)
{
MoveSet[i][0]=BoardArray[Square1.GetSquareIdX()+Displacement[j][0]][Square1.GetSquareIdY()+Displacement[j][1]].GetSquareIdX();
MoveSet[i][1]=BoardArray[Square1.GetSquareIdX()+Displacement[j][0]][Square1.GetSquareIdY()+Displacement[j][1]].GetSquareIdY();
j=j+2;
}
size = 4;
}
void KnightMoveSet(GamePlay Square1, int MoveSet[27][2], GamePlay BoardArray[8][8])
{
int i,j=0;
for(i=0; i<8; i++)
{
MoveSet[i][0]=BoardArray[Square1.GetSquareIdX()+DisplacementKnight[j][0]][Square1.GetSquareIdY()+DisplacementKnight[j][1]].GetSquareIdX();
MoveSet[i][1]=BoardArray[Square1.GetSquareIdX()+DisplacementKnight[j][0]][Square1.GetSquareIdY()+DisplacementKnight[j][1]].GetSquareIdY();
j++;
}
size = 8;
}
void BishopMoveSet(GamePlay Square1, int MoveSet[27][2], GamePlay BoardArray[8][8])
{
int i,j=0;
for(i=0; i<4; i++)
{
MoveSet[i][0]=BoardArray[Square1.GetSquareIdX()+Displacement[j][0]][Square1.GetSquareIdY()+Displacement[j][1]].GetSquareIdX();
MoveSet[i][1]=BoardArray[Square1.GetSquareIdX()+Displacement[j][0]][Square1.GetSquareIdY()+Displacement[j][1]].GetSquareIdY();
j=j+2;
}
size = 4;
}
void QueenMoveSet(GamePlay Square1, int MoveSet[27][2], GamePlay BoardArray[8][8])
{
int i,j=0;
for(i=0; i<4; i++)
{
MoveSet[i][0]=BoardArray[Square1.GetSquareIdX()+Displacement[j][0]][Square1.GetSquareIdY()+Displacement[j][1]].GetSquareIdX();
MoveSet[i][1]=BoardArray[Square1.GetSquareIdX()+Displacement[j][0]][Square1.GetSquareIdY()+Displacement[j][1]].GetSquareIdY();
j++;
}
size = 4;
}
void KingMoveSet(GamePlay Square1, int MoveSet[27][2], GamePlay BoardArray[8][8])
{
int i,j=0;
for(i=0; i<4; i++)
{
MoveSet[i][0]=BoardArray[Square1.GetSquareIdX()+Displacement[j][0]][Square1.GetSquareIdY()+Displacement[j][1]].GetSquareIdX();
MoveSet[i][1]=BoardArray[Square1.GetSquareIdX()+Displacement[j][0]][Square1.GetSquareIdY()+Displacement[j][1]].GetSquareIdY();
j++;
}
size = 4;
}
int MoveSetFunction(int arr[4], int MoveSet[27][2], GamePlay BoardArray[8][8])
{
GamePlay Square1;
Square1.Copy(BoardArray[arr[0]][arr[1]]);
switch(abs(Square1.GetPieceId()))
{
case 1: PawnMoveSet(Square1, MoveSet, BoardArray);
break;
case 2: RookMoveSet(Square1, MoveSet, BoardArray);
break;
case 3: KnightMoveSet(Square1, MoveSet, BoardArray);
break;
case 4: BishopMoveSet(Square1, MoveSet, BoardArray);
break;
case 5: QueenMoveSet(Square1, MoveSet, BoardArray);
break;
case 6: KingMoveSet(Square1, MoveSet, BoardArray);
break;
}
return size;
}