Skip to content
Snippets Groups Projects
Commit c0fb94ed authored by LABROSSE THEO p2003011's avatar LABROSSE THEO p2003011 :eyeglasses:
Browse files

Positions voisines

fait
parent 9d8b1ee2
No related branches found
No related tags found
No related merge requests found
{
"files.associations": {
"ostream": "cpp"
}
}
\ No newline at end of file
......@@ -2,15 +2,30 @@
#include <stdexcept>
Position voisine(const Position& pos, int index) {
Position res = pos ;
Position voisine(const Position& pos, int direction) {
Position res = pos ;
//votre code ici
switch(direction) {
case 0: // haut
res.first-- ;
break ;
case 1: // gauche
res.second++ ;
break ;
case 2: // bas
res.first++ ;
break ;
case 3: // droite
res.second-- ;
break ;
default:
throw std::invalid_argument("Direction invalide") ;
}
return res ;
return res ;
}
std::ostream& operator<<(std::ostream& out, const Position& pos) {
out << "{" << pos.first << "," << pos.second << "}" ;
return out ;
out << "{" << pos.first << "," << pos.second << "}" ;
return out ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment