board.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 1999-2005 Eliot
00003  * Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
00004  *          Olivier Teuliere  <ipkiss@via.ecp.fr>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  *****************************************************************************/
00020 
00021 #ifndef _BOARD_H_
00022 #define _BOARD_H_
00023 
00024 #include "tile.h"
00025 #include "cross.h"
00026 #include <string>
00027 #include <vector>
00028 
00029 typedef struct _Dictionary*Dictionary;
00030 class Rack;
00031 class Round;
00032 class Results;
00033 
00034 using namespace std;
00035 
00036 #define BOARD_MIN 1
00037 #define BOARD_MAX 15
00038 #define BOARD_DIM 15
00039 #define BOARD_REALDIM (BOARD_DIM + 2)
00040 
00041 
00042 // Template matrix class for convenience.
00043 template <class T>
00044 class Matrix: public vector<vector<T> >
00045 {
00046 public:
00047     // Construct a matrix with an initial value
00048     Matrix(int iSize1, int iSize2, const T &iValue)
00049     {
00050         resize(iSize1, vector<T>(iSize2, iValue));
00051     }
00052     // Construct a square matrix with an initial value
00053     Matrix(int iSize, const T &iValue)
00054     {
00055         resize(iSize, vector<T>(iSize, iValue));
00056     }
00057 };
00058 
00059 
00060 class Board
00061 {
00062 public:
00063     Board();
00064     virtual ~Board() {}
00065 
00066     /*************************
00067      * Coordinates have to be BOARD_MIN <= int <= BOARD_MAX
00068      *
00069      * getChar returns an upper case letter for normal tiles and a
00070      * lower case letter for jokers.
00071      *
00072      * getCharAttr tells the attributes of the tile
00073      *   0 : normal played tile
00074      *   1 : joker tile
00075      *   2 : test tile for preview purpose
00076      * Attributes can be combined with the or (|) operator
00077      *************************/
00078 #define ATTR_NORMAL 0
00079 #define ATTR_JOKER  1
00080 #define ATTR_TEST   2
00081 
00082     char getChar    (int iRow, int iCol) const;
00083     int  getCharAttr(int iRow, int iCol) const;
00084 
00085     Tile getTile(int iRow, int iCol) const;
00086     bool isJoker(int iRow, int iCol) const;
00087     bool isVacant(int iRow, int iCol) const;
00088 
00089     void addRound(const Dictionary &iDic, const Round &iRound);
00090     void removeRound(const Dictionary &iDic, const Round &iRound);
00091     int checkRound(Round &iRound, bool iFirstTurn);
00092 
00093     /**
00094      *
00095      */
00096     void testRound(const Round &iRound);
00097     void removeTestRound();
00098     char getTestChar(int iRow, int iCol) const;
00099 
00100     /**
00101      * board_search.c
00102      */
00103     void search(const Dictionary &iDic, const Rack &iRack, Results &oResults);
00104     void searchFirst(const Dictionary &iDic, const Rack &iRack, Results &oResults);
00105 
00106     /**
00107      * board_cross.c
00108      */
00109     void buildCross(const Dictionary &iDic);
00110 
00111     /**
00112      *
00113      */
00114     int getWordMultiplier(int iRow, int iCol) const;
00115     int getLetterMultiplier(int iRow, int iCol) const;
00116 
00117 private:
00118 
00119     Matrix<Tile> m_tilesRow;
00120     Matrix<Tile> m_tilesCol;
00121 
00122     Matrix<bool> m_jokerRow;
00123     Matrix<bool> m_jokerCol;
00124 
00125     Matrix<Cross> m_crossRow;
00126     Matrix<Cross> m_crossCol;
00127 
00128     Matrix<int> m_pointRow;
00129     Matrix<int> m_pointCol;
00130 
00131     Matrix<char> m_testsRow;
00132 
00133     static const int m_tileMultipliers[BOARD_REALDIM][BOARD_REALDIM];
00134     static const int m_wordMultipliers[BOARD_REALDIM][BOARD_REALDIM];
00135 
00136     int checkRoundAux(Matrix<Tile> &iTilesMx,
00137                       Matrix<Cross> &iCrossMx,
00138                       Matrix<int> &iPointsMx,
00139                       Matrix<bool> &iJokerMx,
00140                       Round &iRound,
00141                       bool firstturn);
00142 #ifdef DEBUG
00143     void checkDouble();
00144 #endif
00145 
00146 };
00147 
00148 #endif
00149 
00150 /// Local Variables:
00151 /// mode: c++
00152 /// mode: hs-minor
00153 /// c-basic-offset: 4
00154 /// indent-tabs-mode: nil
00155 /// End:

Generated on Thu Dec 29 02:01:14 2005 for Eliot by  doxygen 1.4.5