-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovelist.cpp
81 lines (66 loc) · 2.11 KB
/
movelist.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
#include "movelist.h"
MoveList::MoveList() {}
void MoveList::clear() {
moves.clear();
}
void MoveList::append(QString move) {
char fromCol = move[0].toLatin1() - 'a';
char fromRow = move[1].toLatin1() - '1';
char toCol = move[2].toLatin1() - 'a';
char toRow = move[3].toLatin1() - '1';
Square from(fromCol, fromRow);
Square to(toCol, toRow);
moves.append(new Move{from, to, 0, 0, 0, 0, 0});
}
void MoveList::append(Move move) {
moves.append(new Move{move.from, move.to, 0, 0, 0, 0, 0});
}
void MoveList::analyzeMoves(const Square board[COLS][ROWS]) {
// ======= CASTLING
int index = indexOf("e1","g1");
if(index != -1 && board['e'-'a'][0].getPiece() == Piece::W_KING)
moves[index]->isCastling = true;
index = indexOf("e1","c1");
if(index != -1 && board['e'-'a'][0].getPiece() == Piece::W_KING)
moves[index]->isCastling = true;
index = indexOf("e8","c8");
if(index != -1 && board['e'-'a'][7].getPiece() == Piece::B_KING)
moves[index]->isCastling = true;
index = indexOf("e8","g8");
if(index != -1 && board['e'-'a'][7].getPiece() == Piece::B_KING)
moves[index]->isCastling = true;
}
MoveList MoveList::movesFrom(Square from) {
MoveList res;
for(Move* move : moves)
if(move->from == from)
res.append(*move);
return res;
}
int MoveList::indexOf(QString from, QString to) {
for(int i = 0; i < moves.size(); i++)
if(moves[i]->from == from && moves[i]->to == to)
return i;
return -1;
}
bool MoveList::contains(Square from, Square to) {
for(int i = 0; i < moves.size(); i++)
if(moves[i]->from == from && moves[i]->to == to)
return true;
return false;
}
bool MoveList::contains(QString from, Square to) {
for(int i = 0; i < moves.size(); i++)
if(moves[i]->from == from && moves[i]->to == to)
return true;
return false;
}
bool MoveList::contains(Square to) {
for(int i = 0; i < moves.size(); i++)
if(moves[i]->to == to)
return true;
return false;
}
int MoveList::size() {
return moves.size();
}