kreversigame.h 2.04 KB
Newer Older
1 2 3 4 5
#ifndef KREVERSI_GAME_H
#define KREVERSI_GAME_H

#include <QObject>

Dmitry Suzdalev's avatar
Dmitry Suzdalev committed
6 7 8
#include "commondefs.h"

class KReversiBoard;
9 10 11 12 13 14 15 16 17 18

/**
 *  KReversiGame incapsulates all of the game logic.
 *  It creates KReversiBoard and manages a chips on it.
 *  Whenever the board state changes it emits corresponding signals.
 *  FIXME dimsuz: enumerate them briefly
 *  The idea is also to abstract from any graphic representation of the game process
 */
class KReversiGame : public QObject
{
19
    Q_OBJECT
20
public:
Dmitry Suzdalev's avatar
Dmitry Suzdalev committed
21
    KReversiGame();
22 23 24 25 26
    ~KReversiGame();
    /**
     *  @returns the board so the callers can examine its current state
     */
    const KReversiBoard& board() const;
Dmitry Suzdalev's avatar
Dmitry Suzdalev committed
27 28 29 30 31 32 33
    ChipColor currentPlayer() const { return m_curPlayer; }
    // NOTE: this is just a wrapper around KReversiBoard::playerScore
    // Maybe consider merging KReversiBoard into this class?
    // same applies to chipColorAt
    int playerScore( ChipColor player ) const;
    // NOTE: this is just a wrapper around KReversiBoard::playerScore
    ChipColor chipColorAt( int row, int col ) const;
34 35 36
    void putChipAt(int row, int col);
signals:
    void boardChanged();
37
private:
Dmitry Suzdalev's avatar
Dmitry Suzdalev committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    /**
     * This function will tell you if the move is possible.
     * That's why it was given such a name ;)
     */
    bool isMovePossible( const KReversiMove& move ) const; 
    enum Direction { Up, Down, Right, Left, UpLeft, UpRight, DownLeft, DownRight };
    /**
     *  Searches for "chunk" in direction dir for move.
     *  As my English-skills are somewhat limited, let me introduce 
     *  new terminology ;).
     *  I'll define a "chunk" of chips for color "C" as follows:
     *  (let "O" be the color of the opponent for "C")
     *  CO[O]C <-- this is a chunk
     *  where [O] is one or more opponent's pieces
     */
    bool hasChunk( Direction dir, const KReversiMove& move) const;
    /**
     *  Board itself
     */
57
    KReversiBoard *m_board;
58 59 60 61 62 63 64 65
    /**
     *  Color of the current player
     */
    ChipColor m_curPlayer;
    /**
     *  The color of the computer played chips
     */
    ChipColor m_computerColor;
66 67
};
#endif