1 | /******************************************************************* |
2 | * |
3 | * Copyright 2006 Dmitry Suzdalev <dimsuz@gmail.com> |
4 | * Copyright 2013 Denis Kuplyakov <dener.kup@gmail.com> |
5 | * |
6 | * This file is part of the KDE project "KReversi" |
7 | * |
8 | * KReversi is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the Free Software Foundation; either version 2, or (at your option) |
11 | * any later version. |
12 | * |
13 | * KReversi is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with KReversi; see the file COPYING. If not, write to |
20 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
21 | * Boston, MA 02110-1301, USA. |
22 | * |
23 | ********************************************************************/ |
24 | #ifndef COMMONDEFS_H |
25 | #define COMMONDEFS_H |
26 | |
27 | #include <QString> |
28 | #include <KgDifficulty> |
29 | |
30 | #include <preferences.h> |
31 | |
32 | /** |
33 | * Used to indicate chip's state. |
34 | */ |
35 | enum ChipColor { |
36 | /** White state */ |
37 | White = 0, |
38 | /** Black state */ |
39 | Black = 1, |
40 | /** No chip (empty cell) */ |
41 | NoColor = 2 |
42 | }; |
43 | |
44 | /** |
45 | * Represents position on board. |
46 | */ |
47 | struct KReversiPos { |
48 | KReversiPos(int r = -1, int c = -1) |
49 | : row(r), col(c) { } |
50 | |
51 | int row; |
52 | int col; |
53 | |
54 | bool isValid() const { |
55 | return (row >= 0 && col >= 0 && row < 8 && col < 8); |
56 | } |
57 | }; |
58 | |
59 | /** |
60 | * Represents move of player. |
61 | * It is KReversiPos + ChipColor |
62 | */ |
63 | struct KReversiMove: public KReversiPos { |
64 | KReversiMove(ChipColor col = NoColor, int r = -1, int c = -1) |
65 | : KReversiPos(r, c), color(col) { } |
66 | |
67 | KReversiMove(ChipColor col, const KReversiPos &pos) |
68 | : KReversiPos(pos), color(col) { } |
69 | |
70 | ChipColor color; |
71 | |
72 | bool isValid() const { |
73 | return (color != NoColor |
74 | && row >= 0 && col >= 0 |
75 | && row < 8 && col < 8); |
76 | } |
77 | }; |
78 | |
79 | typedef QList<KReversiMove> MoveList; |
80 | |
81 | /** |
82 | * Indicates current color setting of user |
83 | */ |
84 | enum ChipsPrefix { |
85 | /** Show Black and White chips */ |
86 | BlackWhite = 0, |
87 | /** Show Red and Blue chips */ |
88 | Colored = 1 |
89 | }; |
90 | |
91 | namespace Utils |
92 | { |
93 | /** |
94 | * Gives appropriate prefix-string by @p prefix |
95 | * @return @c "chip_bw" for @c BlackWhite |
96 | * @c "chip_color" for @c Colored |
97 | */ |
98 | QString chipPrefixToString(ChipsPrefix prefix); |
99 | /** |
100 | * Return opposite color for @p color |
101 | * @return @c Black for @c White |
102 | * @c White for @c Black |
103 | * @c NoColor for @c NoColor |
104 | */ |
105 | ChipColor opponentColorFor(ChipColor color); |
106 | /** |
107 | * @return Human-readable string representing @p color |
108 | */ |
109 | QString colorToString(const ChipColor &color); |
110 | /** |
111 | * @return Human-readable string representing @p move |
112 | */ |
113 | QString moveToString(const KReversiMove& move); |
114 | /** |
115 | * @return Index of current difficulty level in increasing order |
116 | */ |
117 | int difficultyLevelToInt(); |
118 | /** |
119 | * @return Difficulty level that in @p skill place in increasing order among |
120 | * all difficulty levels |
121 | */ |
122 | const KgDifficultyLevel *intToDifficultyLevel(int skill); |
123 | } |
124 | |
125 | |
126 | #endif |
127 | |