File indexing completed on 2024-05-12 05:46:35

0001 /*******************************************************************
0002  *
0003  * Copyright 2013 Denis Kuplyakov <dener.kup@gmail.com>
0004  *
0005  * This file is part of the KDE project "KReversi"
0006  *
0007  * This program is free software; you can redistribute it and/or modify
0008  * it under the terms of the GNU General Public License as published by
0009  * the Free Software Foundation; either version 2, or (at your option)
0010  * any later version.
0011  *
0012  * This program is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0015  * GNU General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU General Public License
0018  * along with this program; see the file COPYING.  If not, write to
0019  * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021  *
0022  ********************************************************************/
0023 
0024 #ifndef KREVERSI_PLAYER_H
0025 #define KREVERSI_PLAYER_H
0026 
0027 #include "kreversigame.h"
0028 #include <QString>
0029 
0030 class KReversiGame;
0031 
0032 /**
0033  * Indicates current state of the player
0034  */
0035 enum KReversiPlayerState {
0036     /** Player is waiting for his move or smth else */
0037     WAITING,
0038     /** Player is thinking about his move */
0039     THINKING,
0040     /** Player state is unknown */
0041     UNKNOWN
0042 };
0043 /**
0044  * Represents abstract player. It is interface.
0045  */
0046 class KReversiPlayer: public QObject
0047 {
0048     Q_OBJECT
0049 public:
0050     /**
0051      * Construct player with specified @p color and @p name.
0052      * @param hintAllowed determines whether hints are allowed for player
0053      * @param undoAllowed determines whether undos are allowed for player
0054      */
0055     explicit KReversiPlayer(ChipColor color, const QString &name,
0056                             bool hintAllowed, bool undoAllowed);
0057 
0058     /**
0059      *  Used to get player color
0060      *  @return color of player
0061      */
0062     ChipColor getColor() const;
0063 
0064     /**
0065      *  Used to get player's name
0066      *  @return player's name
0067      */
0068     QString getName() const;
0069 
0070     /**
0071      *  @return is hint allowed for player or not
0072      */
0073     bool isHintAllowed() const;
0074 
0075     /**
0076      *  KReversiGame triggers it to to increase used hints count
0077      */
0078     void hintUsed();
0079 
0080     /**
0081      *  @return how many times player has used hints
0082      */
0083     int getHintsCount();
0084 
0085     /**
0086      *  @return is undo allowed for player
0087      */
0088     bool isUndoAllowed() const;
0089 
0090     /**
0091      *  KReversiGame triggers it to to increase used undos count
0092      */
0093     void undoUsed();
0094 
0095     /**
0096      *  @return how many times player has used undo
0097      */
0098     int getUndoCount();
0099 
0100 public Q_SLOTS:
0101     /**
0102      *  Triggered by KReversiGame before game starts
0103      *  Implementation should assign @p game to m_game
0104      */
0105     virtual void prepare(KReversiGame* game) = 0;
0106 
0107     /**
0108      *  It triggered from KReversiGame.
0109      *  Means that player should start think about his move.
0110      */
0111     virtual void takeTurn() = 0;
0112 
0113     /**
0114      *  It triggered from KReversiGame.
0115      *  Means that player can't do move and skips it.
0116      */
0117     virtual void skipTurn() = 0;
0118 
0119     /**
0120      *  Triggered by KReversiGame to notify player that game is over.
0121      */
0122     virtual void gameOver() = 0;
0123 
0124 Q_SIGNALS:
0125     /**
0126      *  Player emit it when want to notify about his move
0127      */
0128     void makeMove(KReversiMove);
0129 
0130     /**
0131      * Player emit it after he has prepared after getting prepare command
0132      */
0133     void ready();
0134 
0135 protected:
0136     /**
0137      *  Game which player is playing
0138      */
0139     KReversiGame *m_game;
0140 
0141     /**
0142      *  Is player thinking or waiting
0143      */
0144     KReversiPlayerState m_state;
0145 
0146     /**
0147      *  Player's chip color
0148      */
0149     ChipColor m_color;
0150 
0151     /**
0152      *  Player's name to be shown at UI
0153      */
0154     QString m_name;
0155 
0156     /**
0157      *  Are hints enabled for player
0158      */
0159     bool m_hintAllowed;
0160 
0161     /**
0162      *  How many times player has used hint
0163      */
0164     int m_hintCount;
0165 
0166     /**
0167      *  Can player request undo or not
0168      */
0169     bool m_undoAllowed;
0170 
0171     /**
0172      *  How many times player has used undo
0173      */
0174     int m_undoCount;
0175 };
0176 
0177 #endif // KREVERSIPLAYER_H