1 /*
2 
3   Euchre - a free as in freedom and as in beer version of the
4   euchre card game
5 
6   Copyright 2002 C Nathan Buckles (nbuckles@bigfoot.com)
7 
8   This program 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 2 of the License, or
11   (at your option) any later version.
12 
13   This program 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 this program; if not, write to the Free Software
20   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 
22 */
23 
24 #include <gtk/gtk.h>
25 
26 #include <Debug.hpp>
27 
28 #include "globals.hpp"
29 #include "support.hpp"
30 #include "ComputerGuiPlayer.hpp"
31 
ComputerGuiPlayer(Common::PlayerPosition myPos,Player * theAI)32 ComputerGuiPlayer::ComputerGuiPlayer(Common::PlayerPosition myPos,
33                                      Player* theAI) :
34     Player(myPos), GuiPlayer(myPos), itsAI(theAI) {}
35 
~ComputerGuiPlayer()36 ComputerGuiPlayer::~ComputerGuiPlayer() {
37     if (itsAI != NULL) {
38         delete itsAI;
39     }
40 }
41 
setHand(const Hand & theHand)42 void ComputerGuiPlayer::setHand(const Hand& theHand) {
43     Player::setHand(theHand);
44     itsAI->setHand(theHand);
45 }
46 
setTopCard(const Card & upCard)47 void ComputerGuiPlayer::setTopCard(const Card& upCard) {
48     setCardPixmap(cardPixmaps[upCard.getNumber()][upCard.getSuit()]);
49 }
50 
unsetTopCard()51 void ComputerGuiPlayer::unsetTopCard() {
52     setCardPixmap(itsOldPixmap);
53 }
54 
55 
auction1(const Card & upCard,Common::PlayerPosition dealer)56 Common::Bid ComputerGuiPlayer::auction1(const Card& upCard,
57                                         Common::PlayerPosition dealer) {
58     LOG(itsPos << " enter cgp::auction1" << std::endl);
59 
60     Common::Bid ret = itsAI->auction1(upCard, dealer);
61 
62     if (ret != Common::PASS) {
63         setBidSuitPixmap(bidSuitPixmaps[upCard.getSuit()]);
64 
65         if (ret == Common::PICKITUP) {
66             setBidCallPixmap(bidCallPixmaps[0]);
67         } else {
68             setBidCallPixmap(bidCallPixmaps[1]);
69         }
70 
71         LOG("going for it with " << itsHand
72             << " value " << itsHand.getValue(upCard.getSuit())
73             << std::endl);
74     } else {
75         setMarker(passMarkers[itsPos]);
76     }
77 
78     LOG(itsPos << " exit cgp::auction1 with " << ret << std::endl);
79     return ret;
80 }
81 
auction1End(const Card & upCard)82 void ComputerGuiPlayer::auction1End(const Card& upCard) {
83     setCardPixmap(itsOldPixmap);
84     itsAI->auction1End(upCard);
85     setMarker(NULL);
86 }
87 
auction2(Card & yourTrump,const Card & upCard,bool stuck)88 Common::Bid ComputerGuiPlayer::auction2(Card& yourTrump,
89                                         const Card& upCard,
90                                         bool stuck) {
91     LOG(itsPos << " enter cgp::auction2" << std::endl);
92 
93     Common::Bid ret = itsAI->auction2(yourTrump, upCard, stuck);
94 
95     if (ret != Common::PASS) {
96         setBidSuitPixmap(bidSuitPixmaps[yourTrump.getSuit()]);
97 
98         if (ret == Common::PICKITUP) {
99             setBidCallPixmap(bidCallPixmaps[0]);
100         } else {
101             setBidCallPixmap(bidCallPixmaps[1]);
102         }
103 
104         LOG("going for it with " << itsHand
105             << " value " << itsHand.getValue(yourTrump.getSuit())
106             << " trump " << yourTrump.getSuit()
107             << std::endl);
108     } else {
109         setMarker(passMarkers[itsPos]);
110     }
111 
112     LOG(itsPos << " exit cgp::auction2 with " << ret << std::endl);
113     return ret;
114 }
115 
setBid(Common::PlayerPosition who,Common::Bid bid)116 void ComputerGuiPlayer::setBid(Common::PlayerPosition who,
117                                Common::Bid bid) {
118     itsAI->setBid(who, bid);
119     setMarker(NULL);
120 }
121 
setTrump(Card::Suit trump)122 void ComputerGuiPlayer::setTrump(Card::Suit trump) {
123     LOG(itsPos << " enter cgp::setTrump" << std::endl);
124 
125     setCardPixmap(itsOldPixmap);
126     itsAI->setTrump(trump);
127 
128     LOG(itsPos << " exit cgp::setTrump" << std::endl);
129 }
130 
getCard(const Round & theRound,Common::PlayerPosition whoStarted)131 Card ComputerGuiPlayer::getCard(const Round& theRound,
132                                 Common::PlayerPosition whoStarted) {
133     LOG(itsPos << " enter cgp::getCard" << std::endl);
134 
135     LOG("  " << itsPos << " hand is " << itsAI->getHand() << std::endl);
136     Card ret = itsAI->getCard(theRound, whoStarted);
137     LOG("  " << itsPos << " cgp::getCard with " << ret << std::endl);
138     setCardPixmap(cardPixmaps[ret.getNumber()][ret.getSuit()]);
139     LOG("  " << itsPos << " hand is " << itsAI->getHand() << std::endl);
140 
141     LOG(itsPos << " exit cgp::getCard with " << ret << std::endl);
142     return ret;
143 }
144 
finishRound(const Round & theRound,Common::PlayerPosition whoStarted)145 void ComputerGuiPlayer::finishRound(const Round& theRound,
146                                     Common::PlayerPosition whoStarted) {
147     LOG(itsPos << " enter cgp finishRound" << std::endl);
148 
149     setCardPixmap(itsOldPixmap);
150     itsAI->finishRound(theRound, whoStarted);
151 
152     LOG(itsPos << " exit cgp finishRound" << std::endl);
153 }
154 
allPass()155 void ComputerGuiPlayer::allPass() {
156     setCardPixmap(itsOldPixmap);
157     setMarker(NULL);
158     itsAI->allPass();
159 }
160 
discard(Card & newCard)161 Card ComputerGuiPlayer::discard(Card& newCard) {
162     return itsAI->discard(newCard);
163 }
164 
finishDeal(int NSPoints,int EWPoints)165 void ComputerGuiPlayer::finishDeal(int NSPoints, int EWPoints) {
166     itsAI->finishDeal(NSPoints, EWPoints);
167     setBidSuitPixmap(NULL);
168     setBidCallPixmap(NULL);
169 }
170