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_COORD_H
0023 #define BOVO_COORD_H
0024 
0025 #include "common.h"
0026 
0027 /** @file file declaring the Coord class */
0028 
0029 /** namespace for game engine */
0030 namespace bovo
0031 {
0032 
0033 /**
0034  * A coordinate
0035  *
0036  * This class describes a coordinate on a playing field. It is
0037  * used as a container of an (x, y) coordinate pair that starts to
0038  * count with Origo (0, 0) in upper left corner. No negative coordinates
0039  * are allowed.
0040  *
0041  * If both x and y coordinates are static_cast<unsigned short int>(-1),
0042  * a special case is applied. Then the coordinate is invalid (all
0043  * coordinates outside of playing area are invalid) but it also means
0044  * that the coordinate refers to a moment before any moved has been played.
0045  * This can be queried with null().
0046  *
0047  * @code
0048  * Coord move(const Coord& coord) {
0049  *     if (coord.null()) {
0050  *         return computeAiTurn();
0051  *     } else {
0052  *         markCoordAsOpposite(coord);
0053  *         return computeAiTurn();
0054  *     }
0055  * }
0056  * @endcode
0057  */
0058 class Coord
0059 {
0060 public:
0061     /**
0062      * @brief standard constructor
0063      * @description constructs a Coord with given X and Y coordinates
0064      * @param x X coordinate
0065      * @param y Y coordinate
0066      */
0067     explicit Coord(usi x = -1, usi y = -1);
0068 
0069     /**
0070      * @brief copy constructor
0071      * @description constructs a Coord that is a copy of a given Coord
0072      * @param coord Coord to copy
0073      */
0074     Coord(const Coord &coord) = default;
0075     Coord &operator=(const Coord &coord) = default;
0076 
0077     /**
0078      * @brief
0079      * @description
0080      * @return
0081      */
0082     Coord down() const;
0083 
0084     /**
0085      * @brief
0086      * @description
0087      * @return
0088      */
0089     Coord left() const;
0090 
0091     /**
0092      * @brief is null?
0093      * @description tells if this coord is a null coordinate (-1, -1)
0094      * @return \c true if x == -1 and y == -1, \c false otherwise
0095      */
0096     bool null() const;
0097 
0098     /**
0099      * @brief
0100      * @description
0101      * @return
0102      */
0103     Coord right() const;
0104 
0105     /**
0106      * @brief
0107      * @description
0108      * @return
0109      */
0110     Coord up() const;
0111 
0112     /**
0113      * @brief
0114      * @description
0115      * @return
0116      */
0117     usi x() const;
0118 
0119     /**
0120      * @brief
0121      * @description
0122      * @return
0123      */
0124     usi y() const;
0125 
0126 private:
0127     /* X coordinate property */
0128     usi m_x;
0129 
0130     /* Y coordinate property */
0131     usi m_y;
0132 };
0133 
0134 } /* namespace bovo */
0135 
0136 #endif // BOVO_COORD_H