-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRook.cpp
More file actions
86 lines (70 loc) · 1.99 KB
/
Copy pathRook.cpp
File metadata and controls
86 lines (70 loc) · 1.99 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
// Bryan Liu (chl312), Dept. of Computing, Imperial College London
// Rook.cpp - implementation of Rook extending Piece (info in Rook.hpp)
#include "pch.h"
#include "Rook.hpp"
Rook::Rook(bool isWhitePlayer) : Piece(isWhitePlayer)
{
}
Rook::~Rook()
{
}
Rook* Rook::clone()
{
return new Rook(this->isWhitePlayer());
}
/* A Rook's move is valid if:
- Destination is on the same file/rank (note: mutually exclusive)
- There are no other pieces in intermediate spaces
- Piece at destination, if exist, is not a friendly
(or there are no piece at destination)
Rook.isValidMove() post-cond: return 0 if move is valid
respective error code otherwise
*/
int Rook::isValidMove(wstring sourceFileRank, wstring destFileRank, map<wstring, Piece*>* board)
{
if (isSameFile(sourceFileRank, destFileRank) &&
isSameRank(sourceFileRank, destFileRank))
{
return ChessErrHandler::DEST_EQ_SOURCE;
}
if (!(isSameFile(sourceFileRank, destFileRank) ||
isSameRank(sourceFileRank, destFileRank)))
{
return ChessErrHandler::ILLEGAL_MOVE_PATTERN;
}
/* Obstruction for a Rook only occurs if it is on its intended way
Lazy boolean evalution of C++ ensure !no_Obstruction is evaluated only
after satisfying isSame_, prevents breaking pre-cond of no_Obstruction
*/
if ((isSameFile(sourceFileRank, destFileRank) &&
!noVerticalObstruction(sourceFileRank, destFileRank, board)) ||
(isSameRank(sourceFileRank, destFileRank) &&
!noHorizontalObstruction(sourceFileRank, destFileRank, board)))
{
return ChessErrHandler::OBSTRUCTION_EN_ROUTE;
}
if (destExistFriendlyPiece(destFileRank, board))
{
return ChessErrHandler::FRIENDLY_AT_DEST;
}
return ChessErrHandler::CHESS_NO_ERROR;
}
wstring Rook::toString()
{
wstring name(playerToString());
name.append(_T(" Rook"));
return name;
}
wstring Rook::toGraphics()
{
if (_isWhitePlayer) {
// return wstring("♖");
return wstring(_T("\x2656"));
}
// return wstring("♜");
return wstring(_T("\x265C"));
}
int Rook::Score()
{
return 10;
}