BlueBubble 1.0
A recommendation algorithm for movies based on a Netlfix database
Loading...
Searching...
No Matches
pawn.cc
Go to the documentation of this file.
3#include "piece.h"
4#include "pawn.h"
5#include <vector>
6#include <iostream>
7
11void pawn::needed_space(coordinates dest, std::vector<coordinates> *to_calculate){
12 int diff_x = dest.get_x() - piece::coord.get_x();
13 int diff_y = dest.get_y() - piece::coord.get_y();
14 if(diff_x == 0){
15 //Normal pawn move, destination case verified
16 to_calculate->push_back(dest);
17 // When moving two squares, also verify the intermediate one
18 if(abs(diff_y) == 2){
19 if(piece::white){
20 to_calculate->push_back(coordinates(piece::coord.get_x(),piece::coord.get_y() + 1));
21 }else{
22 to_calculate->push_back(coordinates(piece::coord.get_x(),piece::coord.get_y() - 1));
23 }
24 }
25 }else{
26 //Capture pawn move, don't need any space
27 }
28}
29
32 if(piece::white){
33 std::cout << "\u2659";
34 }else{
35 std::cout << "\u265F";
36 }
37}
38
41 if(piece::white){
42 std::cout << "wP";
43 }else{
44 std::cout << "bP";
45 }
46}
47
51void pawn::move(coordinates dest, bool debug_info){
52 if(!has_moved){
53 legals.erase(legals.begin());
54 has_moved = true;
55 }
56 coord.move(dest);
57 if(debug_info){
58 std::cout << "Piece move from : x=" << coord.get_x() << " y=" << coord.get_y() << "to : x=" << coord.get_x() << " y=" << coord.get_y() << std::endl;
59 std::cout << "Piece info : white=" << white << std::endl;
60 std::cout << "Legal moves :" << std::endl;
61 for(int i = 0; i < legals.size(); i++){
62 std::cout << "x=" << legals[i].get_x() << " y=" << legals[i].get_y() << std::endl;
63 }
64 }
65}
66
71 if(white){
72 return is_corresponding(coord,dest,coordinates(1,1)) || is_corresponding(coord,dest,coordinates(-1,1));
73 }else{
74 return is_corresponding(coord,dest,coordinates(1,-1)) || is_corresponding(coord,dest,coordinates(-1,-1));
75 }
76
77}
78
81std::vector<coordinates> pawn::get_legals(){
82 return possible_legals;
83}
a class representing coordinates
Definition coordinates.h:5
int get_x()
a function to get the x-axis attribute
Definition coordinates.cc:6
int get_y()
a function to get the y-axis attribute
void move(coordinates move_to)
change the coordinate values to move the associated piece
bool is_possible_attack(coordinates dest) override
verify if the dest position is a valid attack move. The pawn need a special overrided function.
Definition pawn.cc:70
void needed_space(coordinates dest, std::vector< coordinates > *to_calculate) override
calculate a list of empty space coordinates needed for the move to be legal, assuming the move is pos...
Definition pawn.cc:11
void canonical_print_piece() override
print the piece to the standard output in canonical form
Definition pawn.cc:40
std::vector< coordinates > possible_legals
Definition pawn.h:12
void print_piece() override
print the piece to the standard output
Definition pawn.cc:31
void move(coordinates dest, bool debug_info) override
called to move the pawn
Definition pawn.cc:51
std::vector< coordinates > get_legals() override
retrieve the piece's legal moves
Definition pawn.cc:81
coordinates coord
Definition piece.h:14
bool has_moved
Definition piece.h:16
bool white
Definition piece.h:13
std::vector< coordinates > legals
Definition piece.h:15
bool is_corresponding(coordinates start, coordinates end, coordinates movement)
verify if a movement is corresponding to a starting and ending coordinates
Definition utilities.cc:10