BlueBubble 1.0
A recommendation algorithm for movies based on a Netlfix database
Loading...
Searching...
No Matches
Functions
utilities.cc File Reference
#include "utilities.h"
#include "coordinates.h"
#include <iostream>

Go to the source code of this file.

Functions

bool is_corresponding (coordinates start, coordinates end, coordinates movement)
 verify if a movement is corresponding to a starting and ending coordinates
 
void terminal_set_text_color (terminal_color color)
 set the terminal font color to the input
 
void terminal_set_background_color (terminal_color color)
 set the terminal background color to the input
 
void terminal_reset_all ()
 reset all terminal attributes
 
bool correct_input (std::string const &cmd)
 Check if an input is conform.
 
bool standard_input (std::string const &cmd)
 Check if an input corresponds to a standard move.
 
bool king_castle_input (std::string const &cmd)
 Check if an input correponds to a king castling move.
 
bool queen_castle_input (std::string const &cmd)
 Check if an input corresponds to a queen castling move.
 
void print_debug (int i)
 Print a message to the standard output : "test i". Used for debug purposes.
 

Function Documentation

◆ correct_input()

bool correct_input ( std::string const & cmd)

Check if an input is conform.

Parameters
cmdthe input string
Returns
a boolean indicating if the input is conform

Definition at line 86 of file utilities.cc.

86 {
87 std::regex mouvmtpattern("[a-h][1-8][a-h][1-8]");
88 std::regex kingcastlemouvmtpattern("(O|o|0)-(O|o|0)");
89 std::regex queencastlemouvmtpattern("(O|o|0)-(O|o|0)-(O|o|0)");
90 return regex_match(cmd,mouvmtpattern) || regex_match(cmd,kingcastlemouvmtpattern) || regex_match(cmd,queencastlemouvmtpattern);
91}

◆ is_corresponding()

bool is_corresponding ( coordinates start,
coordinates end,
coordinates movement )

verify if a movement is corresponding to a starting and ending coordinates

Parameters
startstarting coordinates
endending coordinates
movementthe move to be verified, represente as coordinates
Returns
a boolean value corresponding to the move being valid or not

Definition at line 10 of file utilities.cc.

10 {
11 return (end.get_x() - start.get_x() == movement.get_x()) && (end.get_y() - start.get_y() == movement.get_y());
12}
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

◆ king_castle_input()

bool king_castle_input ( std::string const & cmd)

Check if an input correponds to a king castling move.

Parameters
cmdthe input string
Returns
a boolean indicating if the input is a king castling move

Definition at line 104 of file utilities.cc.

104 {
105 std::regex kingcastlemouvmtpattern("(O|o|0)-(O|o|0)");
106 return regex_match(cmd,kingcastlemouvmtpattern);
107}

◆ print_debug()

void print_debug ( int i)

Print a message to the standard output : "test i". Used for debug purposes.

Parameters
ithe number that appear on the debug message

Definition at line 119 of file utilities.cc.

119 {
120 std::cout << "test" << i << std::endl;
121}

◆ queen_castle_input()

bool queen_castle_input ( std::string const & cmd)

Check if an input corresponds to a queen castling move.

Parameters
cmdthe input string
Returns
a boolean indicating if the input is a queen castling move

Definition at line 112 of file utilities.cc.

112 {
113 std::regex queencastlemouvmtpattern("(O|o|0)-(O|o|0)-(O|o|0)");
114 return regex_match(cmd,queencastlemouvmtpattern);
115}

◆ standard_input()

bool standard_input ( std::string const & cmd)

Check if an input corresponds to a standard move.

Parameters
cmdthe input string
Returns
a boolean indicating if the input is a standard move

Definition at line 96 of file utilities.cc.

96 {
97 std::regex mouvmtpattern("[a-h][1-8][a-h][1-8]");
98 return regex_match(cmd,mouvmtpattern);
99}

◆ terminal_reset_all()

void terminal_reset_all ( )

reset all terminal attributes

Definition at line 79 of file utilities.cc.

79 {
80 std::cout << "\033[0m";
81}

◆ terminal_set_background_color()

void terminal_set_background_color ( terminal_color color)

set the terminal background color to the input

Parameters
color

Definition at line 48 of file utilities.cc.

48 {
49 switch (color)
50 {
51 case terminal_black:
52 std::cout << "\033[40m";
53 break;
54 case terminal_red:
55 std::cout << "\033[41m";
56 break;
57 case terminal_green:
58 std::cout << "\033[42m";
59 break;
60 case terminal_yellow:
61 std::cout << "\033[43m";
62 break;
63 case terminal_blue:
64 std::cout << "\033[44m";
65 break;
67 std::cout << "\033[45m";
68 break;
69 case terminal_cyan:
70 std::cout << "\033[46m";
71 break;
72 case terminal_white:
73 std::cout << "\033[47m";
74 break;
75 }
76}
@ terminal_blue
Definition config.h:5
@ terminal_cyan
Definition config.h:5
@ terminal_magenta
Definition config.h:5
@ terminal_green
Definition config.h:5
@ terminal_white
Definition config.h:5
@ terminal_black
Definition config.h:5
@ terminal_yellow
Definition config.h:5
@ terminal_red
Definition config.h:5

◆ terminal_set_text_color()

void terminal_set_text_color ( terminal_color color)

set the terminal font color to the input

Parameters
color

Definition at line 16 of file utilities.cc.

16 {
17 switch (color)
18 {
19 case terminal_black:
20 std::cout << "\033[30m";
21 break;
22 case terminal_red:
23 std::cout << "\033[31m";
24 break;
25 case terminal_green:
26 std::cout << "\033[32m";
27 break;
28 case terminal_yellow:
29 std::cout << "\033[33m";
30 break;
31 case terminal_blue:
32 std::cout << "\033[34m";
33 break;
35 std::cout << "\033[35m";
36 break;
37 case terminal_cyan:
38 std::cout << "\033[36m";
39 break;
40 case terminal_white:
41 std::cout << "\033[37m";
42 break;
43 }
44}