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

commited on 20240508

parent 51485308
Branches
No related merge requests found
rook: rook.o piece.o coordinates.o utilities.o
g++ rook.o piece.o coordinates.o utilities.o
main: pieces/pawn.o pieces/king.o pieces/queen.o pieces/bishop.o pieces/rook.o pieces pieces/piece.o system/coordinates.o system/utilities.o
g++ pieces/*.o system/*.o
make clean
coordinates.o:
g++ -c system/coordinates.cc
utilities.o:
g++ -c system/utilities.cc
piece.o:
g++ -c pieces/piece.cc
rook.o:
g++ -c pieces/rook.cc
bishop.o:
g++ -c pieces/bishop.cc
%.o: %.cc
g++ -o $@ -c $< $(CFLAGS)
clean:
rm *.o
\ No newline at end of file
rm pieces/*.o
rm system/*.o
\ No newline at end of file
a.out 100644 → 100755
No preview for this file type
......@@ -6,25 +6,24 @@
#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> bishop::needed_space(coordinates start, coordinates end){
std::vector<coordinates> bishop::needed_space(coordinates dest){
std::vector<coordinates> result = {};
int diff_x = end.get_x() - start.get_x();
int diff_y = end.get_y() - start.get_y();
int diff_x = dest.get_x() - piece::coord.get_x();
int diff_y = dest.get_y() - piece::coord.get_y();
int coord_x = -1;
int coord_y = -1;
for(int i = 1; i < abs(diff_x); i++){
if(diff_x > 0){
coord_x = start.get_x() + i;
coord_x = piece::coord.get_x() + i;
}else{
coord_x = start.get_x() - i;
coord_x = piece::coord.get_x() - i;
}
if(diff_y > 0){
coord_y = start.get_y() + i;
coord_y = piece::coord.get_y() + i;
}else{
coord_y = start.get_y() - i;
coord_y = piece::coord.get_y() - i;
}
result.push_back(coordinates(coord_x,coord_y));
}
......
......@@ -5,7 +5,7 @@
#include "piece.h"
#include <vector>
/// @brief the rook piece class.
/// @brief the bishop piece class.
class bishop : public piece{
public:
bishop(bool _white):
......@@ -17,7 +17,7 @@ class bishop : public piece{
legals.push_back(coordinates(i,-i));
}
}
std::vector<coordinates> needed_space(coordinates start, coordinates end) override;
std::vector<coordinates> needed_space(coordinates dest) override;
void print_piece() override;
};
......
File deleted
......@@ -9,30 +9,34 @@ piece::piece(bool _white):
white(_white)
{
legals = {};
has_moved = false;
}
/// @brief verify if a move is within piece range
/// @param start starting coordinates
/// @param end destination coordinates
/// @param dest destination coordinates
/// @return if the move is within range
bool piece::is_possible(coordinates start, coordinates end){
bool piece::is_possible(coordinates dest){
bool result = false;
for(int i = 0; i < legals.size(); i++){
result = result || (is_corresponding(start,end,legals[i]));
result = result || (is_corresponding(coord,dest,legals[i]));
}
return result;
}
/// @brief calculate the space needed for the piece to move
/// @param start starting point
/// @param end ending point
/// @param dest destination point
/// @return a vector containing all spaces to be verified
std::vector<coordinates> piece::needed_space(coordinates start, coordinates end){
std::vector<coordinates> piece::needed_space(coordinates dest){
return {};
}
/// @brief print the piece to the standard output
void piece::print_piece(){
std::cout << "undefined piece";
}
void piece::moved(){
//By default, only update has_moved
has_moved = true;
}
\ No newline at end of file
......@@ -4,16 +4,19 @@
#include "../system/utilities.h"
#include <vector>
/// @brief a generic piece class. white is a boolean indicating the piece's color. legals is a vector indicating all legal movements
/// @brief a generic piece class. white is a boolean indicating the piece's color. legals is a vector indicating all legal movements. has_moved indicate if the piece has already move during this game
class piece{
protected:
bool white;
coordinates coord;
std::vector<coordinates> legals;
bool has_moved;
public:
piece(bool _white);
bool is_possible(coordinates start, coordinates end);
virtual std::vector<coordinates> needed_space(coordinates start, coordinates end);
bool is_possible(coordinates dest);
virtual std::vector<coordinates> needed_space(coordinates dest);
virtual void print_piece();
virtual void moved();
};
#endif
\ No newline at end of file
File deleted
......@@ -49,18 +49,4 @@ void rook::print_piece(){
}else{
std::cout << "\u265C";
}
}
int main(){
rook hello(true);
hello.print_piece();
if(hello.is_possible(coordinates(5,6),coordinates(5,10))){
std::cout << "ok2" << std::endl;
}
if(hello.is_possible(coordinates(3,2),coordinates(8,2))){
std::cout << "ok3" << std::endl;
}
if(hello.is_possible(coordinates(3,4),coordinates(5,2))){
std::cout << "ok4" << std::endl;
}
}
\ No newline at end of file
File deleted
......@@ -3,9 +3,17 @@
#include <iostream>
#include <vector>
#include "../pieces/piece.h"
#include <regex>
#include <string>
class board{
private:
piece *** echiquier;
piece white_piece
public:
board();
};
bool correct_input(std::string const & cmd);
#endif
\ No newline at end of file
#include "utilities.h"
#include "coordinates.h"
#include <iostream>
/// @brief verify if a movement is corresponding to a starting and ending coordinates
/// @param start starting coordinates
......@@ -8,4 +9,73 @@
/// @return a boolean value corresponding to the move being valid or not
bool is_corresponding(coordinates start, coordinates end, coordinates movement){
return (end.get_x() - start.get_x() == movement.get_x()) && (end.get_y() - start.get_y() == movement.get_y());
}
/// @brief set the terminal font color to the input
/// @param color
void terminal_set_text_color(terminal_color color){
switch (color)
{
case terminal_black:
std::cout << "\033[30m";
break;
case terminal_red:
std::cout << "\033[31m";
break;
case terminal_green:
std::cout << "\033[32m";
break;
case terminal_yellow:
std::cout << "\033[33m";
break;
case terminal_blue:
std::cout << "\033[34m";
break;
case terminal_magenta:
std::cout << "\033[35m";
break;
case terminal_cyan:
std::cout << "\033[36m";
break;
case terminal_white:
std::cout << "\033[37m";
break;
}
}
/// @brief set the terminal background color to the input
/// @param color
void terminal_set_background_color(terminal_color color){
switch (color)
{
case terminal_black:
std::cout << "\033[40m";
break;
case terminal_red:
std::cout << "\033[41m";
break;
case terminal_green:
std::cout << "\033[42m";
break;
case terminal_yellow:
std::cout << "\033[43m";
break;
case terminal_blue:
std::cout << "\033[44m";
break;
case terminal_magenta:
std::cout << "\033[45m";
break;
case terminal_cyan:
std::cout << "\033[46m";
break;
case terminal_white:
std::cout << "\033[47m";
break;
}
}
/// @brief reset all terminal attributes
void terminal_reset_all(){
std::cout << "\033[0m";
}
\ No newline at end of file
......@@ -2,7 +2,11 @@
#define UTILITIES
#include "coordinates.h"
enum terminal_color { terminal_black, terminal_red, terminal_green, terminal_yellow, terminal_blue, terminal_magenta, terminal_cyan, terminal_white };
bool is_corresponding(coordinates start, coordinates end, coordinates movement);
void terminal_set_text_color(terminal_color color);
void terminal_set_background_color(terminal_color color);
void terminal_reset_all();
#endif
\ No newline at end of file
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