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

Diff of /eliot/game/game.cpp

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

revision 1.20 by ipkiss, Sat Nov 5 15:48:59 2005 UTC revision 1.21 by ipkiss, Sat Nov 5 23:22:42 2005 UTC
# Line 29  Line 29 
29  #include "ai_percent.h"  #include "ai_percent.h"
30  #include "game.h"  #include "game.h"
31  #include "game_factory.h"  #include "game_factory.h"
32    #include "turn.h"
33    
34  #include "debug.h"  #include "debug.h"
35    
# Line 48  Game::Game(const Dictionary &iDic): Line 49  Game::Game(const Dictionary &iDic):
49    
50  Game::~Game()  Game::~Game()
51  {  {
52      for (unsigned int i = 0; i < m_roundHistory.size(); i++)      for (unsigned int i = 0; i < m_history.size(); i++)
53      {      {
54          delete m_roundHistory[i];          delete m_history[i];
     }  
     for (unsigned int i = 0; i < m_rackHistory.size(); i++)  
     {  
         delete m_rackHistory[i];  
55      }      }
56      for (int i = 0; i < getNPlayers(); i++)      for (int i = 0; i < getNPlayers(); i++)
57      {      {
# Line 308  void Game::save(ostream &out) const Line 305  void Game::save(ostream &out) const
305      out << decal << "===|==========|=================|=====|=====|===|======" << endl;      out << decal << "===|==========|=================|=====|=====|===|======" << endl;
306    
307      // Print the game itself      // Print the game itself
308      for (int i = 0; i < getNRounds(); i++)      for (int i = 0; i < getNTurns(); i++)
309      {      {
310          string word = getPlayedWord(i);          string word = getPlayedWord(i);
311          string coord = getPlayedCoords(i);          string coord = getPlayedCoords(i);
# Line 343  int Game::helperPlayRound(const Round &i Line 340  int Game::helperPlayRound(const Round &i
340       */       */
341    
342      // History of the game      // History of the game
343      m_roundHistory.push_back(new Round(iRound));      m_history.push_back(new Turn(m_history.size(), m_currPlayer,
344      m_rackHistory.push_back(new PlayedRack(m_players[m_currPlayer]->getLastRack()));                                   m_players[m_currPlayer]->getLastRack(),
345      m_playerHistory.push_back(m_currPlayer);                                   iRound));
346    
347      m_points += iRound.getPoints();      m_points += iRound.getPoints();
348    
# Line 426  int Game::back(int n) Line 423  int Game::back(int n)
423    
424      for (i = 0; i < n; i++)      for (i = 0; i < n; i++)
425      {      {
426          if (m_roundHistory.size())          if (m_history.size())
427          {          {
428              prevPlayer();              prevPlayer();
429              player = m_players[m_currPlayer];              player = m_players[m_currPlayer];
430              const Round &lastround = *m_roundHistory.back();              const Round &lastround = m_history.back()->getRound();
431    
432              /* Remove the points of this round */              /* Remove the points of this round */
433              player->addPoints(- lastround.getPoints());              player->addPoints(- lastround.getPoints());
# Line 449  int Game::back(int n) Line 446  int Game::back(int n)
446                  }                  }
447              }              }
448              delete &lastround;              delete &lastround;
449              m_roundHistory.pop_back();              m_history.pop_back();
             m_playerHistory.pop_back();  
450          }          }
451          else          else
452          {          {
# Line 567  int Game::helperSetRackRandom(int p, boo Line 563  int Game::helperSetRackRandom(int p, boo
563          }          }
564          // 2 vowels and 2 consonants are needed up to the 15th turn          // 2 vowels and 2 consonants are needed up to the 15th turn
565          if (bag.nVowels() > 1 && bag.nConsonants() > 1          if (bag.nVowels() > 1 && bag.nConsonants() > 1
566              && getNRounds() < 15)              && getNTurns() < 15)
567              min = 2;              min = 2;
568          else          else
569              min = 1;              min = 1;
# Line 697  int Game::helperSetRackManual(int p, boo Line 693  int Game::helperSetRackManual(int p, boo
693      if (iCheck)      if (iCheck)
694      {      {
695          if (m_bag.nVowels() > 1 && m_bag.nConsonants() > 1          if (m_bag.nVowels() > 1 && m_bag.nConsonants() > 1
696              && getNRounds() < 15)              && getNTurns() < 15)
697              min = 2;              min = 2;
698          else          else
699              min = 1;              min = 1;
# Line 715  int Game::helperSetRackManual(int p, boo Line 711  int Game::helperSetRackManual(int p, boo
711    
712  string Game::getPlayedRack(int num) const  string Game::getPlayedRack(int num) const
713  {  {
714      ASSERT(0 <= num && num < getNRounds(), "Wrong turn number");      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");
715      return m_rackHistory[num]->toString();      return m_history[num]->getPlayedRack().toString();
716  }  }
717    
718    
719  string Game::getPlayedWord(int num) const  string Game::getPlayedWord(int num) const
720  {  {
721      ASSERT(0 <= num && num < getNRounds(), "Wrong turn number");      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");
722      char c;      char c;
723      string s;      string s;
724      const Round &r = *m_roundHistory[num];      const Round &r = m_history[num]->getRound();
725      for (int i = 0; i < r.getWordLen(); i++)      for (int i = 0; i < r.getWordLen(); i++)
726      {      {
727          c = r.getTile(i).toChar();          c = r.getTile(i).toChar();
# Line 739  string Game::getPlayedWord(int num) cons Line 735  string Game::getPlayedWord(int num) cons
735    
736  string Game::getPlayedCoords(int num) const  string Game::getPlayedCoords(int num) const
737  {  {
738      ASSERT(0 <= num && num < getNRounds(), "Wrong turn number");      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");
739      return m_roundHistory[num]->getCoord().toString();      return m_history[num]->getRound().getCoord().toString();
740  }  }
741    
742    
743  int Game::getPlayedPoints(int num) const  int Game::getPlayedPoints(int num) const
744  {  {
745      ASSERT(0 <= num && num < getNRounds(), "Wrong turn number");      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");
746      return m_roundHistory[num]->getPoints();      return m_history[num]->getRound().getPoints();
747  }  }
748    
749    
750  int Game::getPlayedBonus(int num) const  int Game::getPlayedBonus(int num) const
751  {  {
752      ASSERT(0 <= num && num < getNRounds(), "Wrong turn number");      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");
753      return m_roundHistory[num]->getBonus();      return m_history[num]->getRound().getBonus();
754  }  }
755    
756    
757  int Game::getPlayedPlayer(int num) const  int Game::getPlayedPlayer(int num) const
758  {  {
759      ASSERT(0 <= num && num < getNRounds(), "Wrong turn number");      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");
760      return m_playerHistory[num];      return m_history[num]->getPlayer();
761  }  }
762    
763  /*********************************************************  /*********************************************************
# Line 870  int Game::checkPlayedWord(const string & Line 866  int Game::checkPlayedWord(const string &
866    
867      /* Check the word position, compute its points,      /* Check the word position, compute its points,
868       * and specify the origin of each letter (board or rack) */       * and specify the origin of each letter (board or rack) */
869      res = m_board.checkRound(oRound, getNRounds() == 0);      res = m_board.checkRound(oRound, getNTurns() == 0);
870      if (res != 0)      if (res != 0)
871          return res + 4;          return res + 4;
872    

Legend:
Removed from v.1.20  
changed lines
  Added in v.1.21

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