Debian Codegraph @

src/game_tree/matrix.h

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2009 by The qGo Project *
3 * *
4 * This file is part of qGo. *
5 * *
6 * qGo is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, see <http://www.gnu.org/licenses/> *
18 * or write to the Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
21
22
23 #ifndef MATRIX_H
24 #define MATRIX_H
25
26 #include "defines.h"
27
28 /*
29 * Marks used in editing a game
30 */
31 #define MARK_TERRITORY_VISITED 0x1000
32
33 //first nibble is for stone color/erase
34 #define MX_STONEDEAD 0x8000
35 #define MX_STONEEDIT 0x4000
36
37 #define MX_VISITED 0x2000
38
39 class Group;
40
41 struct ASCII_Import
42 {
43 char blackStone, whiteStone, starPoint, emptyPoint, hBorder, vBorder;
44 };
45
46 class Matrix
47 {
48 public:
49 Matrix(int s=DEFAULT_BOARD_SIZE);
50 Matrix(const Matrix &m, bool cleanup = false);
51 ~Matrix();
52 int getSize() const { return size; }
53 void insertStone(int x, int y, StoneColor c, bool fEdit = false);
54 StoneColor getStoneAt(int x, int y);
55 bool isStoneDead(int x, int y);
56 MarkType getMarkAt(int x, int y);
57 QString getFirstTextAvailable(MarkType t);
58
59 void insertMark(int x, int y, MarkType t);
60 void removeMark(int x, int y);
61 void setMarkText(int x, int y, const QString &txt);
62 const QString getMarkText(int x, int y);
63 void clearAllMarks();
64 void clearTerritoryMarks();
65 void absMatrix();
66 const QString saveMarks();
67 const QString saveEditedMoves(Matrix *parent=0);
68 const QString printMe(ASCII_Import *charset);
69
70 int checkStoneCaptures(StoneColor ourColor, int x, int y, std::vector<Group *> &visited) const;
71 void removeGroup(Group * g);
72
73 void toggleGroupAt( int x, int y );
74 void toggleStoneAt(int x, int y);
75 void markStoneDead(int x, int y);
76 void markGroupDead(int x, int y);
77 void markGroupAlive(int x, int y);
78 void toggleAreaAt( int x, int y );
79 void markAreaDead(int x, int y);
80 void markAreaAlive(int x, int y);
81 void markTerritory();
82 void count(int & terrBlack, int & terrWhite, int & deadBlack, int & deadWhite);
83
84 static const QString coordsToString(int x, int y)
85 { return QString(QChar(static_cast<const char>('a' + x))).append(QChar(static_cast<const char>('a' + y))); }
86
87 int makeMove(int x, int y, StoneColor c);
88 bool addHandicapStones(int handicap);
89
90 private:
91 int internalCoordsToKey(int i, int j) const { return i*size + j; }
92 int coordsToKey(int x, int y) const { return internalCoordsToKey(x-1,y-1); }
93 void keyToCoords(int key, int &x, int &y) const
94 { x = key / size; y = key - (x++)*size + 1; }
95
96 StoneColor getStoneAt(int key) const;
97 MarkType getMarkAt(int key) const;
98 void insertStone(int key, StoneColor c, bool fEdit = false);
99 Group* assembleGroup(int key, StoneColor c) const;
100 void toggleStoneAt(int key);
101
102 void checkNeighbour(int key, StoneColor color, Group *group, std::vector<int> * libertyList = NULL) const;
103 int countLiberties(Group *group, unsigned short mask = stoneBlack|stoneWhite);
104 Group* assembleAreaGroups(int key, StoneColor c);
105 // This function returns a list of keys of points adjacent to the point "key".
106 std::vector<int> getNeighbors(int key) const;
107 void floodTerritory(unsigned short mark, int key);
108
109 unsigned short * matrix;
110 const int size;
111 QHash<int,QString> markTexts;
112 };
113
114 #endif