File indexing completed on 2024-12-01 03:48:07

0001 /*
0002     SPDX-FileCopyrightText: 2006 Dmitry Suzdalev <dimsuz@gmail.com>
0003     SPDX-FileCopyrightText: 2013 Denis Kuplyakov <dener.kup@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef COMMONDEFS_H
0009 #define COMMONDEFS_H
0010 
0011 #include <QString>
0012 #include <KGameDifficulty>
0013 
0014 #include "preferences.h"
0015 
0016 /**
0017  * Used to indicate chip's state.
0018  */
0019 enum ChipColor {
0020     /** White state */
0021     White = 0,
0022     /** Black state */
0023     Black = 1,
0024     /** No chip (empty cell) */
0025     NoColor = 2
0026 };
0027 
0028 static const int nRows = 8;
0029 static const int nCols = 8;
0030 
0031 /**
0032  * Represents position on board.
0033  */
0034 struct KReversiPos {
0035     KReversiPos(int r = -1, int c = -1)
0036         : row(r), col(c) { }
0037 
0038     int row;
0039     int col;
0040 
0041     bool isValid() const {
0042         return (row >= 0 && col >= 0 && row < nRows && col < nCols);
0043     }
0044 };
0045 
0046 /**
0047  * Represents move of player.
0048  * It is KReversiPos + ChipColor
0049  */
0050 struct KReversiMove: public KReversiPos {
0051     KReversiMove(ChipColor col = NoColor, int r = -1, int c = -1)
0052         : KReversiPos(r, c), color(col) { }
0053 
0054     KReversiMove(ChipColor col, KReversiPos pos)
0055         : KReversiPos(pos), color(col) { }
0056 
0057     ChipColor color;
0058 
0059     bool isValid() const {
0060         return (color != NoColor
0061                 && row >= 0 && col >= 0
0062                 && row < nRows && col < nCols);
0063     }
0064 };
0065 
0066 typedef QList<KReversiMove> MoveList;
0067 
0068 /**
0069  * Indicates current color setting of user
0070  */
0071 enum ChipsPrefix {
0072     /** Show Black and White chips */
0073     BlackWhite = 0,
0074     /** Show Red and Blue chips */
0075     Colored = 1
0076 };
0077 
0078 namespace Utils
0079 {
0080 /**
0081  * Gives appropriate prefix-string by @p prefix
0082  * @return @c "chip_bw" for @c BlackWhite
0083  *         @c "chip_color" for @c Colored
0084  */
0085 QString chipPrefixToString(ChipsPrefix prefix);
0086 /**
0087  * Return opposite color for @p color
0088  * @return @c Black for @c White
0089  *         @c White for @c Black
0090  *         @c NoColor for @c NoColor
0091  */
0092 ChipColor opponentColorFor(ChipColor color);
0093 /**
0094  * @return Human-readable string representing @p color
0095  */
0096 QString colorToString(ChipColor color);
0097 /**
0098  * @return Human-readable string representing @p move
0099  */
0100 QString moveToString(KReversiMove move);
0101 /**
0102  * @return Index of current difficulty level in increasing order
0103  */
0104 int difficultyLevelToInt();
0105 /**
0106  * @return Difficulty level that in @p skill place in increasing order among
0107  *         all difficulty levels
0108  */
0109 const KGameDifficultyLevel *intToDifficultyLevel(int skill);
0110 }
0111 
0112 
0113 #endif