-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBishop.h
More file actions
35 lines (28 loc) · 1.1 KB
/
Copy pathBishop.h
File metadata and controls
35 lines (28 loc) · 1.1 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
#pragma once
#include "Piece.h"
/// <summary>
/// Represents the Bishop game piece
/// </summary>
class Bishop : public Piece
{
public:
using Piece::Piece;
/// <summary>
/// Finds all the legal bishop moves (diagonal lines)
/// </summary>
/// <returns> A list with all the possible legal moves </returns>
const std::vector<std::pair<sf::Vector2i, Piece*>> CalculateLegalMoves() override {
std::vector<std::pair<sf::Vector2i, Piece*>> moves;
// Finds all the lines
std::vector<std::pair<sf::Vector2i, Piece*>> drLine = CalculateLineMoves({ 1, 1 });
std::vector<std::pair<sf::Vector2i, Piece*>> ulLine = CalculateLineMoves({ -1, -1 });
std::vector<std::pair<sf::Vector2i, Piece*>> urLine = CalculateLineMoves({ 1, -1 });
std::vector<std::pair<sf::Vector2i, Piece*>> dlLine = CalculateLineMoves({ -1, 1 });
// Combines lines into a single list
moves.insert(moves.end(), drLine.begin(), drLine.end());
moves.insert(moves.end(), ulLine.begin(), ulLine.end());
moves.insert(moves.end(), urLine.begin(), urLine.end());
moves.insert(moves.end(), dlLine.begin(), dlLine.end());
return moves;
}
};