From 6d63c6a402cdef000ee38d01a79b900b9fd11bbd Mon Sep 17 00:00:00 2001 From: Allan POINT Date: Mon, 6 Dec 2021 11:58:44 +0100 Subject: [PATCH 1/2] Add CheckBridge --- Pontu/include/model/Game.h | 17 +++++++++++++++++ Pontu/src/model/Game.c | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Pontu/include/model/Game.h b/Pontu/include/model/Game.h index 787b907..7910b67 100644 --- a/Pontu/include/model/Game.h +++ b/Pontu/include/model/Game.h @@ -11,6 +11,7 @@ #include "model/Player.h" #include "model/Board.h" #include +#include /** * \enum Phase @@ -42,4 +43,20 @@ typedef struct { Game newGame(const int nbPlayers, const char* pseudos[]); +/** + * \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 diff --git a/Pontu/src/model/Game.c b/Pontu/src/model/Game.c index dac2c7f..802a623 100644 --- a/Pontu/src/model/Game.c +++ b/Pontu/src/model/Game.c @@ -24,3 +24,16 @@ Game newGame(const int nbPlayers, const char* pseudos[]) { return g; } +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; +} + From 36f0bc44095f3c62ef872654e9c92820d2917b36 Mon Sep 17 00:00:00 2001 From: jathomas2 Date: Mon, 6 Dec 2021 12:00:06 +0100 Subject: [PATCH 2/2] Add in game.c and game.h, the functions : movePiece and checkIsland, MUST BE tested git add *! --- Pontu/include/model/Game.h | 21 ++++++++++++++++++++- Pontu/include/model/Island.h | 2 +- Pontu/include/model/Piece.h | 2 +- Pontu/src/model/Board.c | 8 ++++++-- Pontu/src/model/Game.c | 25 +++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 5 deletions(-) diff --git a/Pontu/include/model/Game.h b/Pontu/include/model/Game.h index 787b907..d2feb36 100644 --- a/Pontu/include/model/Game.h +++ b/Pontu/include/model/Game.h @@ -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 +#include /** * \enum Phase @@ -41,5 +42,23 @@ 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); + #endif //PARTIE_H diff --git a/Pontu/include/model/Island.h b/Pontu/include/model/Island.h index 8b0b246..dee0caa 100644 --- a/Pontu/include/model/Island.h +++ b/Pontu/include/model/Island.h @@ -1,7 +1,7 @@ /** *\file Island.h *\brief Island's model - *\author Jacques + *\author Jacques Thomas *\date 29/11/2021 */ diff --git a/Pontu/include/model/Piece.h b/Pontu/include/model/Piece.h index 2948d6d..535cf43 100644 --- a/Pontu/include/model/Piece.h +++ b/Pontu/include/model/Piece.h @@ -1,7 +1,7 @@ /** *\file Piece.h *\brief Piece's model - *\author Jacques + *\author Jacques Thomas *\date 29/11/2021 */ diff --git a/Pontu/src/model/Board.c b/Pontu/src/model/Board.c index c427b6f..da68406 100644 --- a/Pontu/src/model/Board.c +++ b/Pontu/src/model/Board.c @@ -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; } + + + + diff --git a/Pontu/src/model/Game.c b/Pontu/src/model/Game.c index dac2c7f..bef46fc 100644 --- a/Pontu/src/model/Game.c +++ b/Pontu/src/model/Game.c @@ -24,3 +24,28 @@ 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