00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00043 template <class T>
00044 class Matrix: public vector<vector<T> >
00045 {
00046 public:
00047
00048 Matrix(int iSize1, int iSize2, const T &iValue)
00049 {
00050 resize(iSize1, vector<T>(iSize2, iValue));
00051 }
00052
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
00068
00069
00070
00071
00072
00073
00074
00075
00076
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
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
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
00151
00152
00153
00154
00155