Mari's Tarot
 All Classes Files Functions Variables Enumerations Enumerator Friends
AI.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 <memory>
25 #include <map>
26 #include <vector>
27 
28 #include "Player.hpp"
29 #include "Suits.hpp"
30 #include "Card.hpp"
31 #include "Deck.hpp"
32 #include "StratDiff.hpp"
33 #include "Beginner.hpp"
34 #include "Biddings.hpp"
35 
36 using namespace std;
37 
39 
44 class AI : public Player
45 {
46 public:
48 
52  AI( const string& name, const vector<string>& knownPartners);
53 
55 
61  Biddings bid( const Biddings bestBid, const bool chelemAnnounced) const;
62 
64 
68  shared_ptr<Card> chooseKing( const Deck &deck ) const;
69 
71 
76  bool haveSuit( const string& name, const Suits suit) const;
77 
79 
83  inline bool isOpponent( const string& name ) const { return opponents.find( name ) == opponents.end() ? false : true; }
84 
86 
90  inline bool isPartner( const string& name ) const { return partners.find( name ) == partners.end() ? false : true; }
91 
93 
98  set< shared_ptr<Card> > makeEcart( const int dogSize );
99 
101 
104  void newGame();
105 
107 
111  bool opponentsHaveSuit( const Suits suit ) const;
112 
114 
120  shared_ptr<Card> playCard( const Suits referenceCard, const shared_ptr<Card> highTrump);
121 
123 
126  inline void setDifficulty ( const shared_ptr<StratDiff> diff ) { difficulty = diff; }
127 
128 private:
129 
131  class Counting
132  {
133  public:
135  Counting()
136  : hasHeart(true),
137  hasSpade(true),
138  hasDiamond(true),
139  hasClub(true),
140  hasTrump(true) {}
141 
142  bool hasHeart;
143  bool hasSpade;
144  bool hasDiamond;
145  bool hasClub;
146  bool hasTrump;
147 
149 
153  bool hasSuit( const Suits suit ) const
154  {
155  switch( suit )
156  {
157  case heart:
158  return hasHeart;
159  case spade:
160  return hasSpade;
161  case diamond:
162  return hasDiamond;
163  case club:
164  return hasClub;
165  case trump:
166  return hasTrump;
167  default:
168  return true;
169  }
170  }
171  };
172 
173  Deck cardCounting;
174  map<string, shared_ptr<Counting> > opponents;
175  map<string, shared_ptr<Counting> > partners;
176  shared_ptr<StratDiff> difficulty;
177 };
Suits
The enum containing all suits, plus the Fool as a special suit.
Definition: Suits.hpp:25
bool isPartner(const string &name) const
To know if someone is your partner.
Definition: AI.hpp:90
This class defines AI players.
Definition: AI.hpp:44
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
Definition: Suits.hpp:29
Definition: Suits.hpp:27
Definition: Suits.hpp:30
Biddings
The enum containing all official biddings.
Definition: Biddings.hpp:35
void setDifficulty(const shared_ptr< StratDiff > diff)
Inline function to set the difficulty (set a Strategy concrete class).
Definition: AI.hpp:126
bool isOpponent(const string &name) const
To know if someone is your opponent.
Definition: AI.hpp:83
Definition: Suits.hpp:28
Definition: Suits.hpp:31
Player is an abstract class presenting a common interface for AI and Human players.
Definition: Player.hpp:36