-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.cc
78 lines (62 loc) · 1.91 KB
/
move.cc
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
#include "move.h"
#include "board.h"
Move::Move() : from{Square::a1}, to{Square::a1}, moveType{Normal}, promotionType{Piece::Knight} {}
Move::Move(Square from, Square to, Move::MoveType moveType, Piece promoType) : from{from}, to{to}, moveType{moveType}, promotionType{promoType} { }
bool Move::operator==(const Move& other) const {
return from == other.from && to == other.to && moveType == other.moveType && promotionType == other.promotionType;
}
bool Move::operator!=(const Move& other) const {
return !(*this == other);
}
Square Move::getFrom() const {
return from;
}
Square Move::getEnpassantSquareCaptured(Color turn) const {
assert(moveType == Enpassant);
return getSquareFromIndex(to - 8 + (turn << 4));
}
bool Move::isMoveNone() const {
return from == Square::a1 && to == Square::a1 && moveType == Normal && promotionType == Piece::Knight;
}
bool Move::isMovePromotion() const {
return getMoveType() == Promotion;
}
Square Move::getTo() const {
return to;
}
Move::MoveType Move::getMoveType() const {
return moveType;
}
Piece Move::getPromoType() const {
return promotionType;
}
void Move::print(std::ostream& out) const {
out << toString() << std::endl;
}
std::string Move::toString() const {
Square from = getFrom();
Square to = getTo();
std::string fr = Board::squareToString(from);
std::string t = Board::squareToString(to);
fr += t;
if(isMovePromotion()) {
switch(getPromoType()) {
case Piece::King:
case Piece::Pawn:
return "AHHHHHHHHHHH"; // That's no bueno. Our input handler takes care of it though!
case Piece::Knight:
fr += "N";
break;
case Piece::Bishop:
fr += "B";
break;
case Piece::Rook:
fr += "R";
break;
case Piece::Queen:
fr += "Q";
break;
}
}
return fr;
}