Skip to content
Snippets Groups Projects
Commit 60c20c25 authored by Clément Desberg's avatar Clément Desberg
Browse files

commited on 20240508

parent c4534d8a
Branches
No related merge requests found
No preview for this file type
......@@ -6,8 +6,7 @@
#include <iostream>
/// @brief calculate a list of empty space coordinates needed for the move to be legal, assuming the move is possible
/// @param start starting coordinates
/// @param end destination coordinates
/// @param dest destination coordinates
/// @return a vector containing all coordinates to be verified
std::vector<coordinates> pawn::needed_space(coordinates dest){
std::vector<coordinates> result = {};
......@@ -48,8 +47,15 @@ void pawn::moved(){
}
}
/// @brief verify if the dest position is a valid attack move. The pawn need a special overrided function.
/// @param dest destination coordinates
/// @return if the move is within attack range
bool piece::is_possible_attack(coordinates dest){
return is_corresponding(coord,dest,coordinates(1,1)) || is_corresponding(coord,dest,coordinates(1,-1));
}
int main(){
pawn hello(true);
pawn hello(true,coordinates(0,0));
hello.print_piece();
if(hello.is_possible(coordinates(0,2))){
std::cout << "ok2" << std::endl;
......
......@@ -17,14 +17,14 @@ class pawn : public piece{
}else{
direction = -1;
}
// The attack moves list is managed in the overrided is_possible_attack function.
legals.push_back(coordinates(0,2*direction));
legals.push_back(coordinates(0,direction));
legals.push_back(coordinates(1,direction));
legals.push_back(coordinates(-1,direction));
}
std::vector<coordinates> needed_space(coordinates dest) override;
void print_piece() override;
void moved() override;
bool is_possible_attack(coordinates dest) override;
};
#endif
\ No newline at end of file
......@@ -16,7 +16,17 @@ piece::piece(bool _white, coordinates _coord):
/// @param dest destination coordinates
/// @return if the move is within range
bool piece::is_possible(coordinates dest){
bool result = false;
for(int i = 0; i < legals.size(); i++){
result = result || (is_corresponding(coord,dest,legals[i]));
}
return result;
}
/// @brief verify if a move is within piece attack range
/// @param dest destination coordinates
/// @return if the move is within attack range
bool piece::is_possible_attack(coordinates dest){
bool result = false;
for(int i = 0; i < legals.size(); i++){
result = result || (is_corresponding(coord,dest,legals[i]));
......
......@@ -14,6 +14,7 @@ class piece{
public:
piece(bool _white, coordinates _coord);
bool is_possible(coordinates dest);
virtual bool is_possible_attack(coordinates dest);
virtual std::vector<coordinates> needed_space(coordinates dest);
virtual void print_piece();
virtual void moved();
......
......@@ -6,8 +6,7 @@
#include <iostream>
/// @brief calculate a list of empty space coordinates needed for the move to be legal, assuming the move is possible
/// @param start starting coordinates
/// @param end destination coordinates
/// @param dest destination coordinates
/// @return a vector containing all coordinates to be verified
std::vector<coordinates> queen::needed_space(coordinates dest){
std::vector<coordinates> result = {};
......
......@@ -6,8 +6,7 @@
#include <iostream>
/// @brief calculate a list of empty space coordinates needed for the move to be legal, assuming the move is possible
/// @param start starting coordinates
/// @param end destination coordinates
/// @param dest destination coordinates
/// @return a vector containing all coordinates to be verified
std::vector<coordinates> rook::needed_space(coordinates dest){
std::vector<coordinates> result = {};
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment