From 4665fa176b8fdb6d8cfbab28fa710fff9e18b70b Mon Sep 17 00:00:00 2001 From: Antoine Fraboulet Date: Sun, 1 Jan 2006 19:49:35 +0000 Subject: [PATCH] - add comments and emacs mode --- game/ai_percent.cpp | 6 ++++++ game/ai_percent.h | 6 ++++++ game/ai_player.h | 6 ++++++ game/bag.cpp | 7 +++++++ game/bag.h | 7 +++++++ game/board.cpp | 6 ++++++ game/board.h | 27 +++++++++++++++------------ game/coord.cpp | 39 ++++++++++++++++++++++++++------------- game/coord.h | 12 +++++++++--- game/cross.cpp | 7 +++++++ game/cross.h | 7 +++++++ game/debug.h | 7 +++++++ game/duplicate.cpp | 6 ++++++ game/duplicate.h | 7 +++++++ game/freegame.cpp | 6 ++++++ game/freegame.h | 7 +++++++ game/game_factory.cpp | 7 +++++++ game/game_factory.h | 7 +++++++ game/history.cpp | 10 ++++++---- game/history.h | 28 +++++++++++----------------- game/player.cpp | 1 + game/player.h | 10 +++++++++- game/results.cpp | 1 + game/results.h | 1 + game/round.cpp | 4 +++- game/round.h | 11 +++++++++-- game/tile.cpp | 6 ++++++ game/tile.h | 7 +++++++ game/training.cpp | 42 +++++++++++++++++++++++++----------------- game/training.h | 9 ++++++++- game/turn.cpp | 10 ++++++---- game/turn.h | 3 ++- 32 files changed, 244 insertions(+), 76 deletions(-) diff --git a/game/ai_percent.cpp b/game/ai_percent.cpp index 10bb55b..b38e25a 100644 --- a/game/ai_percent.cpp +++ b/game/ai_percent.cpp @@ -65,3 +65,9 @@ vector AIPercent::getChangedLetters() const return vector(); } +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/ai_percent.h b/game/ai_percent.h index 8a2e682..35a10e6 100644 --- a/game/ai_percent.h +++ b/game/ai_percent.h @@ -62,3 +62,9 @@ private: #endif +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/ai_player.h b/game/ai_player.h index be7b01a..8efa452 100644 --- a/game/ai_player.h +++ b/game/ai_player.h @@ -89,3 +89,9 @@ protected: #endif +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/bag.cpp b/game/bag.cpp index c18e85f..263a9a1 100644 --- a/game/bag.cpp +++ b/game/bag.cpp @@ -136,3 +136,10 @@ void Bag::dumpAll() const } fprintf(stderr, "\n"); } + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/bag.h b/game/bag.h index 6549cc6..1d570db 100644 --- a/game/bag.h +++ b/game/bag.h @@ -73,3 +73,10 @@ private: }; #endif + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/board.cpp b/game/board.cpp index 9e7ee80..e140971 100644 --- a/game/board.cpp +++ b/game/board.cpp @@ -473,3 +473,9 @@ void Board::checkDouble() } #endif +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/board.h b/game/board.h index f66d5fd..6189806 100644 --- a/game/board.h +++ b/game/board.h @@ -90,31 +90,27 @@ public: void removeRound(const Dictionary &iDic, const Round &iRound); int checkRound(Round &iRound, bool iFirstTurn); - /************************* + /** * - * - *************************/ + */ void testRound(const Round &iRound); void removeTestRound(); char getTestChar(int iRow, int iCol) const; - /************************* - * + /** * board_search.c - *************************/ + */ void search(const Dictionary &iDic, const Rack &iRack, Results &oResults); void searchFirst(const Dictionary &iDic, const Rack &iRack, Results &oResults); - /************************* - * + /** * board_cross.c - *************************/ + */ void buildCross(const Dictionary &iDic); - /************************* + /** * - * - *************************/ + */ int getWordMultiplier(int iRow, int iCol) const; int getLetterMultiplier(int iRow, int iCol) const; @@ -150,3 +146,10 @@ private: }; #endif + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/coord.cpp b/game/coord.cpp index f0d0457..83c4d27 100644 --- a/game/coord.cpp +++ b/game/coord.cpp @@ -19,7 +19,7 @@ /** * \file coord.cpp - * \brief Eliot coordinate system + * \brief Board coordinate system * \author Antoine Fraboulet * \date 2005 */ @@ -85,26 +85,39 @@ void Coord::setFromString(const string &iStr) setRow(row); } -string Coord::toString() const +string Coord::toString(coord_mode_t mode) const { ASSERT(isValid(), "Invalid coordinates"); - string res; - char s[5]; - sprintf(s, "%d", m_col); - if (getDir() == HORIZONTAL) + char res[7]; + char srow[3]; + char scol[3]; + + sprintf(scol, "%d", m_col); + sprintf(srow, "%c", m_row + 'A' - 1); + + switch (mode) { - res = string(1, m_row + 'A' - 1) + s; + case COORD_MODE_COMPACT: + if (getDir() == HORIZONTAL) + sprintf(res,"%s%s",srow,scol); + else + sprintf(res,"%s%s",scol,srow); + break; + case COORD_MODE_LONG: + if (getDir() == HORIZONTAL) + sprintf(res,"%2s %2s",srow,scol); + else + sprintf(res,"%2s %2s",scol,srow); + break; } - else - { - res = s + string(1, m_row + 'A' - 1); - } - return res; + + return string(res); } - /// Local Variables: +/// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/coord.h b/game/coord.h index 0ea503f..888328e 100644 --- a/game/coord.h +++ b/game/coord.h @@ -19,7 +19,7 @@ /** * \file coord.h - * \brief Game coordinates system + * \brief Board coordinates system * \author Antoine Fraboulet * \date 2005 */ @@ -55,7 +55,12 @@ public: void swap(); void setFromString(const string &iStr); - string toString() const; + + typedef enum { + COORD_MODE_COMPACT, + COORD_MODE_LONG + } coord_mode_t; + string toString(coord_mode_t mode = COORD_MODE_COMPACT) const; private: Direction m_dir; @@ -65,8 +70,9 @@ private: #endif - /// Local Variables: +/// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/cross.cpp b/game/cross.cpp index 1529e61..976b482 100644 --- a/game/cross.cpp +++ b/game/cross.cpp @@ -62,3 +62,10 @@ bool Cross::operator==(const Cross &iOther) const else return false; } + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/cross.h b/game/cross.h index e1ff284..e104824 100644 --- a/game/cross.h +++ b/game/cross.h @@ -57,3 +57,10 @@ private: }; #endif + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/debug.h b/game/debug.h index 1fe4ad1..244d31e 100644 --- a/game/debug.h +++ b/game/debug.h @@ -48,3 +48,10 @@ #endif #endif + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/duplicate.cpp b/game/duplicate.cpp index 5136e86..e6d55fe 100644 --- a/game/duplicate.cpp +++ b/game/duplicate.cpp @@ -284,3 +284,9 @@ void Duplicate::nextHumanPlayer() m_hasPlayed[m_currPlayer]); } +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/duplicate.h b/game/duplicate.h index 8503226..5b80d44 100644 --- a/game/duplicate.h +++ b/game/duplicate.h @@ -82,3 +82,10 @@ private: }; #endif /* _DUPLICATE_H_ */ + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/freegame.cpp b/game/freegame.cpp index a86ba7a..d7503a3 100644 --- a/game/freegame.cpp +++ b/game/freegame.cpp @@ -254,3 +254,9 @@ int FreeGame::helperPass(const vector &iToChange, int n) return 0; } +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/freegame.h b/game/freegame.h index 1b849f7..dafa58d 100644 --- a/game/freegame.h +++ b/game/freegame.h @@ -64,3 +64,10 @@ private: }; #endif /* _FREEGAME_H_ */ + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/game_factory.cpp b/game/game_factory.cpp index d24a836..8558295 100644 --- a/game/game_factory.cpp +++ b/game/game_factory.cpp @@ -214,3 +214,10 @@ void GameFactory::printVersion() const << "Public License;\nsee the file named COPYING for details.\n"; } + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/game_factory.h b/game/game_factory.h index 414df0d..9f93fd6 100644 --- a/game/game_factory.h +++ b/game/game_factory.h @@ -93,3 +93,10 @@ private: }; #endif // _GAME_FACTORY_H_ + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/history.cpp b/game/history.cpp index 909f2ef..fabadb0 100644 --- a/game/history.cpp +++ b/game/history.cpp @@ -39,7 +39,7 @@ History::History() { - Turn* t = new Turn(); + Turn* t = new Turn (); m_history.clear(); m_history.push_back(t); } @@ -143,7 +143,7 @@ void History::removeLastTurn() delete t; } - // Now we have the previous played round in back() + // now we have the previous played round in back() Turn* t = m_history.back(); t->setNum(0); t->setPlayer(0); @@ -160,13 +160,13 @@ string History::toString() const string rs = ""; #ifdef DEBUG char buff[20]; - sprintf(buff, "%ld", m_history.size()); + sprintf(buff,"%d",m_history.size()); rs = "history size = " + string(buff) + "\n\n"; #endif for (i = 0; i < m_history.size(); i++) { Turn *t = m_history[i]; - rs += t->toString() + "\n"; + rs += t->toString() + string("\n"); } return rs; } @@ -177,6 +177,8 @@ string History::toString() const /// Local Variables: +/// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/history.h b/game/history.h index 3ef0b11..7b5e879 100644 --- a/game/history.h +++ b/game/history.h @@ -27,16 +27,10 @@ #ifndef _HISTORY_H #define _HISTORY_H -#include #include - -using std::string; -using std::vector; - -class Round; -class Turn; -class PlayedRack; - +#include "pldrack.h" +#include "round.h" +#include "turn.h" /** * History stores all the turns that have been played @@ -45,23 +39,23 @@ class PlayedRack; * - one for each of the players * * A History is never void (getSize() can be used as the is the current turn - * number for the complete game history). + * number for the complete game history). * * History starts at zero. * * The top of the history is an empty * Turn until it has been filled and game is up to a new round. - * - * getCurrentRack() can/should be used to store the current played rack. + * + * getCurrentRack() can/should be used to store the current played rack. * setCurrentRack must be called whenever the current played rack is * modified. - * + * * History owns the turns that it stores. Do not delete a turn referenced by History */ class History { -public: + public: History(); virtual ~History(); @@ -90,15 +84,15 @@ public: /// String handling string toString() const; -private: - vector m_history; + private: + vector < Turn* > m_history; }; #endif - /// Local Variables: /// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/player.cpp b/game/player.cpp index 6cca58e..4629ddf 100644 --- a/game/player.cpp +++ b/game/player.cpp @@ -97,4 +97,5 @@ const string Player::toString() const /// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/player.h b/game/player.h index fa2deaa..2e638e4 100644 --- a/game/player.h +++ b/game/player.h @@ -69,7 +69,7 @@ public: // A new rack is created with the remaining letters void endTurn(const Round &iRound, int iTurn); - const std::string toString() const; + const string toString() const; private: /// ID of the player @@ -89,6 +89,8 @@ private: class HumanPlayer: public Player { public: + string name; + HumanPlayer(int iId): Player(iId) {} virtual ~HumanPlayer() {} @@ -98,3 +100,9 @@ public: #endif +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/results.cpp b/game/results.cpp index 4563295..89a4b3e 100644 --- a/game/results.cpp +++ b/game/results.cpp @@ -84,4 +84,5 @@ void Results::sort_by_points() /// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/results.h b/game/results.h index 24c8e91..0f3d3ae 100644 --- a/game/results.h +++ b/game/results.h @@ -76,4 +76,5 @@ private: /// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/round.cpp b/game/round.cpp index edf4cf1..a147a7b 100644 --- a/game/round.cpp +++ b/game/round.cpp @@ -144,7 +144,7 @@ void Round::removeRightToRack(Tile c, bool iJoker) string Round::getWord() const { char c; - std::string s; + string s; for (int i = 0; i < getWordLen(); i++) { @@ -175,6 +175,8 @@ string Round::toString() const } /// Local Variables: +/// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/round.h b/game/round.h index de6e495..32a2520 100644 --- a/game/round.h +++ b/game/round.h @@ -81,8 +81,8 @@ public: *************************/ const Coord& getCoord() const { return m_coord; } Coord& accessCoord() { return m_coord; } - - std::string toString() const; + + string toString() const; private: vector m_word; @@ -93,3 +93,10 @@ private: }; #endif + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/tile.cpp b/game/tile.cpp index 7e55ddb..db99ee6 100644 --- a/game/tile.cpp +++ b/game/tile.cpp @@ -209,3 +209,9 @@ bool Tile::operator !=(const Tile &iOther) const return !(*this == iOther); } +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/tile.h b/game/tile.h index 32a4031..b06f916 100644 --- a/game/tile.h +++ b/game/tile.h @@ -73,3 +73,10 @@ private: }; #endif + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/training.cpp b/game/training.cpp index 6173bbd..6a760be 100644 --- a/game/training.cpp +++ b/game/training.cpp @@ -38,14 +38,20 @@ Training::~Training() { } -int Training::setRackRandom(int p, bool iCheck, set_rack_mode mode) + +int Training::setRackRandom(bool iCheck, set_rack_mode mode) { +#define MAX_RANDOM_TRY 5 + int res; + int try_number = 0; + int p = m_currPlayer; m_results.clear(); do { res = helperSetRackRandom(p, iCheck, mode); - } while (res == 2); + try_number ++; + } while (res == 2 && try_number < MAX_RANDOM_TRY); // 0 : ok // 1 : not enough tiles // 2 : check failed (number of voyels before round 15) @@ -64,9 +70,9 @@ int Training::setRackManual(bool iCheck, const string &iLetters) m_results.clear(); uLetters = iLetters; for(it = uLetters.begin(); it != uLetters.end(); it ++) - { - *it = toupper(*it); - } + { + *it = toupper(*it); + } res = helperSetRackManual(p, iCheck, uLetters); // 0 : ok // 1 : not enough tiles @@ -78,17 +84,17 @@ int Training::setRack(set_rack_mode iMode, bool iCheck, const string &iLetters) { int res = 0; switch(iMode) - { - case RACK_MANUAL: - res = setRackManual(iCheck, iLetters); - break; - case RACK_ALL: - res = setRackRandom(m_currPlayer, iCheck, iMode); - break; - case RACK_NEW: - res = setRackRandom(m_currPlayer, iCheck, iMode); - break; - } + { + case RACK_MANUAL: + res = setRackManual(iCheck, iLetters); + break; + case RACK_ALL: + res = setRackRandom(iCheck, iMode); + break; + case RACK_NEW: + res = setRackRandom(iCheck, iMode); + break; + } return res; } @@ -128,6 +134,7 @@ int Training::start() return 0; } + int Training::endTurn() { // Nothing to do? @@ -140,7 +147,7 @@ void Training::search() // Search for the current player Rack r; m_players[m_currPlayer]->getCurrentRack().getRack(r); -// debug("Training::search for %s\n",r.toString().c_str()); + debug("Training::search for %s\n",r.toString().c_str()); m_results.search(*m_dic, m_board, r, m_history.getSize()); } @@ -209,4 +216,5 @@ std::string Training::getTestPlayWord() const /// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/training.h b/game/training.h index 28efe0d..b2e1a7e 100644 --- a/game/training.h +++ b/game/training.h @@ -52,7 +52,7 @@ public: void search(); int playResult(int); - virtual int setRackRandom(int, bool, set_rack_mode); + int setRackRandom(bool, set_rack_mode); int setRackManual(bool iCheck, const string &iLetters); int setRack(set_rack_mode iMode, bool iCheck, const string &iLetters); @@ -87,3 +87,10 @@ private: }; #endif /* _TRAINING_H_ */ + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/turn.cpp b/game/turn.cpp index 79bf51d..293a60f 100644 --- a/game/turn.cpp +++ b/game/turn.cpp @@ -47,9 +47,10 @@ Turn::Turn(int iNum, int iPlayerId, #if 0 void Turn::operator=(const Turn &iOther) { - m_num = iOther.m_num; - m_pldrack = iOther.m_pldrack; - m_round = iOther.m_round; + m_num = iOther.m_num; + m_playerId = iOther.m_playerId; + m_pldrack = iOther.m_pldrack; + m_round = iOther.m_round; } #endif @@ -64,8 +65,9 @@ string Turn::toString(bool iShowExtraSigns) const return rs; } - /// Local Variables: +/// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: diff --git a/game/turn.h b/game/turn.h index 822faac..418ddbd 100644 --- a/game/turn.h +++ b/game/turn.h @@ -60,8 +60,9 @@ private: #endif - /// Local Variables: +/// mode: c++ /// mode: hs-minor /// c-basic-offset: 4 +/// indent-tabs-mode: nil /// End: