BlueBubble 1.0
A recommendation algorithm for movies based on a Netlfix database
Loading...
Searching...
No Matches
piece.cc
Go to the documentation of this file.
1#include "piece.h"
4#include <iostream>
5
8piece::piece(bool _white, coordinates _coord):
9 white(_white), coord(_coord)
10 {
11 legals = {};
12 has_moved = false;
13 }
14
19 bool result = false;
20 for(int i = 0; i < legals.size(); i++){
21 result = result || (is_corresponding(coord,dest,legals[i]));
22 }
23 return result;
24}
25
30 bool result = false;
31 for(int i = 0; i < legals.size(); i++){
32 result = result || (is_corresponding(coord,dest,legals[i]));
33 }
34 return result;
35}
36
40void piece::needed_space(coordinates dest, std::vector<coordinates> *to_calculate){
41 // By default, no space needed
42}
43
46 std::cout << "undefined piece";
47}
48
51 std::cout << "undefined piece";
52}
53
57void piece::move(coordinates dest,bool debug_info){
58 //By default, only update has_moved
59 has_moved = true;
60 coord.move(dest);
61 if(debug_info){
62 std::cout << "Piece move from : x=" << coord.get_x() << " y=" << coord.get_y() << "to : x=" << coord.get_x() << " y=" << coord.get_y() << std::endl;
63 std::cout << "Piece info : white=" << white << std::endl;
64 std::cout << "Legal moves :" << std::endl;
65 for(int i = 0; i < legals.size(); i++){
66 std::cout << "x=" << legals[i].get_x() << " y=" << legals[i].get_y() << std::endl;
67 }
68 }
69}
70
76
80 return white;
81}
82
86 return has_moved;
87}
88
94
97std::vector<coordinates> piece::get_legals(){
98 return legals;
99}
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(coordinates dest)
verify if a move is within piece range
Definition piece.cc:18
coordinates coord
Definition piece.h:14
bool get_color()
retrieve the piece's color
Definition piece.cc:79
virtual void move(coordinates dest, bool debug_info)
called to move the piece
Definition piece.cc:57
piece_type type
Definition piece.h:17
virtual std::vector< coordinates > get_legals()
retrieve the piece's legal moves
Definition piece.cc:97
virtual bool is_possible_attack(coordinates dest)
verify if a move is within piece attack range
Definition piece.cc:29
piece_type get_type()
retrieve the piece's type
Definition piece.cc:91
coordinates get_coord()
retrieve the piece's coordinates
Definition piece.cc:73
piece(bool _white, coordinates _coord)
the constructor for the piece class
Definition piece.cc:8
virtual void canonical_print_piece()
print the piece to the standard output in canonical form
Definition piece.cc:50
bool get_has_moved()
retrieve if the piece has already moved during the game
Definition piece.cc:85
bool has_moved
Definition piece.h:16
virtual void print_piece()
print the piece to the standard output
Definition piece.cc:45
bool white
Definition piece.h:13
std::vector< coordinates > legals
Definition piece.h:15
virtual void needed_space(coordinates dest, std::vector< coordinates > *to_calculate)
calculate the space needed for the piece to move
Definition piece.cc:40
piece_type
Represent a piece type. Undefined for default piece.
Definition piece.h:8
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