/[eliot]/eliot/game/player.cpp
ViewVC logotype

Diff of /eliot/game/player.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by ipkiss, Sun Oct 23 14:53:43 2005 UTC revision 1.5.2.1 by afrab, Sun Oct 23 17:16:24 2005 UTC
# Line 1  Line 1 
1    <<<<<<< player.cpp
2    /* Copyright (C) 2004-2005 Eliot                                             */
3    /* Authors: Olivier Teuliere  <ipkiss@via.ecp.fr>                            */
4    /*                                                                           */
5    /* This file is part of Eliot.                                               */
6    /*                                                                           */
7    /* Eliot is free software; you can redistribute it and/or modify             */
8    /* it under the terms of the GNU General Public License as published by      */
9    /* the Free Software Foundation; either version 2 of the License, or         */
10    /* (at your option) any later version.                                       */
11    /*                                                                           */
12    /* Eliot is distributed in the hope that it will be useful,                  */
13    /* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
14    /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
15    /* GNU General Public License for more details.                              */
16    /*                                                                           */
17    /* You should have received a copy of the GNU General Public License         */
18    /* along with this program; if not, write to the Free Software               */
19    /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
20    
21    /* $Id$ */
22    
23    /**
24     *  \file   player.cpp
25     *  \brief  Eliot player class
26     *  \author Olivier Teuliere
27     *  \date   2005
28     */
29    =======
30  /*****************************************************************************  /*****************************************************************************
31   * Copyright (C) 2004-2005 Eliot   * Copyright (C) 2004-2005 Eliot
32   * Authors: Olivier Teuliere  <ipkiss@via.ecp.fr>   * Authors: Olivier Teuliere  <ipkiss@via.ecp.fr>
# Line 18  Line 47 
47   * along with this program; if not, write to the Free Software   * along with this program; if not, write to the Free Software
48   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
49   *****************************************************************************/   *****************************************************************************/
50    >>>>>>> 1.5
51    
52  #include "tile.h"  #include "tile.h"
53  #include "rack.h"  #include "rack.h"
54  #include "pldrack.h"  #include "pldrack.h"
55  #include "round.h"  #include "round.h"
56    #include "turn.h"
57  #include "results.h"  #include "results.h"
58  #include "board.h"  #include "board.h"
59  #include "player.h"  #include "player.h"
60    
61  #include "debug.h"  #include "debug.h"
62    
63  Player::Player():  /* ******************************************************** */
64      m_score(0)  /* ******************************************************** */
65  {  /* ******************************************************** */
66      // Start with an empty rack  
67      m_playedRacks.push_back(new PlayedRack());  Player::Player(int number)
68    {
69        m_num   = number;
70        m_score = 0;
71        m_name  = "eliot";
72  }  }
73    
   
74  Player::~Player()  Player::~Player()
75  {  {
     for (unsigned int i = 0; i < m_playedRacks.size(); i++)  
         delete m_playedRacks[i];  
     for (unsigned int i = 0; i < m_rounds.size(); i++)  
         delete m_rounds[i];  
76  }  }
77    
78    
79  const PlayedRack & Player::getCurrentRack() const  const PlayedRack Player::getCurrentRack() const
80  {  {
81      return *m_playedRacks.back();      return m_history.getCurrentRack();
82  }  }
83    
84    
85  void Player::setCurrentRack(const PlayedRack &iPld)  void Player::setCurrentRack(const PlayedRack &iPld)
86  {  {
87      *m_playedRacks.back() = iPld;      gdebug("Player::setCurrentRack\n");
88        m_history.setCurrentRack(iPld);
89  }  }
90    
91    
92  const PlayedRack & Player::getLastRack() const  const Turn Player::getPreviousTurn() const
93  {  {
94      return *m_playedRacks[m_playedRacks.size() - 2];      return m_history.getPreviousTurn();
95  }  }
96    
97    
98  const Round & Player::getLastRound() const  void Player::playRound(int iTurn, const Round &iRound)
99  {  {
100      return *m_rounds.back();      gdebug("Player::playRound\n");
101        m_history.playRound(m_num,iTurn,iRound);
102        addPoints(iRound.getPoints());
103  }  }
104    
105    
106  /*  void Player::removeLastTurn()
  * This function increments the number of racks, and fills the new rack  
  * with the unplayed tiles from the previous one.  
  * 03 sept 2000 : We have to sort the tiles according to the new rules  
  */  
 void Player::endTurn(const Round &iRound, int iTurn)  
107  {  {
108      m_turns.push_back(iTurn);      gdebug("Player::removeLastTurn\n");
109      m_rounds.push_back(new Round(iRound));      Round r  = m_history.getPreviousTurn().getRound();
110        m_score -= r.getPoints();
111        m_history.removeLastTurn();
112    }
113    
     Rack rack;  
     m_playedRacks.back()->getRack(rack);  
114    
115      /* We remove the played tiles from the rack */  void Player::addPoints(int s)
116      for (int i = 0; i < iRound.getWordLen(); i++)  {
117      {      gdebug("Player::addPoints\n");
118          if (iRound.isPlayedFromRack(i))      m_score += s;
         {  
             if (iRound.isJoker(i))  
                 rack.remove(Tile::Joker());  
             else  
                 rack.remove(iRound.getTile(i));  
         }  
     }  
   
     m_playedRacks.push_back(new PlayedRack());  
     /* Now m_playedRacks.back() is the newly created PlayedRack object */  
     m_playedRacks.back()->setOld(rack);  
119  }  }
120    
121    
122    int Player::getPoints() const
123    {
124        return m_score;
125    }
126    
127    
128    std::string
129    Player::toString()
130    {
131        std::string rs;
132        char sp[5];
133        sprintf(sp,"%d",m_score);
134        rs = m_history.toString() + std::string("\ntotal:\t") + sp + std::string("\n");
135        return rs;
136    }
137    
138    /* ******************************************************** */
139    /* ******************************************************** */
140    /* ******************************************************** */
141    
142    
143    /// Local Variables:
144    /// mode: hs-minor
145    /// c-basic-offset: 4
146    /// End:

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.5.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26