-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Duzzuti/20-add-human-player
Add human player
- Loading branch information
Showing
9 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "human_player.h" | ||
|
||
Action HumanPlayer::turn(const Data& data, const bool onlyRaise) const noexcept { | ||
std::cout << "Your hand: " << this->getHand().first.toString() << " " << this->getHand().second.toString(); | ||
std::cout << " | Community cards: "; | ||
for (u_int8_t i = 0; i < 5; i++) { | ||
if (data.roundData.betRoundState == BetRoundState::PREFLOP) | ||
break; | ||
else if (data.roundData.betRoundState == BetRoundState::FLOP && i == 3) | ||
break; | ||
else if (data.roundData.betRoundState == BetRoundState::TURN && i == 4) | ||
break; | ||
|
||
std::cout << data.roundData.communityCards[i].toString() << " "; | ||
} | ||
std::cout << "| Pot: " << data.roundData.pot << " | Current bet: " << data.betRoundData.currentBet; | ||
std::cout << " | Your chips: " << data.getChips() << std::endl; | ||
while (true) { | ||
if (onlyRaise) | ||
std::cout << "Please enter an action ('c' for call, 'r <bet>' for raise): "; | ||
else | ||
std::cout << "Please enter an action ('f' for fold, 'c' for call, 'chk' for check, 'r <bet>' for raise, 'b <bet>' for bet): "; | ||
std::string input; | ||
std::getline(std::cin, input); | ||
|
||
if (input == "f" && !onlyRaise) | ||
return {Actions::FOLD}; | ||
else if (input == "c") | ||
return {Actions::CALL}; | ||
else if (input == "chk" && !onlyRaise) | ||
return {Actions::CHECK}; | ||
else if (input[0] == 'r') { | ||
u_int64_t bet = std::stoull(input.substr(2)); | ||
return {Actions::RAISE, bet}; | ||
} else if (input[0] == 'b' && !onlyRaise) { | ||
u_int64_t bet = std::stoull(input.substr(2)); | ||
return {Actions::BET, bet}; | ||
} else { | ||
std::cout << "Invalid input! Try again" << std::endl; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
#include "player.h" | ||
|
||
class HumanPlayer : public Player { | ||
public: | ||
HumanPlayer(const std::string& name) noexcept : Player(name){}; | ||
HumanPlayer(u_int8_t playerNum = 0) noexcept : Player(!playerNum ? "HumanPlayer" : "HumanPlayer" + std::to_string(playerNum)){}; | ||
|
||
Action turn(const Data& data, const bool onlyRaise = false) const noexcept override; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
This player is a human player. It is used to play the game manually. | ||
You will be asked which action you want to perform at each turn. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters