BlueBubble 1.0
A recommendation algorithm for movies based on a Netlfix database
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
pawn Class Reference

the pawn piece class. More...

#include <pawn.h>

Inheritance diagram for pawn:
piece

Public Member Functions

 pawn (bool _white, coordinates _coord)
 
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 possible
 
void print_piece () override
 print the piece to the standard output
 
void canonical_print_piece () override
 print the piece to the standard output in canonical form
 
void move (coordinates dest, bool debug_info) override
 called to move the pawn
 
bool is_possible_attack (coordinates dest) override
 verify if the dest position is a valid attack move. The pawn need a special overrided function.
 
std::vector< coordinatesget_legals () override
 retrieve the piece's legal moves
 
- Public Member Functions inherited from piece
 piece (bool _white, coordinates _coord)
 the constructor for the piece class
 
bool is_possible (coordinates dest)
 verify if a move is within piece range
 
coordinates get_coord ()
 retrieve the piece's coordinates
 
bool get_color ()
 retrieve the piece's color
 
bool get_has_moved ()
 retrieve if the piece has already moved during the game
 
piece_type get_type ()
 retrieve the piece's type
 

Private Attributes

std::vector< coordinatespossible_legals
 

Additional Inherited Members

- Protected Attributes inherited from piece
bool white
 
coordinates coord
 
std::vector< coordinateslegals
 
bool has_moved
 
piece_type type
 

Detailed Description

the pawn piece class.

Definition at line 9 of file pawn.h.

Constructor & Destructor Documentation

◆ pawn()

pawn::pawn ( bool _white,
coordinates _coord )
inline

Definition at line 14 of file pawn.h.

14 :
15 piece(_white,_coord)
16 {
18 int direction = 0;
19 if(piece::white){
20 direction = 1;
21 }else{
22 direction = -1;
23 }
24 // The attack moves list is managed in the overrided is_possible_attack function.
25 legals.push_back(coordinates(0,2*direction));
26 possible_legals.push_back(coordinates(0,2*direction));
27 legals.push_back(coordinates(0,direction));
28 possible_legals.push_back(coordinates(0,direction));
29 // Attack moves in possible_legals
30 possible_legals.push_back(coordinates(1,direction));
31 possible_legals.push_back(coordinates(-1,direction));
32 }
a class representing coordinates
Definition coordinates.h:5
std::vector< coordinates > possible_legals
Definition pawn.h:12
piece_type type
Definition piece.h:17
piece(bool _white, coordinates _coord)
the constructor for the piece class
Definition piece.cc:8
bool white
Definition piece.h:13
std::vector< coordinates > legals
Definition piece.h:15
@ pawn_type
Definition piece.h:8

Member Function Documentation

◆ canonical_print_piece()

void pawn::canonical_print_piece ( )
overridevirtual

print the piece to the standard output in canonical form

Reimplemented from piece.

Definition at line 40 of file pawn.cc.

40 {
41 if(piece::white){
42 std::cout << "wP";
43 }else{
44 std::cout << "bP";
45 }
46}

◆ get_legals()

std::vector< coordinates > pawn::get_legals ( )
overridevirtual

retrieve the piece's legal moves

Returns
the legal moves vector

Reimplemented from piece.

Definition at line 81 of file pawn.cc.

81 {
82 return possible_legals;
83}

◆ is_possible_attack()

bool pawn::is_possible_attack ( coordinates dest)
overridevirtual

verify if the dest position is a valid attack move. The pawn need a special overrided function.

Parameters
destdestination coordinates
Returns
if the move is within attack range

Reimplemented from piece.

Definition at line 70 of file pawn.cc.

70 {
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}
coordinates coord
Definition piece.h:14
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

◆ move()

void pawn::move ( coordinates dest,
bool debug_info )
overridevirtual

called to move the pawn

Parameters
destthe destination coordinates of the piece
debug_infoprint debug info to output when true

Reimplemented from piece.

Definition at line 51 of file pawn.cc.

51 {
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}
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 has_moved
Definition piece.h:16

◆ needed_space()

void pawn::needed_space ( coordinates dest,
std::vector< coordinates > * to_calculate )
overridevirtual

calculate a list of empty space coordinates needed for the move to be legal, assuming the move is possible

Parameters
destdestination coordinates
Returns
a vector containing all coordinates to be verified

Reimplemented from piece.

Definition at line 11 of file pawn.cc.

11 {
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}

◆ print_piece()

void pawn::print_piece ( )
overridevirtual

print the piece to the standard output

Reimplemented from piece.

Definition at line 31 of file pawn.cc.

31 {
32 if(piece::white){
33 std::cout << "\u2659";
34 }else{
35 std::cout << "\u265F";
36 }
37}

Field Documentation

◆ possible_legals

std::vector<coordinates> pawn::possible_legals
private

Definition at line 12 of file pawn.h.


The documentation for this class was generated from the following files: