Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.17)
project(Proj)

set(CMAKE_CXX_STANDARD 17)

file(GLOB SOURCES
sources/*.cpp
)
include_directories(include)
add_executable(Proj ${SOURCES})
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
# Pocker-ProjectTP-
# Poker

### Structure of the game:


* There is a card tableю Player is up to choose one of the 2 modes of poker to play: [**Classical Poker**](https://en.wikipedia.org/wiki/Draw_poker) and [**No Limit Texas Holdem**](https://en.wikipedia.org/wiki/Texas_hold_%27em).
In the beginning of the game, players register by entering their names.

### Details of realization:

* All players initially have the same amount of money, 100 conventional units. At the beginning of the game, players are randomly dealt 2 cards.
Each card has its own value and suit. Users take turns: _raising/calling/folding_,
while game stages consequently change in the following order: _preflop, flop, turn, river_. Before the move of next player, other players' moves are hidden, current best combination for this player is shown.

* At the end of the round, based on the cards on the table and in the hands of the remaining players, the winner is determined who takes all the pot.
Players with no money left are eliminated and new round begins.
The game is played until there is only **one winner** left.

### Useful patterns and hints used:

1. Observer
2. Command - players' actions


We tried our best to comply with the **SOLID principles**.

### Installation:

> $ git clone git@github.com:tasticolly/Pocker-ProjectTP-.git
>
> $ cmake -B build
>
> $ cmake --build build

### Run:

> $ ./build/Proj
Binary file added description/ATP_POCKER.pdf
Binary file not shown.
27 changes: 27 additions & 0 deletions include/Card.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <string>
#ifndef CARD_H_
#define CARD_H_
using std::string;

enum Suit{
HEARTS=1, DIAMONDS, SPADES, CLUBS};
enum Face{
TWO=1, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE};

class Card {
private:
Suit suit;
Face face;
public:
Card(const Suit& suit, const Face& face);
Face getFace() const;
void setFace(Face face);
Suit getSuit() const;
void setSuit(Suit suit);
string getSuitString();
string getFaceString();
string toString();
virtual ~Card();
};

#endif /* CARD_H_ */
32 changes: 32 additions & 0 deletions include/Deck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef DECK_H_
#define DECK_H_

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <vector>
#include "Card.h"
using std::vector;
using std::cout;
using std::endl;


class Deck {
private:
vector <Card> deck;
public:
Deck();
Deck(const vector<Card>& deck);
void initDeck();
const vector<Card>& getDeck() const;
void setDeck(const vector<Card>& deck);
void shuffle();
int cardsRemaining();
vector<Card> dealHand(const int& size);
Card drawCard(const unsigned& index = 0);
void addCard(const Card& card);
string toString();
virtual ~Deck();
};

#endif /* DECK_H_ */
59 changes: 59 additions & 0 deletions include/Hand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef HAND_H_
#define HAND_H_
#include "Card.h"
#include <vector>
#include <sstream>
#include <iostream>
using std::vector;
using std::string;
using std::cout;
using std::endl;
using std::stringstream;

class Hand {
private:
string ownerName;
vector <Card> hand;
unsigned short countFaces[13];
unsigned short countSuits[4];
public:
Hand(const vector<Card>& hand);

const vector<Card>& getHand() const;
void setHand(const vector<Card>& hand);
const string& getOwnerName() const;
void setOwnerName(const string& ownerName);

friend Hand operator+(Hand& hand1, Hand& hand2);
friend bool operator>(Hand& hand1, Hand& hand2);
friend bool operator<(Hand& hand1, Hand& hand2);
friend bool operator>=(Hand& hand1, Hand& hand2);
friend bool operator<=(Hand& hand1, Hand& hand2);
friend bool operator==(Hand& hand1, Hand& hand2);

void countCardProps();
void sortBySuit(const bool& asc = false);
void sortByFace(const bool& asc = false);
void swapCards(const unsigned& index1, const unsigned& index2);
Card getCard(int index);
Card peekCard(int index);
void addCard(Card card);
int cardsRemaining();
bool hasFaceMatch(const int& num1, const int& num2 = 0);
bool hasSuitMatch(const int& num);
bool hasStraight();
unsigned short getHighestCard(const short& recur = 0);
unsigned short getHighestCombo(const short& recur = 0);
int evaluate();
string printEvaluation();
string toFaceSymbol(const Face& index);
string toSuitSymbol(const Suit& index);
string drawHand(const int& faceDown = 0);
string toString();
static void winner(Hand& h1, Hand& h2);
static int determineWinner(Hand& hand1, Hand& hand2);

virtual ~Hand();
};

#endif /* HAND_H_ */
39 changes: 39 additions & 0 deletions include/PokerGame.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef POKERGAME_H_
#define POKERGAME_H_

#include <iostream>
#include <vector>
#include <sstream>
#include "Deck.h"
#include "Hand.h"
using namespace std;

class PokerGame {
private:
Deck deck;
unsigned short numOfPlayers{};
unsigned short gameType;
vector <Hand> playerHands;
vector <int> credit;
stringstream history;
static void splash();
static void clearScreen();
static void pause();
static void dash();
public:
PokerGame();
unsigned short getNumOfPlayers() const;
unsigned short getGameType() const;
const vector<Hand>& getPlayerHands() const;
void setNumOfPlayers(unsigned short numOfPlayers);
void setGameType(unsigned short gameType);
void setPlayerHands(const vector<Hand>& playerHands);
void discardFromHand(Hand& hand, int discard);
void beginGame();
void gameInit();
void classicGameLoop(int turns = 1);
void texasGameLoop(int turns = 1);
virtual ~PokerGame();
};

#endif /* POKERGAME_H_ */
58 changes: 58 additions & 0 deletions sources/Card.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "Card.h"

Card::Card(const Suit& suit, const Face& face) {
setSuit(suit);
setFace(face);
}

string Card::getSuitString() {
switch(suit){
case HEARTS: return "Hearts";
case DIAMONDS: return "Diamonds";
case SPADES: return "Spades";
case CLUBS: return "Clubs";
default: return "Unknown";
}
}

string Card::getFaceString() {
switch(face){
case TWO: return "Two";
case THREE: return "Three";
case FOUR: return "Four";
case FIVE: return "Five";
case SIX: return "Six";
case SEVEN: return "Seven";
case EIGHT: return "Eight";
case NINE: return "Nine";
case TEN: return "Ten";
case JACK: return "Jack";
case QUEEN: return "Queen";
case KING: return "King";
case ACE: return "Ace";
default: return "Unknown";
}
}

string Card::toString() {
return getFaceString() + " of " + getSuitString();
}

Face Card::getFace() const {
return face;
}

void Card::setFace(Face face) {
this->face = face;
}

Suit Card::getSuit() const {
return suit;
}

void Card::setSuit(Suit suit) {
this->suit = suit;
}

Card::~Card() {
}
65 changes: 65 additions & 0 deletions sources/Deck.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "Deck.h"

Deck::Deck() {
srand(time(nullptr));
initDeck();
}

Deck::Deck(const vector<Card> &deck) {
srand(time(nullptr));
setDeck(deck);
}

void Deck::initDeck() {
vector<Card> newDeck;
for (int i = TWO; i != ACE + 1; ++i)
for (int j = HEARTS; j != CLUBS + 1; ++j)
newDeck.emplace_back(static_cast<Suit>(j), static_cast<Face>(i));
setDeck(newDeck);
}

void Deck::setDeck(const vector<Card>& deck_) {
this->deck = deck_;
}

void Deck::shuffle() {
vector<Card> newDeck;
int rnum;
while (!deck.empty()) {
rnum = rand() % deck.size();
newDeck.push_back(drawCard(rnum));
}
setDeck(newDeck);
}

Card Deck::drawCard(const unsigned &index) {
Card drawnCard = deck[index];
deck.erase(deck.begin() + index);
return drawnCard;
}

void Deck::addCard(const Card& card_) {
deck.push_back(card_);
}

vector<Card> Deck::dealHand(const int &size) {
vector<Card> hand;
for (int i = 0; i < size; ++i)
hand.push_back(drawCard(0));
return hand;
}

string Deck::toString() {
string str = "";
for (int i = 0; i < cardsRemaining(); ++i)
str += deck[i].toString() + "\n";
return str;
}

const vector<Card> &Deck::getDeck() const { return deck; }

int Deck::cardsRemaining() { return deck.size(); }

Deck::~Deck() = default;


Loading