|
#pragma once
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include "card.hpp"
|
|
#include "deck.hpp"
|
|
#include "player.hpp"
|
|
#include "sort.hpp"
|
|
#include "game_details.hpp"
|
|
#define GAME_HPP
|
|
|
|
class Game
|
|
{
|
|
public:
|
|
std::vector<Player> players;
|
|
std::vector<Card> communityCards;
|
|
int playerCount = 0;
|
|
Deck deck;
|
|
Player bestPlayer;
|
|
Game(int playerCount)
|
|
{
|
|
this->playerCount = playerCount;
|
|
for (int i = 0; i < playerCount; i++)
|
|
{
|
|
std::string name = std::string("Player ") + std::to_string(i + 1);
|
|
this->players.push_back(Player(name));
|
|
}
|
|
|
|
}
|
|
GameDetails getGameDetails(){
|
|
// TODO
|
|
GameDetails gameDetails;
|
|
//gameDetails
|
|
return gameDetails;
|
|
}
|
|
void addCommunityCards(int amount)
|
|
{
|
|
for (int i = 0; i < amount; i++)
|
|
{
|
|
this->communityCards.push_back(this->deck.getCard());
|
|
}
|
|
sort_card_vector_ascending(this->communityCards);
|
|
for(auto & player : this->players){
|
|
player.setCommunityCards(this->communityCards);
|
|
}
|
|
}
|
|
void thePreFlop()
|
|
{
|
|
for(auto & player : this->players){
|
|
player.thePreFlop();
|
|
}
|
|
}
|
|
void theFlop()
|
|
{
|
|
this->addCommunityCards(3);
|
|
|
|
|
|
for(auto & player : this->players){
|
|
player.theFlop();
|
|
}
|
|
}
|
|
void theTurn()
|
|
{
|
|
this->addCommunityCards(1);
|
|
for(auto & player : this->players){
|
|
|
|
player.theTurn();
|
|
|
|
}
|
|
}
|
|
void theRiver()
|
|
{
|
|
this->addCommunityCards(1);
|
|
for (auto &player : this->players)
|
|
{
|
|
player.theRiver();
|
|
}
|
|
}
|
|
void showdown()
|
|
{
|
|
for (auto &player : this->players)
|
|
{
|
|
player.showDown();
|
|
}
|
|
}
|
|
|
|
void updatePlayerStatistics() {
|
|
for (auto &player : this->players)
|
|
{
|
|
player.update();
|
|
player.score.calculate();
|
|
}
|
|
this->bestPlayer = this->players[0];
|
|
for (auto &player : this->players)
|
|
{
|
|
if (player.score.score >= this->bestPlayer.score.score)
|
|
this->bestPlayer = player;
|
|
}
|
|
for (auto &player : this->players)
|
|
{
|
|
if (player.score.score == this->bestPlayer.score.score)
|
|
{
|
|
if (player.name != this->bestPlayer.name)
|
|
{
|
|
// tie
|
|
player.ties++;
|
|
this->bestPlayer.ties++;
|
|
}
|
|
else
|
|
{
|
|
player.wins++;
|
|
// win
|
|
}
|
|
}
|
|
else
|
|
{
|
|
player.losses++;
|
|
// loss
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void playTheFlop(std::string cardString = ""){
|
|
this->start(cardString);
|
|
this->thePreFlop();
|
|
this->theFlop();
|
|
this->updatePlayerStatistics();
|
|
}
|
|
|
|
void start(std::string cardString = ""){
|
|
this->deck = Deck(cardString);
|
|
this->communityCards.clear();
|
|
for (auto &player : this->players)
|
|
{
|
|
player.reset();
|
|
Card card1 = this->deck.getCard();
|
|
Card card2 = this->deck.getCard();
|
|
player.setCards(card1, card2);
|
|
}
|
|
}
|
|
|
|
void play(std::string cardString = "")
|
|
{
|
|
this->start(cardString);
|
|
this->thePreFlop();
|
|
this->theFlop();
|
|
this->theTurn();
|
|
this->theRiver();
|
|
this->showdown();
|
|
this->updatePlayerStatistics();
|
|
}
|
|
void print()
|
|
{
|
|
std::cout << "Cards in deck: " << this->deck.length << std::endl;
|
|
for (auto &player : this->players)
|
|
{
|
|
std::cout << player.name << ": ";
|
|
for (auto &card : player.cards)
|
|
{
|
|
std::cout << card.key << ",";
|
|
}
|
|
std::cout << player.score.score << " ";
|
|
std::cout << player.score.name << std::endl;
|
|
}
|
|
for (auto &card : this->communityCards)
|
|
{
|
|
std::cout << card.key << ",";
|
|
}
|
|
std::cout << std::endl;
|
|
}
|
|
};
|