-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmove.cpp
More file actions
101 lines (81 loc) · 2 KB
/
Copy pathmove.cpp
File metadata and controls
101 lines (81 loc) · 2 KB
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
#pragma once
#include "move.h"
Move::Move(int from, int to, int piece, int capturedPiece, int specialMove)
:move(((specialMove & 0xf) << 20) | ((capturedPiece & 0xf) << 16) | ((piece & 0xf) << 12) | ((to & 0x3f) << 6) | (from & 0x3f)) {
}
int Move::getFrom()
{
return (move & 0x3f);
}
int Move::getTo()
{
return ((move >> 6) & 0x3f);
}
int Move::getPiece()
{
return ((move >> 12) & 0xf);
}
int Move::getPieceColor()
{
return pieceColor::getPieceColor((Piece)getPiece());
}
int Move::getPieceGroup()
{
return (pieceColor::getPieceColor((Piece)getPiece()) == White) ? Whites : Blacks;
}
int Move::getCapturedPiece()
{
return (move >> 16) & 0xf;
}
int Move::getSpecialMove()
{
return (move >> 20) & 0xf;
}
bool Move::isCapture()
{
return getCapturedPiece() != EMPTY;
}
bool Move::isPromotion()
{
return ((move >> 20) & 0xf) >= QUEEN_PROM && ((move >> 20) & 0xf) <= KNIGHT_PROM;
}
bool Move::isCastling()
{
return ((move >> 20) & 0xf) == KING_CASTLING || ((move >> 20) & 0xf) == QUEEN_CASTLING;
}
void Move::setPromotion(int promotionPiece) // can be done maybe better
{
move &= ~(0xfff << 20);
move |= (promotionPiece & 0xf) << 20;
}
std::string Move::getStr()
{
const std::string files[] = {"a", "b", "c", "d", "e", "f", "g", "h"};
std::string str = files[getFrom() % 8] + std::to_string(8 - getFrom() / 8) + files[getTo() % 8] + std::to_string(8 - getTo() / 8);
if (isPromotion()) {
if (getSpecialMove() == QUEEN_PROM)
str.append("q");
else if (getSpecialMove() == ROOK_PROM)
str.append("r");
else if (getSpecialMove() == KNIGHT_PROM)
str.append("n");
else if (getSpecialMove() == BISHOP_PROM)
str.append("b");
}
return str;
}
PosInfo::PosInfo(int castlingRights, int epSquare, int halfMoveClock)
: posInfo(((halfMoveClock & 0x7f) << 10) | ((epSquare & 0x3f) << 4) | (castlingRights & 0xf)) {
}
int PosInfo::getCastlingRights()
{
return posInfo & 0xf;
}
int PosInfo::getEpSquare()
{
return (posInfo >> 4) & 0x3f;
}
int PosInfo::getHalfMoveClock()
{
return (posInfo >> 10) & 0x7f;
}