From d73c93b4c783edfc6f3afe19d35b9409953c7323 Mon Sep 17 00:00:00 2001 From: Stephen Enders Date: Wed, 27 Jan 2021 22:15:08 -0500 Subject: Legal placement logic and capturing Use board_t for board and prevent illegal placements. And allow for piece capture --- src/helper.hpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/helper.hpp') diff --git a/src/helper.hpp b/src/helper.hpp index 9495791..2ff8b24 100644 --- a/src/helper.hpp +++ b/src/helper.hpp @@ -16,6 +16,9 @@ static const float SPRITE_ROWS = 9.f; static const float SPRITE_COLS = 14.f; static const float SCR_W = SPRITE_SIZE / ZOOM * SPRITE_COLS / ZOOM; static const float SCR_H = SPRITE_SIZE / ZOOM * SPRITE_ROWS / ZOOM; +static const int SHARED_ID = -1; +static const int P1_ID = 0; +static const int P2_ID = 1; static const int P1_PIECE = 19; static const int P2_PIECE = 18; static const int P1_BOARD_TILES[2] = { 0, 1 }; @@ -45,10 +48,19 @@ struct piece_t int id; int position; sf::Sprite sprite; + sf::Vector2f origin; +}; + +struct board_t +{ + int pid; // owning players space -1 for shared + int position; + sf::Sprite sprite; }; struct player_t { + int pid; int score; std::shared_ptr> pieces; }; @@ -63,14 +75,14 @@ struct dice_t std::shared_ptr> loadTextures(const char* path); -std::shared_ptr> +std::shared_ptr> createBoard(std::shared_ptr> textures); sf::Font loadFont(); std::shared_ptr -createPlayer(sf::Texture& pieceTexture); +createPlayer(const int pid, sf::Texture& pieceTexture); std::shared_ptr createPiece(int id, sf::Texture& texture); @@ -101,4 +113,13 @@ getLegalMoves(std::shared_ptr activePlayer, sf::Vector2f pos(float c, float r); + +bool +canPlace(struct piece_t* piece, + int turn_pid, + struct board_t board_tile, + std::shared_ptr> myPieces, + std::shared_ptr> opponentPieces, + int& takenPieceId); + #endif -- cgit v1.2.3-54-g00ecf