From 37093935766cdc0462d140e6b764e03b46ad7390 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 8 Mar 2016 19:23:35 +0100 Subject: [PATCH] Seance #7 --- Chess/dep/ChessContext.cpp | 42 ++++++++ Chess/dep/ChessContext.h | 38 +++++++ Chess/dep/Pieces/Cavalier.cpp | 4 +- Chess/dep/Pieces/Cavalier.h | 6 +- Chess/dep/Pieces/Fou.cpp | 19 +++- Chess/dep/Pieces/Fou.h | 6 +- Chess/dep/Pieces/Piece.cpp | 8 +- Chess/dep/Pieces/Piece.h | 9 +- Chess/dep/Pieces/PieceFactory.cpp | 8 ++ Chess/dep/Pieces/Pion.cpp | 2 +- Chess/dep/Pieces/Pion.h | 6 +- Chess/dep/Pieces/Reine.cpp | 4 +- Chess/dep/Pieces/Reine.h | 6 +- Chess/dep/Pieces/Roi.cpp | 4 +- Chess/dep/Pieces/Roi.h | 6 +- Chess/dep/Pieces/Tour.cpp | 4 +- Chess/dep/Pieces/Tour.h | 6 +- Chess/dep/Player.cpp | 85 +++++++++++++++ Chess/dep/Player.h | 45 ++++++++ Chess/dep/term.h | 4 +- Chess/e | Bin 15821 -> 0 bytes Chess/main.cpp | 170 ++++++++++++++++++++++++++++-- Chess/main.h | 11 +- 23 files changed, 447 insertions(+), 46 deletions(-) create mode 100644 Chess/dep/ChessContext.cpp create mode 100644 Chess/dep/ChessContext.h create mode 100644 Chess/dep/Player.cpp create mode 100644 Chess/dep/Player.h delete mode 100755 Chess/e diff --git a/Chess/dep/ChessContext.cpp b/Chess/dep/ChessContext.cpp new file mode 100644 index 0000000..75957cf --- /dev/null +++ b/Chess/dep/ChessContext.cpp @@ -0,0 +1,42 @@ +/* [1] Initialisation de la partie +=========================================================*/ +void ChessContext::init(){ + _p1 = new Player(true); + _p2 = new Player(false); + + _turn = '1'; + + _p1->initPieces(); + _p2->initPieces(); +} + +/* [0] Constructeur +=========================================================*/ +ChessContext::ChessContext(){ + _p1 = new Player(true); + _p2 = new Player(false); + + _turn = '1'; + + _p1->initPieces(); + _p2->initPieces(); +} + + +/* [2] Renvoie le pion qui est en case (x, y) +=========================================================*/ +Player* ChessContext::at(const int x, const int y){ + // On verifie que c'est pas le Player 1 qui l'a + Piece *p; + p = _p1->at(x, y); + if( p != NULL ) + return _p1; + + // On verifie que c'est pas le Player 2 qui l'a + p = _p2->at(x, y); + if( p != NULL ) + return _p2; + + + return NULL; +} \ No newline at end of file diff --git a/Chess/dep/ChessContext.h b/Chess/dep/ChessContext.h new file mode 100644 index 0000000..aeeb6fd --- /dev/null +++ b/Chess/dep/ChessContext.h @@ -0,0 +1,38 @@ +#ifndef DEF_CHESSCONTEXT_H + + #define DEF_CHESSCONTEXT_H + + /* [1] Libs + =========================================================*/ + /* (1) Internes */ + #include + #include + #include + + /* (2) Externes */ + #include "term.h" + #include "Player.h" + + /* (3) Namespace */ + using namespace std; + + + /* [2] Definition + =========================================================*/ + class ChessContext{ + public: + ChessContext(); + void init(); + Player* at(const int x, const int y); + + // ATTRIBUTS + char _turn; + Player *_p1; + Player *_p2; + }; + + /* [n] Inclusion du corps + =========================================================*/ + #include "ChessContext.cpp" + +#endif \ No newline at end of file diff --git a/Chess/dep/Pieces/Cavalier.cpp b/Chess/dep/Pieces/Cavalier.cpp index 774178a..c1a6735 100644 --- a/Chess/dep/Pieces/Cavalier.cpp +++ b/Chess/dep/Pieces/Cavalier.cpp @@ -4,10 +4,10 @@ Cavalier::Cavalier(int x, int y) : Piece(CAVALIER, x, y) { } // ABSTRACT -bool Cavalier::can(const int x, const int y) const{ +bool Cavalier::can(const ChessContext& ctx, int x, int y){ return true; } char Cavalier::getchar(){ - return 'P'; + return 'C'; } diff --git a/Chess/dep/Pieces/Cavalier.h b/Chess/dep/Pieces/Cavalier.h index d2941bc..0ef3e68 100644 --- a/Chess/dep/Pieces/Cavalier.h +++ b/Chess/dep/Pieces/Cavalier.h @@ -1,6 +1,6 @@ -#ifndef DEF_CAVALIER +#ifndef DEF_CAVALIER_H - #define DEF_CAVALIER + #define DEF_CAVALIER_H /* [1] Libs =========================================================*/ @@ -19,7 +19,7 @@ Cavalier(int x, int y); // ABSTRACT - bool can(const int x, const int y) const; + bool can(const ChessContext& ctx, int x, int y); char getchar(); }; diff --git a/Chess/dep/Pieces/Fou.cpp b/Chess/dep/Pieces/Fou.cpp index 46ab666..84357ae 100644 --- a/Chess/dep/Pieces/Fou.cpp +++ b/Chess/dep/Pieces/Fou.cpp @@ -4,10 +4,23 @@ Fou::Fou(int x, int y) : Piece(FOU, x, y) { } // ABSTRACT -bool Fou::can(const int x, const int y) const{ - return true; +bool Fou::can(const ChessContext& ctx, int x, int y){ + bool inDiag = abs( _x-x ) == abs( _y-y ); + + // Si deplacement pas en diagonale, on retourne faux + if( !inDiag ) return false; + + // On verifie que la diagonale est degagee + int xstep = ( x-_x ) / abs( x-_x ); + int ystep = ( y-_y ) / abs( y-_y ); + + for( int i = _x+xstep, j = _y+ystep ; i != x && j != y ; i+=xstep, j+=ystep ) + if( ctx._p1->at(i, j) != NULL ) return false; + + + return true; } char Fou::getchar(){ - return 'P'; + return 'F'; } diff --git a/Chess/dep/Pieces/Fou.h b/Chess/dep/Pieces/Fou.h index 926d788..43b548d 100644 --- a/Chess/dep/Pieces/Fou.h +++ b/Chess/dep/Pieces/Fou.h @@ -1,6 +1,6 @@ -#ifndef DEF_FOU +#ifndef DEF_FOU_H - #define DEF_FOU + #define DEF_FOU_H /* [1] Libs =========================================================*/ @@ -19,7 +19,7 @@ Fou(int x, int y); // ABSTRACT - bool can(const int x, const int y) const; + bool can(const ChessContext& ctx, int x, int y); char getchar(); }; diff --git a/Chess/dep/Pieces/Piece.cpp b/Chess/dep/Pieces/Piece.cpp index 7c552c3..1fc1d10 100644 --- a/Chess/dep/Pieces/Piece.cpp +++ b/Chess/dep/Pieces/Piece.cpp @@ -7,6 +7,12 @@ PIECE_TYPE Piece::gett() const{ return _t; } int Piece::getx() const{ return _x; } int Piece::gety() const{ return _y; } +// DECODE DES COORDONNES DE LA FORME "A7" VERS (x,y) +void Piece::decode(char *s, int* xy){ + xy[0] = (s[0] - 'A'); + xy[1] = 8 - (s[1] - '0'); +} + // SETTERS void Piece::move(const int x, const int y){ _x = x; @@ -19,5 +25,5 @@ ostream& operator<<(ostream& o, const Piece& p){ } // ABTRACT -bool Piece::can(const int x, const int y){ return false; } +bool Piece::can(const ChessContext& ctx, int x, int y){ return false; } char Piece::getchar(){ return '?'; } \ No newline at end of file diff --git a/Chess/dep/Pieces/Piece.h b/Chess/dep/Pieces/Piece.h index ad3ba45..01ce9d9 100644 --- a/Chess/dep/Pieces/Piece.h +++ b/Chess/dep/Pieces/Piece.h @@ -1,6 +1,6 @@ -#ifndef DEF_PIECE +#ifndef DEF_PIECE_H - #define DEF_PIECE + #define DEF_PIECE_H /* [1] Libs =========================================================*/ @@ -8,8 +8,10 @@ #include #include #include + #include /* (2) Externes */ + #include "../ChessContext.h" /* (3) Namespace */ using namespace std; @@ -48,6 +50,7 @@ PIECE_TYPE gett() const; int getx() const; int gety() const; + static void decode(char *s, int* xy); // SETTERS void move(const int x, const int y); @@ -56,7 +59,7 @@ friend ostream& operator<<(ostream& o, const Piece& p); // ABSTRACT - virtual bool can(const int x, const int y); + virtual bool can(const ChessContext& ctx, int x, int y); virtual char getchar(); protected: diff --git a/Chess/dep/Pieces/PieceFactory.cpp b/Chess/dep/Pieces/PieceFactory.cpp index 13e81e4..264197a 100644 --- a/Chess/dep/Pieces/PieceFactory.cpp +++ b/Chess/dep/Pieces/PieceFactory.cpp @@ -10,5 +10,13 @@ Piece& PieceFactory::create(PIECE_TYPE t, int x, int y){ case PION: p = new Pion(x, y); break; } + /* DEBUG */ + setfont(SKYBLUE, NORMAL); + + cout << "\t[+] " << p->gett() << " at (" << p->getx() << "," << p->gety() << ")"; + + setfont(); + cout << endl; + return *p; } diff --git a/Chess/dep/Pieces/Pion.cpp b/Chess/dep/Pieces/Pion.cpp index 38c6add..6065f6c 100644 --- a/Chess/dep/Pieces/Pion.cpp +++ b/Chess/dep/Pieces/Pion.cpp @@ -4,7 +4,7 @@ Pion::Pion(int x, int y) : Piece(PION, x, y) { } // ABSTRACT -bool Pion::can(const int x, const int y) const{ +bool Pion::can(const ChessContext& ctx, const int x, const int y) const{ return true; } diff --git a/Chess/dep/Pieces/Pion.h b/Chess/dep/Pieces/Pion.h index bff2dcc..272f556 100644 --- a/Chess/dep/Pieces/Pion.h +++ b/Chess/dep/Pieces/Pion.h @@ -1,6 +1,6 @@ -#ifndef DEF_PION +#ifndef DEF_PION_H - #define DEF_PION + #define DEF_PION_H /* [1] Libs =========================================================*/ @@ -19,7 +19,7 @@ Pion(int x, int y); // ABSTRACT - bool can(const int x, const int y) const; + bool can(const ChessContext& ctx, const int x, const int y) const; char getchar(); }; diff --git a/Chess/dep/Pieces/Reine.cpp b/Chess/dep/Pieces/Reine.cpp index d33f8bb..623e407 100644 --- a/Chess/dep/Pieces/Reine.cpp +++ b/Chess/dep/Pieces/Reine.cpp @@ -4,10 +4,10 @@ Reine::Reine(int x, int y) : Piece(REINE, x, y) { } // ABSTRACT -bool Reine::can(const int x, const int y) const{ +bool Reine::can(const ChessContext& ctx, int x, int y){ return true; } char Reine::getchar(){ - return 'P'; + return 'Q'; } diff --git a/Chess/dep/Pieces/Reine.h b/Chess/dep/Pieces/Reine.h index 7915bc2..b16492f 100644 --- a/Chess/dep/Pieces/Reine.h +++ b/Chess/dep/Pieces/Reine.h @@ -1,6 +1,6 @@ -#ifndef DEF_REINE +#ifndef DEF_REINE_H - #define DEF_REINE + #define DEF_REINE_H /* [1] Libs =========================================================*/ @@ -19,7 +19,7 @@ Reine(int x, int y); // ABSTRACT - bool can(const int x, const int y) const; + bool can(const ChessContext& ctx, int x, int y); char getchar(); }; diff --git a/Chess/dep/Pieces/Roi.cpp b/Chess/dep/Pieces/Roi.cpp index 7717f4b..0a8d9b5 100644 --- a/Chess/dep/Pieces/Roi.cpp +++ b/Chess/dep/Pieces/Roi.cpp @@ -4,10 +4,10 @@ Roi::Roi(int x, int y) : Piece(ROI, x, y) { } // ABSTRACT -bool Roi::can(const int x, const int y) const{ +bool Roi::can(const ChessContext& ctx, int x, int y){ return true; } char Roi::getchar(){ - return 'R'; + return 'K'; } diff --git a/Chess/dep/Pieces/Roi.h b/Chess/dep/Pieces/Roi.h index 2bad8be..7d90f22 100644 --- a/Chess/dep/Pieces/Roi.h +++ b/Chess/dep/Pieces/Roi.h @@ -1,6 +1,6 @@ -#ifndef DEF_Roi +#ifndef DEF_ROI_H - #define DEF_Roi + #define DEF_ROI_H /* [1] Libs =========================================================*/ @@ -19,7 +19,7 @@ Roi(int x, int y); // ABSTRACT - bool can(const int x, const int y) const; + bool can(const ChessContext& ctx, int x, int y); char getchar(); }; diff --git a/Chess/dep/Pieces/Tour.cpp b/Chess/dep/Pieces/Tour.cpp index 76d8aab..be80cb3 100644 --- a/Chess/dep/Pieces/Tour.cpp +++ b/Chess/dep/Pieces/Tour.cpp @@ -4,10 +4,10 @@ Tour::Tour(int x, int y) : Piece(TOUR, x, y) { } // ABSTRACT -bool Tour::can(const int x, const int y) const{ +bool Tour::can(const ChessContext& ctx, int x, int y){ return true; } char Tour::getchar(){ - return 'P'; + return 'T'; } diff --git a/Chess/dep/Pieces/Tour.h b/Chess/dep/Pieces/Tour.h index b490532..9a4565c 100644 --- a/Chess/dep/Pieces/Tour.h +++ b/Chess/dep/Pieces/Tour.h @@ -1,6 +1,6 @@ -#ifndef DEF_TOUR +#ifndef DEF_TOUR_H - #define DEF_TOUR + #define DEF_TOUR_H /* [1] Libs =========================================================*/ @@ -19,7 +19,7 @@ Tour(int x, int y); // ABSTRACT - bool can(const int x, const int y) const; + bool can(const ChessContext& ctx, int x, int y); char getchar(); }; diff --git a/Chess/dep/Player.cpp b/Chess/dep/Player.cpp new file mode 100644 index 0000000..8890250 --- /dev/null +++ b/Chess/dep/Player.cpp @@ -0,0 +1,85 @@ +// CONSTRUCTEUR +Player::Player(bool first) : _first(first){ + setfont(GREEN, BOLD); + + cout << "[+] Player " << (_first?1:2); + + setfont(); + cout << endl; +} + +// GETTERS +bool Player::owns(Piece& p) const{ + for( int i = 0 ; i < _pieces.size() ; i++ ) + if( _pieces.at(i) == &p ) return true; + + return false; +} + +Piece* Player::at(const int x, const int y){ + for( int i = 0 ; i < _pieces.size() ; i++ ) + if( _pieces[i]->getx() == x && _pieces[i]->gety() == y ) + return _pieces[i]; + + return NULL; + +} +// SETTERS +void Player::addPiece(Piece& p){ + _pieces.push_back( &p ); + + /* DEBUG */ + setfont(BLUE, ITALIC); + + cout << "\t\t[+] linked to Player " << (_first?1:2); + + setfont(); + cout << endl; +} + +void Player::remPiece(Piece& p){ + int index = -1; + + // On cherche la piece + for( int i = 0 ; i < _pieces.size() ; i++ ) + if( _pieces.at(i) == &p ) + index = i; + + // On ajoute au cimetiere + if( index > -1 ){ + _cimetery.push_back( &p ); + _pieces.erase(_pieces.begin() + index ); + } + + /* DEBUG */ + setfont(BLUE, ITALIC); + + cout << "\t\t[-] " << p << " to cimetery of Player " << (_first?1:2); + + setfont(); + cout << endl; +} + +// INITIALISATION DES PIECES DE BASE +void Player::initPieces(){ + int y1 = _first ? 0 : 7; // ligne forte + int y2 = _first ? 1 : 6; // ligne de pions + + + // Premier ligne + this->addPiece( PieceFactory::create(TOUR, 0, y1) ); + this->addPiece( PieceFactory::create(CAVALIER, 1, y1) ); + this->addPiece( PieceFactory::create(FOU, 2, y1) ); + + this->addPiece( PieceFactory::create(REINE, 3, y1) ); + this->addPiece( PieceFactory::create(ROI, 4, y1) ); + + this->addPiece( PieceFactory::create(FOU, 5, y1) ); + this->addPiece( PieceFactory::create(CAVALIER, 6, y1) ); + this->addPiece( PieceFactory::create(TOUR, 7, y1) ); + + for( int i = 0 ; i < 8 ; i++ ) + this->addPiece( PieceFactory::create(PION, i, y2) ); + +} + diff --git a/Chess/dep/Player.h b/Chess/dep/Player.h new file mode 100644 index 0000000..bddb4e6 --- /dev/null +++ b/Chess/dep/Player.h @@ -0,0 +1,45 @@ +#ifndef DEF_PAYER_H + + #define DEF_PAYER_H + + /* [1] Libs + =========================================================*/ + /* (1) Internes */ + #include + #include + #include + + /* (2) Externes */ + #include "term.h" + #include "Pieces/PieceFactory.h" + + /* (3) Namespace */ + using namespace std; + + + /* [2] Definition + =========================================================*/ + class Player{ + public: + Player(bool first); + + // GETTERS + bool _first; + bool owns(Piece& p) const; + Piece* at(const int x, const int y) ; + + // SETTERS + void addPiece(Piece& p); + void remPiece(Piece& p); + void initPieces(); + + private: + vector _pieces; + vector _cimetery; + }; + + /* [n] Inclusion du corps + =========================================================*/ + #include "Player.cpp" + +#endif \ No newline at end of file diff --git a/Chess/dep/term.h b/Chess/dep/term.h index 5237c47..c146219 100644 --- a/Chess/dep/term.h +++ b/Chess/dep/term.h @@ -1,6 +1,6 @@ -#ifndef DEF_TERM +#ifndef DEF_TERM_H - #define DEF_TERM + #define DEF_TERM_H /* [1] Libs =========================================================*/ diff --git a/Chess/e b/Chess/e deleted file mode 100755 index 9abe399292acae7207db8fdb07f85ab541e72b9d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15821 zcmeHOdvH`$nm_4)gjZ+~ccP5Yvbci}+5`f|*VrKsI}k!9X)uD}rb!yonxwPo+YnSR zR?x8rbu$+0uv2TT&)0 z6;QL)EOil(@%RsD2~m?1I?S$x7O-AE=s5hBc??kI3FwT_uNqhhl^PPI@-ivFSwm-D zW>}$0`7}UwRM+9lH4ECJGeY~g9_>^qoqYOAFxeH&)+}g?&IldkiV2nWksJCCvEPs< z0FL+o5ml+L87jrrzi+ou{^-R<;poKyoe^5fu6ih5$#I!F6b>=vS3N6KOXZh)a@q!q&wgYYOE0aH2fcZVA5Mpw!ZS( z6`!4-IKS%c+Dmp#sQ{ca{SfGk91^OhF9$wn6ub)+%H`+DQSgCL@I|BeKL|XR|COWY z(>Tbb|C3StJOKO(b*bv}wIHWdlfEid1wVwVxh)zI{P*C<{~lfsv=Eml<9#mt2f(Mp z&mjBv!mmykFLArA^_pvF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B+IBvHm{3Ur2n;FfQNyrGGtW2>Frk=aaZTUf@)J_qucqyVkL)WDKMw)-qQBhz_&DpkKx-u90%#I&w*2YTG&6kSNU+5YyMuL@u^DoTS&VWGwxo8D;WPd z_wTp3fDMc<_c z`w zgcBN>gBX_Gi4zAniV;_G0>c4WR$I*4*b!SF?y%bISWnyvCwdj$Pj+`i>`0q`$qm;p zg6AAc7QHDo?>#NN%k0^r%$w4-L}%v~m^e6`)`;3!s&s0>-`d@+&s)@%SynWrU&2~z zN=tA?!VcRwo5cNGwN<2%RmZk$K%aY2R^=Uaf4u6 zb#|FVLsbnc ztcsPjD;qf97`mgD4zkrPPgf)pzR>D42$j%knb*+PQOjuJl-{3orq10KlwmerS`qy< z4HeUo%4!^zJyxP|r8ivC#N47MCe8-Bof;SE6})7jHmMG`;&!-YNh?kW+L4ii2`i_R X5~^{=L3h8SLi&JSderlX(~at(x, y); + Piece *p2_Piece = ctx._p2->at(x, y); + /* (1) Si Joueur 1 a une piece sur la case */ + if( p1_Piece != NULL ){ + setfont(YELLOW, BOLD); + cout << p1_Piece->getchar(); + setfont(); + } + + /* (2) Si Joueur 2 a une piece sur la case */ + else if( p2_Piece != NULL ){ + setfont(SKYBLUE, BOLD); + cout << p2_Piece->getchar(); + setfont(); + } + + /* (3) Si la case est vide */ + else + cout << " "; + + cout << " "; + + } + + cout << "+ " << (8-y) << endl; + cout << " + + + + + + + + +" << endl; + cout << " +-------+-------+-------+-------+-------+-------+-------+-------+" << endl; + } + + cout << " A B C D E F G H" << endl; + cout << endl << endl; + + if( ctx._turn == '1' ) + cout << "TOUR DU JOUEUR 1" << endl; + else if( ctx._turn == '2' ) + cout << "TOUR DU JOUEUR 2" << endl; + else + cout << "PARTIE FINIE" << endl; + + +} + +/* [2] Traitement pour chaque tour +=========================================================*/ +void game_routine(ChessContext& ctx){ + int origin[2]; // contiendra la position d'origine + int dest[2]; // contiendra la position souhaitee + + // Contient le joueur courant + Player *curnt = (ctx._turn=='1') ? ctx._p1 : ctx._p2; + // Contient l'ennemi + Player *enemy = (ctx._turn=='1') ? ctx._p2 : ctx._p1; + + + + /* [2] On prends la saisie de l'utilisateur + =========================================================*/ + chess_input(origin, dest); + + cout << "(" << origin[0] << "," << origin[1] << ")" << endl; + + /* [3] On verifie qu'un pion est a cette case + =========================================================*/ + Piece *toMove = ctx._p1->at(origin[0], origin[1]); + + if( toMove == NULL ) + toMove = ctx._p2->at(origin[0], origin[1]); + + if( toMove != NULL ) + cout << *toMove << endl; + + else{ + cout << "Aucune piece sur cette case" << endl; + return; + } + + + /* [4] On verifie qu'il peut atteindre la destination + =========================================================*/ + cout << "Can move to dest : " << toMove->can(ctx, dest[0], dest[1]) << endl; + + + /* [5] On gere le deplacement + =========================================================*/ + /* (1) Gestion de si on mange l'ennemi */ + Piece *eaten = enemy->at(dest[0], dest[1]); + if( eaten != NULL ) // si piece mangee + enemy->remPiece( *eaten ); // on mange l'ennemi + + toMove->move(dest[0], dest[1]); // on deplace la piece + + + /* [n] Gestion du tour ou partie finie + =========================================================*/ + ctx._turn = (ctx._turn=='1') ? '2' : '1'; +} + +/* [3] Gestion de la saisie du tour +=========================================================*/ +void chess_input(int* origin, int* dest){ + char coord[2] = {'\0'}; + + cout << "Piece to move (XN) : "; + cin >> coord; + Piece::decode(coord, origin); + cout << endl; + + cout << "Move to (XN) : "; + cin >> coord; + Piece::decode(coord, dest); + cout << endl; +} \ No newline at end of file diff --git a/Chess/main.h b/Chess/main.h index e855e20..d6e9b79 100644 --- a/Chess/main.h +++ b/Chess/main.h @@ -1,6 +1,6 @@ -#ifndef DEF_HEADER +#ifndef DEF_MAIN_H - #define DEF_HEADER + #define DEF_MAIN_H /* [1] Libs =========================================================*/ @@ -8,10 +8,12 @@ #include #include #include + #include + #include /* (2) Externes */ #include "dep/term.h" - #include "dep/Grid.h" + #include "dep/ChessContext.h" /* (3) Namespace */ using namespace std; @@ -24,5 +26,8 @@ /* [3] Methodes =========================================================*/ int main(); + void display_board(ChessContext& ctx); + void game_routine(ChessContext& ctx); + void chess_input(int* origin, int* dest); #endif \ No newline at end of file