Skip to content

Commit

Permalink
Move utils into game + add player field
Browse files Browse the repository at this point in the history
  • Loading branch information
Duzzuti committed Dec 26, 2023
1 parent 33b4ca9 commit 44a93d4
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 116 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3")

set(INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include)
set(SRC_DIR ${PROJECT_SOURCE_DIR}/src)
set(TEST_DIR ${PROJECT_SOURCE_DIR}/tests)
set(PLAYER_DIR ${SRC_DIR}/players)
set(CHECK_PLAYER ${PLAYER_DIR}/check_player/check_player.cpp)
set(RAND_PLAYER ${PLAYER_DIR}/rand_player/rand_player.cpp)
Expand Down
36 changes: 25 additions & 11 deletions include/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,60 @@
#include "player.h"

class Game {
friend class GameTest;

public:
Game(const Config& config) noexcept : m_config(config) {}
Game(const Config& config) noexcept : m_config(config), players(new Player*[config.numPlayers]) {}

void run();

void run() const;
~Game() {
for (int i = 0; i < this->m_config.numPlayers; i++) {
delete this->players[i];
}
delete[] this->players;
}

private:
std::string getPlayerInfo(const Data& data) const noexcept;

void initPlayerOrder() noexcept;

// starts a round by shuffling the deck, setting the dealer and the blinds
OutEnum startRound(Player* players[], Data& data, Deck& deck, const bool firstRound) const noexcept;
OutEnum startRound(Data& data, Deck& deck, const bool firstRound) const noexcept;

// sets the blinds for the round by betting the small and big blind automatically
OutEnum setBlinds(Player* players[], Data& data) const noexcept;
OutEnum setBlinds(Data& data) const noexcept;

// sets up the data for a bet round (preflop, flop, turn, river)
void setupBetRound(Data& data) const noexcept;

// runs a single bet round (preflop, flop, turn, river)
OutEnum betRound(Player* players[], Data& data) const;
OutEnum betRound(Data& data) const;

// runs a single non out player turn
OutEnum playerTurn(Player* players[], Data& data, short* firstChecker) const;
OutEnum playerTurn(Data& data, short* firstChecker) const;

// the current player bets amount and the next player is selected
// note that amount is the total amount that the player bets (e.g. if the player has to call 200 but he already bet 100 => amount is still 200)
bool bet(Data& data, const u_int64_t amount) const noexcept;

// selects the current player as out and returns true if only one player is left in this game, selects the next player
OutEnum playerOut(Player* players[], Data& data) const noexcept;
OutEnum playerOut(Data& data) const noexcept;

// selects the current player as folded and returns true if only one player is left in this round, selects the next player
OutEnum playerFolded(Data& data) const noexcept;

OutEnum getOutEnum(const Data& data) const noexcept;

OutEnum preflop(Player* players[], Data& data, OutEnum lastRes) const noexcept;
OutEnum preflop(Data& data, OutEnum lastRes) const noexcept;

OutEnum flop(Player* players[], Data& data, Deck& deck, OutEnum lastRes) const noexcept;
OutEnum flop(Data& data, Deck& deck, OutEnum lastRes) const noexcept;

OutEnum turn(Player* players[], Data& data, Deck& deck, OutEnum lastRes) const noexcept;
OutEnum turn(Data& data, Deck& deck, OutEnum lastRes) const noexcept;

OutEnum river(Player* players[], Data& data, Deck& deck, OutEnum lastRes) const noexcept;
OutEnum river(Data& data, Deck& deck, OutEnum lastRes) const noexcept;

Config m_config;
Player** players;
};
2 changes: 1 addition & 1 deletion include/hand_strengths.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class HandStrengths {

HandStrengths(HandKinds handkind, u_int32_t rankStrength) noexcept : handkind(handkind), rankStrength(rankStrength){};

static std::vector<HandStrengths> getHandStrengths(Player* players[], const Data& data) noexcept;
static std::vector<HandStrengths> getHandStrengths(Player* const players[], const Data& data) noexcept;
static HandStrengths getHandStrength(const std::pair<Card, Card>& hand, const std::vector<Card>& community) noexcept;
static u_int32_t getRankStrength(const std::vector<Card> sortedCards, const u_int8_t num) noexcept;

Expand Down
6 changes: 0 additions & 6 deletions include/utils.h

This file was deleted.

6 changes: 2 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Add the executable target
add_executable(PokerWorkshop main.cpp deck.cpp game.cpp player.cpp utils.cpp hand_strengths.cpp ${CHECK_PLAYER} ${RAND_PLAYER})
add_executable(PokerWorkshop main.cpp deck.cpp game.cpp player.cpp hand_strengths.cpp ${CHECK_PLAYER} ${RAND_PLAYER})
# Include headers
target_include_directories(PokerWorkshop PUBLIC ${INCLUDE_DIR})
target_include_directories(PokerWorkshop PUBLIC ${PLAYER_DIR})

target_include_directories(PokerWorkshop PUBLIC ${INCLUDE_DIR} ${PLAYER_DIR})

# Link with plog library
target_link_libraries(PokerWorkshop plog)
Loading

0 comments on commit 44a93d4

Please sign in to comment.