merge-requests/1/merge
marouault 4 years ago
commit 6fd58d28b6

@ -1,7 +1,7 @@
/**
* \file Game.h
* \brief Management of a Game
* \author Théotime Maillarbaux
* \author Théotime Maillarbaux, Jacques Thomas
* \date 29/11/2021
*/
@ -11,6 +11,7 @@
#include "model/Player.h"
#include "model/Board.h"
#include <SDL2/SDL_pixels.h>
#include <stdbool.h>
/**
* \enum Phase
@ -41,5 +42,39 @@ typedef struct {
*/
Game newGame(const int nbPlayers, const char* pseudos[]);
/**
* \brief Move a piece to an island
* \param[in] p the piece to move
* \param[in] i island target
* \return True if the piece can be move otherwise false
*/
bool movePiece(Piece p, Island i);
/**
* \brief Check if the the island is attainable from the piece's position (no player on the island)
* \param[in] p the piece to move
* \param[in] i island target
* \return True if the island is attainable (no player on the island) otherwise false
*/
bool checkIsland(Piece p, Island i);
/**
* \biref Check if there is a bridge at (coord->x; coord->y)
* \param[in] coords Coords to test
* \param[in] board Actual game board
* \return True if there is a bridge. Else return false.
*/
bool checkBridge(Coord* coords, Board* board);
/**
* \brief Remove bridge from board at (coord->x; coord->y)
* \param[in] coords Bridge's coords to remove
* \param[in] board Actual game board
* \return True on succsess. Else return false.
*/
bool rmBridge(Coord* coords, Board* board);
#endif //PARTIE_H

@ -1,7 +1,7 @@
/**
*\file Island.h
*\brief Island's model
*\author Jacques
*\author Jacques Thomas
*\date 29/11/2021
*/

@ -1,7 +1,7 @@
/**
*\file Piece.h
*\brief Piece's model
*\author Jacques
*\author Jacques Thomas
*\date 29/11/2021
*/

@ -5,7 +5,7 @@ Board newBoard(const int nbPlayers) {
int nbPiecesPerPlayer = (nbPlayers == 4) ? 2 : 3;
int pieceIndex = 0;
// Init pieces
// Init pieces for each player
for (int player_i = 0; player_i < nbPlayers; player_i++) {
for (int piece_i = 0; piece_i < nbPiecesPerPlayer; piece_i++) {
board.arrPieces[pieceIndex] = newPiece(player_i);
@ -19,8 +19,12 @@ Board newBoard(const int nbPlayers) {
for (int vy = 0; vy < 4; vy++) {
for (int vx = 0; vx < 5; vx++) {
board.vBridges[vy][vx] = true;
board.hBridges[vx][vy] = false;
board.hBridges[vx][vy] = true;
}
}
return board;
}

@ -24,3 +24,44 @@ Game newGame(const int nbPlayers, const char* pseudos[]) {
return g;
}
bool movePiece(Piece p, Island i)
{
return checkIsland(p,i) && checkBridge(p,i); //Otherwise call one function before one other
}
//Not yet over
bool checkIsland(Piece p, Island i)
{
bool check;
int diff;
if(p.island.x==i.x) //piece and island are on the same x axe
{
diff=p.island.y-i.y;
return -1<diff && diff<1; //Island is atteinable if the difference is between -1 and 1 y on the y axe
}
else if (p.island.y==i.y) //piece and island are on the same y axe
{
diff=p.island.x-i.y;
return -1<diff && diff<1; //Island is atteinable if the difference is between -1 and 1 x on the x axe
}
return false;
}
bool checkBridge(Coord* coords, Board* board)
{
if((coords->x%2 == 1) && (coords->y%2 == 0))
{
return board->hBridge[coord->y][coord->x];
}
if((coords->x%2 == 0) && (coords->y%2 == 1))
{
return board->vBridge[coord->y][coord->x];
}
return false;
}

Loading…
Cancel
Save