-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBishop.cpp
More file actions
77 lines (60 loc) · 1.63 KB
/
Copy pathBishop.cpp
File metadata and controls
77 lines (60 loc) · 1.63 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
// Bryan Liu (chl312), Dept. of Computing, Imperial College London
// Bishop.cpp - implementation of Bishop extending Piece (info in Bishop.hpp)
#include "pch.h"
#include "Bishop.hpp"
Bishop::Bishop(bool isWhitePlayer) : Piece(isWhitePlayer) {
}
Bishop::~Bishop() {
}
Bishop* Bishop::clone()
{
return new Bishop(this->isWhitePlayer());
}
/* A Bishop's move is valid if:
- The destination is on the same diagonal as its current position
- There is no obstruction (any piece) in intermediate squares
- The (possibly) existing piece on destination square is not a friendly
(or destination is empty)
Bishop.isValidMove() post-cond: retrun 0 if move is valid as above
respective error code otherwise
*/
int Bishop::isValidMove(wstring sourceFileRank, wstring destFileRank, map<wstring, Piece*>* board)
{
if (isSameFile(sourceFileRank, destFileRank) &&
isSameRank(sourceFileRank, destFileRank))
{
return ChessErrHandler::DEST_EQ_SOURCE;
}
if (!isSameDiagonal(sourceFileRank, destFileRank))
{
return ChessErrHandler::ILLEGAL_MOVE_PATTERN;
}
if (!noDiagonalObstruction(sourceFileRank, destFileRank, board))
{
return ChessErrHandler::OBSTRUCTION_EN_ROUTE;
}
if (destExistFriendlyPiece(destFileRank, board))
{
return ChessErrHandler::FRIENDLY_AT_DEST;
}
return ChessErrHandler::CHESS_NO_ERROR;
}
wstring Bishop::toString()
{
wstring name(playerToString());
name.append(_T(" Bishop"));
return name;
}
wstring Bishop::toGraphics()
{
if (_isWhitePlayer) {
// return wstring("♗");
return wstring(_T("\x2657"));
}
// return wstring("♝");
return wstring(_T("\x265D"));
}
int Bishop::Score()
{
return 10;
}