/[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.21 by ipkiss, Sat Nov 5 23:22:42 2005 UTC revision 1.22 by ipkiss, Sun Nov 6 01:05:06 2005 UTC
# Line 60  Game::~Game() Line 60  Game::~Game()
60  }  }
61    
62    
63  const Player& Game::getPlayer(int num) const  const Player& Game::getPlayer(int iNum) const
64  {  {
65      ASSERT(0 <= num && num < (int)m_players.size(), "Wrong player number");      ASSERT(0 <= iNum && iNum < (int)m_players.size(), "Wrong player number");
66      return *(m_players[num]);      return *(m_players[iNum]);
67    }
68    
69    
70    const Turn& Game::getTurn(int iNum) const
71    {
72        ASSERT(0 <= iNum && iNum < (int)m_history.size(), "Wrong turn number");
73        return *(m_history[iNum]);
74  }  }
75    
76    
# Line 272  Game * Game::load(FILE *fin, const Dicti Line 279  Game * Game::load(FILE *fin, const Dicti
279          // the game was saved while a human was to play.          // the game was saved while a human was to play.
280          for (int i = 0; i < pGame->getNPlayers(); i++)          for (int i = 0; i < pGame->getNPlayers(); i++)
281          {          {
282              if (pGame->m_players[i]->isHuman())              if (pGame->getPlayer(i).isHuman())
283              {              {
284                  pGame->m_currPlayer = i;                  pGame->m_currPlayer = i;
285                  break;                  break;
# Line 292  void Game::save(ostream &out) const Line 299  void Game::save(ostream &out) const
299      for (int i = 0; i < getNPlayers(); i++)      for (int i = 0; i < getNPlayers(); i++)
300      {      {
301          out << "Player " << i << ": ";          out << "Player " << i << ": ";
302          if (m_players[i]->isHuman())          if (getPlayer(i).isHuman())
303              out << "Human" << endl;              out << "Human" << endl;
304          else          else
305              out << "Computer" << endl;              out << "Computer" << endl;
# Line 323  void Game::save(ostream &out) const Line 330  void Game::save(ostream &out) const
330      out << endl;      out << endl;
331      for (int i = 0; i < getNPlayers(); i++)      for (int i = 0; i < getNPlayers(); i++)
332      {      {
333          string rack = m_players[i]->getCurrentRack().toString();          string rack = getPlayer(i).getCurrentRack().toString();
334          out << "Rack " << i << ": " << rack << endl;          out << "Rack " << i << ": " << rack << endl;
335      }      }
336  }  }
# Line 341  int Game::helperPlayRound(const Round &i Line 348  int Game::helperPlayRound(const Round &i
348    
349      // History of the game      // History of the game
350      m_history.push_back(new Turn(m_history.size(), m_currPlayer,      m_history.push_back(new Turn(m_history.size(), m_currPlayer,
351                                   m_players[m_currPlayer]->getLastRack(),                                   getPlayer(m_currPlayer).getLastRack(),
352                                   iRound));                                   iRound));
353    
354      m_points += iRound.getPoints();      m_points += iRound.getPoints();
# Line 373  int Game::helperPlayRound(const Round &i Line 380  int Game::helperPlayRound(const Round &i
380                  // There is a big design problem here, but i am unsure what is                  // There is a big design problem here, but i am unsure what is
381                  // the best way to fix it.                  // the best way to fix it.
382                  vector<Tile> tiles;                  vector<Tile> tiles;
383                  m_players[m_currPlayer]->getCurrentRack().getAllTiles(tiles);                  getPlayer(m_currPlayer).getCurrentRack().getAllTiles(tiles);
384                  for (unsigned int j = 0; j < tiles.size(); j++)                  for (unsigned int j = 0; j < tiles.size(); j++)
385                  {                  {
386                      bag.replaceTile(tiles[j]);                      bag.replaceTile(tiles[j]);
387                  }                  }
388                  m_players[m_currPlayer]->getLastRack().getAllTiles(tiles);                  getPlayer(m_currPlayer).getLastRack().getAllTiles(tiles);
389                  for (unsigned int j = 0; j < tiles.size(); j++)                  for (unsigned int j = 0; j < tiles.size(); j++)
390                  {                  {
391                      bag.takeTile(tiles[j]);                      bag.takeTile(tiles[j]);
# Line 473  void Game::realBag(Bag &ioBag) const Line 480  void Game::realBag(Bag &ioBag) const
480          /* In freegame mode, replace the letters from all the racks */          /* In freegame mode, replace the letters from all the racks */
481          for (int i = 0; i < getNPlayers(); i++)          for (int i = 0; i < getNPlayers(); i++)
482          {          {
483              m_players[i]->getCurrentRack().getAllTiles(tiles);              getPlayer(i).getCurrentRack().getAllTiles(tiles);
484              for (unsigned int j = 0; j < tiles.size(); j++)              for (unsigned int j = 0; j < tiles.size(); j++)
485              {              {
486                  ioBag.takeTile(tiles[j]);                  ioBag.takeTile(tiles[j]);
# Line 484  void Game::realBag(Bag &ioBag) const Line 491  void Game::realBag(Bag &ioBag) const
491      {      {
492          /* In training or duplicate mode, replace the rack of the current          /* In training or duplicate mode, replace the rack of the current
493           * player only */           * player only */
494          m_players[m_currPlayer]->getCurrentRack().getAllTiles(tiles);          getPlayer(m_currPlayer).getCurrentRack().getAllTiles(tiles);
495          for (unsigned int j = 0; j < tiles.size(); j++)          for (unsigned int j = 0; j < tiles.size(); j++)
496          {          {
497              ioBag.takeTile(tiles[j]);              ioBag.takeTile(tiles[j]);
# Line 513  int Game::helperSetRackRandom(int p, boo Line 520  int Game::helperSetRackRandom(int p, boo
520      int nold, min;      int nold, min;
521    
522      // Make a copy of the player's rack      // Make a copy of the player's rack
523      PlayedRack pld = m_players[p]->getCurrentRack();      PlayedRack pld = getPlayer(p).getCurrentRack();
524      nold = pld.nOld();      nold = pld.nOld();
525    
526      // Create a copy of the bag in which we can do everything we want,      // Create a copy of the bag in which we can do everything we want,
# Line 651  int Game::helperSetRackManual(int p, boo Line 658  int Game::helperSetRackManual(int p, boo
658      unsigned int i;      unsigned int i;
659      int min;      int min;
660    
661      PlayedRack pld = m_players[p]->getCurrentRack();      PlayedRack pld = getPlayer(p).getCurrentRack();
662      pld.reset();      pld.reset();
663    
664      if (iLetters.size() == 0)      if (iLetters.size() == 0)
# Line 711  int Game::helperSetRackManual(int p, boo Line 718  int Game::helperSetRackManual(int p, boo
718    
719  string Game::getPlayedRack(int num) const  string Game::getPlayedRack(int num) const
720  {  {
721      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");      return getTurn(num).getPlayedRack().toString();
     return m_history[num]->getPlayedRack().toString();  
722  }  }
723    
724    
725  string Game::getPlayedWord(int num) const  string Game::getPlayedWord(int num) const
726  {  {
     ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");  
727      char c;      char c;
728      string s;      string s;
729      const Round &r = m_history[num]->getRound();      const Round &r = getTurn(num).getRound();
730      for (int i = 0; i < r.getWordLen(); i++)      for (int i = 0; i < r.getWordLen(); i++)
731      {      {
732          c = r.getTile(i).toChar();          c = r.getTile(i).toChar();
# Line 735  string Game::getPlayedWord(int num) cons Line 740  string Game::getPlayedWord(int num) cons
740    
741  string Game::getPlayedCoords(int num) const  string Game::getPlayedCoords(int num) const
742  {  {
743      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");      return getTurn(num).getRound().getCoord().toString();
     return m_history[num]->getRound().getCoord().toString();  
744  }  }
745    
746    
747  int Game::getPlayedPoints(int num) const  int Game::getPlayedPoints(int num) const
748  {  {
749      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");      return getTurn(num).getRound().getPoints();
     return m_history[num]->getRound().getPoints();  
750  }  }
751    
752    
753  int Game::getPlayedBonus(int num) const  int Game::getPlayedBonus(int num) const
754  {  {
755      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");      return getTurn(num).getRound().getBonus();
     return m_history[num]->getRound().getBonus();  
756  }  }
757    
758    
759  int Game::getPlayedPlayer(int num) const  int Game::getPlayedPlayer(int num) const
760  {  {
761      ASSERT(0 <= num && num < getNTurns(), "Wrong turn number");      return getTurn(num).getPlayer();
     return m_history[num]->getPlayer();  
762  }  }
763    
764  /*********************************************************  /*********************************************************
# Line 773  int Game::getNHumanPlayers() const Line 774  int Game::getNHumanPlayers() const
774  {  {
775      int count = 0;      int count = 0;
776      for (int i = 0; i < getNPlayers(); i++)      for (int i = 0; i < getNPlayers(); i++)
777          count += (m_players[i]->isHuman() ? 1 : 0);          count += (getPlayer(i).isHuman() ? 1 : 0);
778      return count;      return count;
779  }  }
780    

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

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