-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rook.cpp
98 lines (82 loc) · 2.45 KB
/
Rook.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// Rook.cpp
// Chess
//
// Created by Albaraa on 3/6/14.
// Copyright (c) 2014 Albaraa. All rights reserved.
//
#include "Rook.h"
using namespace std;
Rook* Rook::clone(){
return new Rook (*this);
}
void Rook::getValidMove(Piece* (&chessBoard)[9][9], std::vector<PieceMove> &allPossibleMoves, PieceMove & lastMove){
PieceMove newMove;
newMove.movingPiece = this;
//Checks straight line moves for Queen (Up, Down, Right, Left).
for(int i = this->rank() + 1; i <= 8; i++){
if(chessBoard[i][this->file()] != NULL && chessBoard[i][this->file()]->owner() == this->owner()){
break;
}
newMove.fromRank = this->rank();
newMove.fromFile = this->file();
newMove.rank = i;
newMove.file = this->file();
newMove.promotion = 0;
if(isKingInCheck(chessBoard, newMove, *this) == false){
allPossibleMoves.push_back(newMove);
}
if(chessBoard[i][this->file()] != NULL){
break;
}
}
for(int i = this->file() + 1; i <= 8; i++){
if(chessBoard[this->rank()][i] != NULL && chessBoard[this->rank()][i]->owner() == this->owner()){
break;
}
newMove.fromRank = this->rank();
newMove.fromFile = this->file();
newMove.rank = this->rank();
newMove.file = i;
newMove.promotion = 0;
if(isKingInCheck(chessBoard, newMove, *this) == false){
allPossibleMoves.push_back(newMove);
}
if(chessBoard[this->rank()][i] != NULL){
break;
}
}
for(int i = this->rank() - 1; i > 0; i--){
if(chessBoard[i][this->file()] != NULL && chessBoard[i][this->file()]->owner() == this->owner()){
break;
}
newMove.fromRank = this->rank();
newMove.fromFile = this->file();
newMove.rank = i;
newMove.file = this->file();
newMove.promotion = 0;
if(isKingInCheck(chessBoard, newMove, *this) == false){
allPossibleMoves.push_back(newMove);
}
if(chessBoard[i][this->file()] != NULL){
break;
}
}
for(int i = this->file() - 1; i > 0; i--){
if(chessBoard[this->rank()][i] != NULL && chessBoard[this->rank()][i]->owner() == this->owner()){
break;
}
newMove.fromRank = this->rank();
newMove.fromFile = this->file();
newMove.rank = this->rank();
newMove.file = i;
newMove.promotion = 0;
if(isKingInCheck(chessBoard, newMove, *this) == false){
allPossibleMoves.push_back(newMove);
}
if(chessBoard[this->rank()][i] != NULL){
break;
}
}
return;
};