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

Diff of /eliot/game/training.cpp

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

revision 1.8.2.2 by afrab, Sun Oct 23 18:38:18 2005 UTC revision 1.8.2.3 by ipkiss, Sun Oct 23 20:58:20 2005 UTC
# Line 18  Line 18 
18   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19   *****************************************************************************/   *****************************************************************************/
20    
 /* $Id$ */  
   
21  #include "dic.h"  #include "dic.h"
22  #include "tile.h"  #include "tile.h"
23  #include "rack.h"  #include "rack.h"
# Line 27  Line 25 
25  #include "pldrack.h"  #include "pldrack.h"
26  #include "player.h"  #include "player.h"
27  #include "training.h"  #include "training.h"
28    #include "turn.h"
29    
30  #include "debug.h"  #include "debug.h"
31    
# Line 42  Training::~Training() Line 41  Training::~Training()
41  }  }
42    
43    
44  int Training::play(int player, Round& round)  int Training::play(int player, Round& oRound)
45  {  {
46      gdebug("Training::play\n");      gdebug("Training::play\n");
47      int res = checkPlayedWord(round);      int res = checkPlayedWord(oRound);
48      if (res != 0)      if (res != 0)
49          {          {
50              gdebug("Training::play - error in checkPlayedWord (code %d)\n",res);              gdebug("Training::play - error in checkPlayedWord (code %d)\n",res);
51              return res;              return res;
52          }          }
53    
54      int player_num = 0;      int player_num = 0;
55      int turn_num = m_history.getSize();      int turn_num = m_history.getSize();
56      /* Update the board */      /* Update the board */
57      m_board.addRound(m_dic,round);      m_board.addRound(m_dic, oRound);
58      /* Update the game history */      /* Update the game history */
59      m_history.setCurrentRack(m_players[player_num]->getHistory().getCurrentRack());      m_history.setCurrentRack(m_players[player_num]->getHistory().getCurrentRack());
60      m_history.playRound(player_num,turn_num,round);      m_history.playRound(player_num,turn_num, oRound);
61      /* Update the rack and the score of the current player */      /* Update the rack and the score of the current player */
62      m_players[player_num]->playRound(turn_num,round);      m_players[player_num]->playRound(turn_num, oRound);
63      /* reset the search */      /* reset the search */
64      m_results.clear();      m_results.clear();
65      return 0;      return 0;
# Line 73  int Training::back() Line 72  int Training::back()
72      int res = 0;      int res = 0;
73      int player_num = 0;      int player_num = 0;
74      if (m_history.getSize() > 1)      if (m_history.getSize() > 1)
75          {      {
76              const PlayedRack current_rack = m_history.getCurrentRack();          const PlayedRack current_rack = m_history.getCurrentRack();
77              const Turn       last_turn = m_history.getPreviousTurn();          const Turn       last_turn = m_history.getPreviousTurn();
78    
79              /* remove the turn for the player */          /* remove the turn for the player */
80              ASSERT(0,"player history\n");          ASSERT(0,"player history\n");
81              // m_players[player_num]->getHistory().removeLastTurn();          // m_players[player_num]->getHistory().removeLastTurn();
82    
83              /* remove the turn for the game history */          /* remove the turn for the game history */
84              m_history.removeLastTurn();          m_history.removeLastTurn();
85              /* Remove the word from the board */          /* Remove the word from the board */
86              m_board.removeRound(m_dic, last_turn.getRound());          m_board.removeRound(m_dic, last_turn.getRound());
87              /* Put back the letter in the bag */          /* Put back the letter in the bag */
88              ASSERT(0,"put back tiles in bag\n");          ASSERT(0,"put back tiles in bag\n");
89  #if 0  #if 0
90              for (j = 0; j < lastround.getWordLen(); j++)          for (j = 0; j < lastround.getWordLen(); j++)
91            {
92                if (lastround.isPlayedFromRack(j))
93              {              {
94                  if (lastround.isPlayedFromRack(j))                  if (lastround.isJoker(j))
95                      {                      m_bag.replaceTile(Tile::Joker());
96                          if (lastround.isJoker(j))                  else
97                              m_bag.replaceTile(Tile::Joker());                      m_bag.replaceTile(lastround.getTile(j));
                         else  
                             m_bag.replaceTile(lastround.getTile(j));  
                     }  
98              }              }
 #endif  
99          }          }
100    #endif
101        }
102      else      else
103          {      {
104              res = 1;          res = 1;
105          }      }
106      return res;      return res;
107  }  }
108    
# Line 112  void Training::search() Line 111  void Training::search()
111  {  {
112      Rack rack;      Rack rack;
113      getCurrentPlayer().getCurrentRack().getRack(rack);      getCurrentPlayer().getCurrentRack().getRack(rack);
114      std::cerr << "Training::search() for " << rack.toString()      std::cerr << "Training::search() for " << rack.toString()
115                << " with history size "     << m_history.getSize() << std::endl;                << " with history size "     << m_history.getSize() << std::endl;
116      m_results.search(m_dic, m_board, rack, m_history.getSize() - 1);      m_results.search(m_dic, m_board, rack, m_history.getSize() - 1);
117      m_results.sort_by_points();      m_results.sort_by_points();
118  }  }
# Line 142  void Training::removeTestPlay() Line 141  void Training::removeTestPlay()
141  }  }
142    
143    
144  std::string Training::getTestPlayWord()  std::string Training::getTestPlayWord() const
145  {  {
146      return testRound.getWord();      return testRound.getWord();
147  }  }
148    
149    
150  int Training::setRack(PlayedRack::set_rack_mode mode, bool check, std::string rack)  int Training::setRack(PlayedRack::set_rack_mode mode, bool check, const std::string& rack)
151  {  {
152      return Game::setRack(0,mode,check,rack);      return Game::setRack(0, mode, check, rack);
153  }  }
154    
155    
156    
157  /// Local Variables:  /// Local Variables:
158  /// mode: hs-minor  /// mode: hs-minor
159  /// c-basic-offset: 4  /// c-basic-offset: 4

Legend:
Removed from v.1.8.2.2  
changed lines
  Added in v.1.8.2.3

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