File indexing completed on 2024-04-21 04:02:36
0001 /* 0002 SPDX-FileCopyrightText: 1997 Mathias Mueller <in5y158@public.uni-hamburg.de> 0003 SPDX-FileCopyrightText: 2006-2007 Mauricio Piacentini <mauricio@tabuleiro.com> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef GAMEDATA_H 0009 #define GAMEDATA_H 0010 0011 // Qt 0012 #include <QList> 0013 #include <QRandomGenerator> 0014 0015 // KMahjongg 0016 #include "kmtypes.h" 0017 0018 class BoardLayout; 0019 0020 /** 0021 * @author Mauricio Piacentini <mauricio@tabuleiro.com> */ 0022 class GameData 0023 { 0024 public: 0025 explicit GameData(BoardLayout * boardlayout); 0026 ~GameData(); 0027 0028 void putTile(short e, short y, short x, UCHAR f); 0029 0030 bool tilePresent(int z, int y, int x) const; 0031 0032 UCHAR BoardData(short z, short y, short x) const; 0033 0034 UCHAR HighlightData(short z, short y, short x) const; 0035 0036 POSITION & MoveListData(short i); 0037 0038 void setMoveListData(short i, POSITION & value); 0039 0040 char * getMaskBytes() 0041 { 0042 return m_mask.data(); 0043 } 0044 0045 bool saveToStream(QDataStream & out) const; 0046 bool loadFromStream(QDataStream & in); 0047 0048 void generatePositionDepends(); 0049 void generateTilePositions(); 0050 0051 bool generateStartPosition2(); 0052 0053 bool findMove(POSITION & posA, POSITION & posB); 0054 int moveCount(); 0055 short findAllMatchingTiles(POSITION & posA); 0056 void setRemovedTilePair(POSITION & a, POSITION & b); 0057 void clearRemovedTilePair(POSITION & a, POSITION & b); 0058 bool isMatchingTile(POSITION & pos1, POSITION & pos2) const; 0059 void shuffle(); 0060 POSITION & getFromPosTable(int index) 0061 { 0062 return m_posTable[index]; 0063 } 0064 0065 int m_allowUndo; 0066 int m_allowRedo; 0067 0068 USHORT m_tileNum; 0069 USHORT m_maxTileNum; 0070 0071 //Board Layout dimensions 0072 short m_width; 0073 short m_height; 0074 short m_depth; 0075 short m_maxTiles; 0076 0077 QRandomGenerator random; 0078 0079 private: 0080 void putTile(POSITION & pos) 0081 { 0082 putTile(pos.z, pos.y, pos.x, pos.f); 0083 } 0084 void setBoardData(short z, short y, short x, UCHAR value); 0085 UCHAR MaskData(short z, short y, short x) const; 0086 0087 int tileAt(int x, int y, int z) const; 0088 bool generateSolvableGame(); 0089 bool onlyFreeInLine(int position) const; 0090 int selectPosition(int lastPosition); 0091 void placeTile(int position, int tile); 0092 void updateDepend(int position); 0093 0094 //other generation bits 0095 void randomiseFaces(); 0096 void getFaces(POSITION & a, POSITION & b); 0097 0098 int m_tilesUsed; 0099 0100 UCHAR m_tilePair[144]; 0101 0102 // storage to keep track of removed tiles 0103 unsigned char m_removedCharacter[9]; 0104 unsigned char m_removedBamboo[9]; 0105 unsigned char m_removedRod[9]; 0106 unsigned char m_removedDragon[3]; 0107 unsigned char m_removedWind[9]; 0108 unsigned char m_removedFlower[4]; 0109 unsigned char m_removedSeason[4]; 0110 0111 // new bits for new game generation, with solvability. Scratch storage 0112 int m_numTilesToGenerate; 0113 0114 QByteArray m_board; 0115 QByteArray m_mask; 0116 QByteArray m_highlight; 0117 QList<POSITION> m_moveList; 0118 0119 QList<POSITION> m_tilePositions; 0120 QList<DEPENDENCY> m_positionDepends; 0121 0122 //PosTable, scratch storage used for highlighting matching tiles 0123 QList<POSITION> m_posTable; 0124 }; 0125 0126 #endif // GAMEDATA_H