File indexing completed on 2022-11-29 18:40:53

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 #include "commondefs.h"
0009 
0010 #include <KLocalizedString>
0011 
0012 
0013 static QString chipPrefixString[2] = {QStringLiteral("chip_bw"), QStringLiteral("chip_color")};
0014 
0015 QString Utils::chipPrefixToString(ChipsPrefix prefix) {
0016     return chipPrefixString[prefix];
0017 }
0018 
0019 ChipColor Utils::opponentColorFor(ChipColor color)
0020 {
0021     if (color == NoColor)
0022         return NoColor;
0023     else
0024         return (color == White ? Black : White);
0025 }
0026 
0027 
0028 QString Utils::colorToString(ChipColor color)
0029 {
0030     if (Preferences::useColoredChips())
0031         return (color == Black ? i18n("Blue") : i18n("Red"));
0032     return (color == Black ? i18n("Black") : i18n("White"));
0033 }
0034 
0035 QString Utils::moveToString(KReversiMove move)
0036 {
0037     QString moveString = colorToString(move.color);
0038 
0039     const char labelsHor[] = "ABCDEFGH";
0040     const char labelsVer[] = "12345678";
0041 
0042     moveString += QLatin1Char(' ');
0043     moveString += QLatin1Char(labelsHor[move.col]);
0044     moveString += QLatin1Char(labelsVer[move.row]);
0045 
0046     return moveString;
0047 }
0048 
0049 int Utils::difficultyLevelToInt()
0050 {
0051 
0052     for (int i = 0; i < Kg::difficulty()->levels().size(); i++)
0053         if (Kg::difficultyLevel()
0054                 == Kg::difficulty()->levels()[i]->standardLevel())
0055             return i;
0056 
0057     return -1;
0058 }
0059 
0060 const KgDifficultyLevel *Utils::intToDifficultyLevel(int skill)
0061 {
0062     return Kg::difficulty()->levels()[skill];
0063 }