From c68f45a7c136c107262e54e341fd3f166bfa0913 Mon Sep 17 00:00:00 2001 From: jathomas2 Date: Mon, 13 Dec 2021 11:52:53 +0100 Subject: [PATCH] Game c : add getPieceFromIsland which allow you to get the piece from an island, and also add moveOnBoard which allows you to move piece from start position to end position --- Pontu/include/model/Board.h | 2 +- Pontu/include/model/Game.h | 15 ++++++++++++- Pontu/src/model/Game.c | 43 ++++++++++++++++++++++++++----------- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/Pontu/include/model/Board.h b/Pontu/include/model/Board.h index b04205c..556d69b 100644 --- a/Pontu/include/model/Board.h +++ b/Pontu/include/model/Board.h @@ -25,7 +25,7 @@ typedef struct { bool vBridges[4][5]; ///< 2D-array of vertical bridges. bool hBridges[5][4]; ///< 2D-array of horizontal bridges. Piece arrPieces[9]; ///< Array of pieces on the Board. - const size_t nbPieces; + const size_t nbPieces; ///< Logical size of arrPieces } Board; Board newBoard(const int nbPlayers); diff --git a/Pontu/include/model/Game.h b/Pontu/include/model/Game.h index 2555e20..b3d0e71 100644 --- a/Pontu/include/model/Game.h +++ b/Pontu/include/model/Game.h @@ -85,7 +85,7 @@ bool isPieceAdjacentToIsland(const Piece p, const Island i); /** - * \bref Check if there is a bridge between two Island. + * \brief Check if there is a bridge between two Island. * \param[in] start On island were the bridge ends * \param[in] target The other island were the bridge ends * \param[in] b The Board for this Game. @@ -93,6 +93,19 @@ bool isPieceAdjacentToIsland(const Piece p, const Island i); */ bool checkBridge(const Island start, const Island target, const Board* b); +/** + * \brief Get piece from island + * \param[in] arrPieces Array of all pieces + * \param[in] logicalSize The logical size of arrPieces + * \param[in] island The island on the one we want to check the piece + */ + +Piece* getPieceFromIsland(Piece arrPieces[9],int logicalSize, Island island); + +//NEED A COMMENTARY +bool moveOnBoard(const Coord start, const Coord end, Game* game); + + /** * \brief Remove bridge from board at (coord->x; coord->y) * \param[in] coords Bridge to remove diff --git a/Pontu/src/model/Game.c b/Pontu/src/model/Game.c index 9c52a09..e1eb6f6 100644 --- a/Pontu/src/model/Game.c +++ b/Pontu/src/model/Game.c @@ -123,29 +123,48 @@ bool cliqueOnBoard(const Coord coord, Game* game) { } break; case RM_BRIDGE: -<<<<<<< HEAD - - - break; -======= - /*if (islandOrBridge.type == ) - rmBridge - if (isIslandIsolated()) { + if (islandOrBridge.type == BRIDGE) + Bridge bridge = islandOrBridge.data.bridge; + rmBridge(bridge,game->board) + if (isPieceIsolated()) { //Check is a piece is isolated and then if the player is eliminated } - break;*/ ->>>>>>> cacb66ccf9c68400e71a998e9349c7dce919383f + break; default: break; } } +Piece* getPieceFromIsland(Piece arrPieces[9],int logicalSize, Island island){ + Piece *piece=NULL; + for(int i=0; iphase) { - case + case MOVE_PIECE: + if(islandOrBridgeStart.type==ISLAND && islandOrBridgeEnd.type==ISLAND) + { + Piece *piece; + int idCurrentPlayer = game->currentPlayerID; + Island islandStart = islandOrBridgeStart.data.island; + Island islandEnd = islandOrBridgeEnd.data.island; + piece=getPieceFromIsland(game->arrPieces,game->board.nbPieces,islandStart); + if(idCurrentPlayer==piece->idJ) //Check if the current player id is the same than the piece selected by the player + return movePiece(piece, islandEnd, game->board); + return false; + } } }