File indexing completed on 2025-03-23 06:53:53

0001 /*******************************************************************
0002  *
0003  * Copyright 2007  Aron Boström <c02ab@efd.lth.se>
0004  *
0005  * Bovo is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation; either version 2, or (at your option)
0008  * any later version.
0009  *
0010  * Bovo is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with Bovo; see the file COPYING.  If not, write to
0017  * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  *
0020  ********************************************************************/
0021 
0022 #ifndef BOVO_BOARD_H
0023 #define BOVO_BOARD_H
0024 
0025 #include "common.h"
0026 
0027 /** @file file declaring class Board */
0028 
0029 /** namespace for game engine */
0030 namespace bovo
0031 {
0032 
0033 class Coord;
0034 class Dimension;
0035 class Move;
0036 class Square;
0037 
0038 /**
0039  * A playing board
0040  *
0041  * This class might be somewhat missnamed. It doesn't just keep track of a
0042  * playing board. It also keeps track of a game history, if a player has won,
0043  * and in that case how it has won.
0044  *
0045  * Maybe this class should be renamed to Game, or a lot of its code moved into
0046  * gui/Game. On the other hand, maybe gui/Game should be moved into game,
0047  * making it game/Game. But as gui/Game is dependent on Qt4, which I have tried
0048  * to make sure ai/ and game/ isn't, it would break that design decision.
0049  *
0050  * However, maybe that is a stupid design decision which deserves to be broken.
0051  * After all, this is a KDE 4 project, right? Did we have in mind some other
0052  * project reusing our background code?
0053  *
0054  * @code
0055  * Dimension dimension(width, height);
0056  * Board board(dimension);
0057  * board.setPlayer(Coord(x, y), X);
0058  * @endcode
0059  */
0060 class Board
0061 {
0062 public:
0063     /**
0064      * @brief Constructs a Board with width and height
0065      * @description Constructs a Board object with a width and height specified
0066      * by a Dimension
0067      * @param dimension the Dimension containing the width and height
0068      */
0069     explicit Board(const Dimension &dimension);
0070 
0071     /**
0072      * @brief destructs this Board
0073      * @description destructs this Board object
0074      */
0075     ~Board();
0076 
0077     /**
0078      * @brief is a Coord empty or set?
0079      * @description tells whether a given Coord is marked as empty or
0080      * marked by a player
0081      * @param coord Coord to check
0082      * @return @c true if coord is empty, @c false otherwise
0083      */
0084     bool empty(const Coord &coord) const;
0085 
0086     /**
0087      * @brief is Game Over?
0088      * @description tells whether game is over (someone has won)
0089      * @return @c true if someone has won, @c false if game is still on
0090      */
0091     bool gameOver() const;
0092 
0093     /**
0094      * @brief is a coord in board?
0095      * @description tells whether a given coordinate is within the limits of
0096      * this playing board.
0097      * @param coord coordinate to verify
0098      * @return \c true if coord exist, \c false otherwise
0099      */
0100     bool ok(const Coord &coord) const;
0101 
0102     /**
0103      * @brief the player occupying a Coord
0104      * @description tells which players occupies a certain square in the board
0105      * @param coord the square to check
0106      * @return @c X if player 1, @c O if player 2, @c No if empty
0107      */
0108     Player player(const Coord &coord) const;
0109 
0110     /**
0111      * @brief set the player of a Coord
0112      * @description sets which player should occupy a certain square in the
0113      * playing board.
0114      * @param move the move to perform
0115      */
0116     void setPlayer(const Move &);
0117 
0118 private:
0119     /* property holding the actual playing board */
0120     Square **m_board;
0121 
0122     /* property containing the dimension of the actual playing board */
0123     Dimension *m_dimension;
0124 };
0125 
0126 } /* namespace bovo */
0127 
0128 #endif // BOVO_BOARD_H