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

merge-requests/1/merge
Jacques THOMAS 4 years ago
parent d5cc01766e
commit c68f45a7c1

@ -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);

@ -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

@ -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; i<logicalSize;i++)
{
if(islandEqual(arrPieces[i].island,island))
{
*piece=arrPieces[i];
return piece;
}
}
}
bool moveOnBoard(const Coord start, const Coord end, Game* game) {
const IslandOrBridge islandOrBridge = coordToEntity(coord);
const IslandOrBridge islandOrBridgeStart = coordToEntity(start);
const IslandOrBridge islandOrBridgeEnd = coordToEntity(end);
switch(game->phase)
{
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;
}
}
}

Loading…
Cancel
Save