Mari's Tarot
 All Classes Files Functions Variables Enumerations Enumerator Friends
Game.hpp
Go to the documentation of this file.
1 /*
2  * Tarot is an application for Android system to play to French Tarot.
3  * Please visit https://github.com/richoux/Tarot for further information.
4  *
5  * Copyright (C) 2013-2016 Florian Richoux
6  *
7  * This file is part of Tarot.
8  * Tarot is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12 
13  * Tarot is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17 
18  * You should have received a copy of the GNU General Public License
19  * along with Tarot. If not, see http://www.gnu.org/licenses/.
20  */
21 
22 #pragma once
23 
24 #include <vector>
25 #include <stack>
26 #include <set>
27 #include <map>
28 #include <memory>
29 
30 #include "Suits.hpp"
31 #include "Biddings.hpp"
32 #include "Team.hpp"
33 #include "Player.hpp"
34 #include "Human.hpp"
35 #include "AI.hpp"
36 #include "Card.hpp"
37 // #include "StratLang.hpp"
38 #include "Trick.hpp"
39 #include "Deck.hpp"
40 
41 using namespace std;
42 
44 class Game
45 {
46 public:
47 
49  Game();
50 
52 
57  Game( int& numberPlayers, const bool automatic = false );
58 
60  void chooseKing();
61 
63 
67  void closeBiddings( const Biddings bestBid );
68 
70 
74  double computeScore( const string& name ) const;
75 
77  void dealCards();
78 
80  Team endGame();
81 
83  inline Biddings getBidding() const { return bidding; }
84 
86  inline int getCardsPerPlayer() const { return cardsPerPlayer; }
87 
89  inline shared_ptr<Trick> getCurrentTrick() const { return currentTrick; }
90 
92  inline Team getDefenders() const { return defenders; }
93 
95  inline set< shared_ptr<Card> >getDog() const { return dog; }
96 
98  inline shared_ptr<Card> getKingCalled() const { return kingCalled; }
99 
101  inline int getIndexBidder() const { return indexBidder; }
102 
104  inline int getIndexNext() const { return indexNext; }
105 
107  inline int getIndexStarter() const { return indexStarter; }
108 
110  inline int getIndexToBid() const { return indexToBid; }
111 
113  inline int getNumberPlayers() const { return players.size(); }
114 
116  inline vector< shared_ptr<Player> > getPlayers() const { return players; }
117 
119 
123  set<shared_ptr<Card> >getPlayerWonCards( const shared_ptr<Player> player ) const;
124 
126  inline Team getTakers() const { return takers; }
127 
129  shared_ptr<Trick> getTrick();
130 
132  inline Team getUnknownTeam() const { return unknown; }
133 
135  inline bool isBotsOnly() const { return botsOnly; }
136 
138  inline bool isKingFound() const { return kingFound; }
139 
141  void newGame();
142 
144  void printScores() const;
145 
147 
151  shared_ptr< Card > playCard( bool &kingJustFound );
152 
154 
159  bool sameTeam( const shared_ptr<Player> p1, const shared_ptr<Player> p2 ) const;
160 
162  void setGame( int& numberPlayers, const bool automatic = false );
163 
165  void showDeck() const;
166 
168  void showPlayersCards() const;
169 
171  void shuffleDeck();
172 
174 
178  pair< shared_ptr<Player>, Biddings > takeBiddings( const Biddings &bestBid );
179 
181  void takeDog();
182 
184  inline void updateIndexBidder() { indexBidder = indexToBid; }
185 
186 private:
188 
192  void addWonCards( const string& name, const set<shared_ptr<Card> >& cards );
193 
195 
200  bool isCardCalled( const shared_ptr<Card> card, const shared_ptr<Player> player );
201 
203  void nextPlayer();
204 
206 
209  void setNext( const shared_ptr<Player> player );
210 
212  void swapFool();
213 
215  void update();
216 
217  vector< shared_ptr<Player> > players;
218  map< string, set<shared_ptr<Card> > > cardsPlayer;
219  // shared_ptr<StratLang> language;
220  shared_ptr<Trick> currentTrick;
221  stack< shared_ptr<Trick> > history;
222  shared_ptr<Player> next;
223  int indexNext;
224  int indexStarter;
225  int indexToBid;
226  int indexBidder;
227  Deck deck;
228  set< shared_ptr<Card> > dog;
229  Team takers;
230  Team defenders;
231  Team unknown;
232  Biddings bidding;
233  shared_ptr<Card> kingCalled;
234  bool kingFound;
235  int dogSize;
236  int cardsPerPlayer;
237  int consecutiveDealing;
238  bool chelemAnnounced;
239  bool addDogAtTheEnd;
240 
241  bool toSwap;
242  bool botsOnly;
243  shared_ptr<Player> foolGiver;
244  shared_ptr<Player> foolReceiver;
245 };
shared_ptr< Trick > getCurrentTrick() const
Inline function returning the current trick.
Definition: Game.hpp:89
Team getUnknownTeam() const
Inline function returning the unknown team (only in a 5-player game).
Definition: Game.hpp:132
int getCardsPerPlayer() const
Inline function returning the number of cards players have to play in the game.
Definition: Game.hpp:86
set< shared_ptr< Card > > getDog() const
Inline function returning the dog.
Definition: Game.hpp:95
Team is the class handling team management.
Definition: Team.hpp:32
shared_ptr< Card > getKingCalled() const
Inline function returning the called king.
Definition: Game.hpp:98
Deck is the class managing the deck of cards. Used as well as for the game deck, but also for a count...
Definition: Deck.hpp:32
Team getTakers() const
Inline function returning the taker team.
Definition: Game.hpp:126
int getIndexNext() const
Inline function returning next player's index.
Definition: Game.hpp:104
bool isBotsOnly() const
Inline function returning if it is a game without any human players.
Definition: Game.hpp:135
int getNumberPlayers() const
Inline function returning the number of players.
Definition: Game.hpp:113
Game is one of the main class of Tarot. Here are defined rules, games' turns, scores, etc.
Definition: Game.hpp:44
int getIndexToBid() const
Inline function returning the index of the next player to bid.
Definition: Game.hpp:110
Biddings
The enum containing all official biddings.
Definition: Biddings.hpp:35
vector< shared_ptr< Player > > getPlayers() const
Inline function returning the players vector.
Definition: Game.hpp:116
int getIndexBidder() const
Inline function returning bidder's index.
Definition: Game.hpp:101
Biddings getBidding() const
Inline function returning the game bid.
Definition: Game.hpp:83
bool isKingFound() const
Inline function returning if it the called king is known.
Definition: Game.hpp:138
int getIndexStarter() const
Inline function returning starter player's index.
Definition: Game.hpp:107
void updateIndexBidder()
Inline function setting indexBidder to the value of indexToBid.
Definition: Game.hpp:184
Definition: Suits.hpp:33
Team getDefenders() const
Inline function returning the defender team.
Definition: Game.hpp:92