summaryrefslogtreecommitdiff
path: root/src/helper.hpp
diff options
context:
space:
mode:
authorStephen Enders <smenders@gmail.com>2021-01-27 22:15:08 -0500
committerStephen Enders <smenders@gmail.com>2021-01-27 22:22:40 -0500
commitd73c93b4c783edfc6f3afe19d35b9409953c7323 (patch)
treedb6841bd704d8de2b16abfa34fa72e7e0039aed6 /src/helper.hpp
parent100907bd56b18c50aab9efb10700956b8c164c05 (diff)
Legal placement logic and capturing
Use board_t for board and prevent illegal placements. And allow for piece capture
Diffstat (limited to 'src/helper.hpp')
-rw-r--r--src/helper.hpp25
1 files changed, 23 insertions, 2 deletions
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<std::vector<struct piece_t>> pieces;
};
@@ -63,14 +75,14 @@ struct dice_t
std::shared_ptr<std::vector<sf::Texture>>
loadTextures(const char* path);
-std::shared_ptr<std::vector<struct piece_t>>
+std::shared_ptr<std::vector<struct board_t>>
createBoard(std::shared_ptr<std::vector<sf::Texture>> textures);
sf::Font
loadFont();
std::shared_ptr<struct player_t>
-createPlayer(sf::Texture& pieceTexture);
+createPlayer(const int pid, sf::Texture& pieceTexture);
std::shared_ptr<struct piece_t>
createPiece(int id, sf::Texture& texture);
@@ -101,4 +113,13 @@ getLegalMoves(std::shared_ptr<struct player_t> 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<std::vector<struct piece_t>> myPieces,
+ std::shared_ptr<std::vector<struct piece_t>> opponentPieces,
+ int& takenPieceId);
+
#endif