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 /** @file move.h declares Move */ 0023 0024 #ifndef BOVO_MOVE_H 0025 #define BOVO_MOVE_H 0026 0027 #include "common.h" 0028 #include "coord.h" 0029 0030 /** namespace for game engine */ 0031 namespace bovo 0032 { 0033 0034 /** 0035 * @brief class representing a move (a Coord and a Player id) 0036 * @description this class represents a game move, that is a player id (Player) 0037 * and a coordinate (Coord). 0038 * 0039 * @code 0040 * Move illegalMove(); // represents the move "-1", i.e. the move before the 0041 * // first move in the game 0042 * Move myMove(X, Coord(x, y)); 0043 * Move identicalMove(myMove.player(), myMove.x(), myMove.y()); 0044 * illegalMove.valid() == false; 0045 * myMove.valid == true; // if Coord(x, y) is in range 0046 * @endcode 0047 */ 0048 class Move 0049 { 0050 public: 0051 /** 0052 * @brief constructs Move 0053 * @description creates a Move with a Player and a coordinate 0054 * @param player player 0055 * @param col x-coordinate 0056 * @param row y-coordinate 0057 */ 0058 explicit Move(Player player = No, int col = -1, int row = -1); 0059 0060 /** 0061 * @brief constructs Move 0062 * @description creates a Move with a Player and a coordinate 0063 * @param player player 0064 * @param coord coordinate 0065 */ 0066 Move(Player player, const Coord &coord); 0067 0068 /** 0069 * @brief constructs Move 0070 * @description copy constructor for Move 0071 */ 0072 Move(const Move &m); 0073 0074 ~Move(); 0075 0076 /** 0077 * @brief returns the Coord 0078 * @return the coordinate 0079 */ 0080 Coord coord() const; 0081 0082 /** 0083 * @brief returns the Player 0084 * @return the player 0085 */ 0086 Player player() const; 0087 0088 /** 0089 * @brief returns whether this is a valid move 0090 * @description tells if the player of this move is X or O and the coord 0091 * is within the playing board limits. 0092 * @return \c true if move is valid, \c false otherwise 0093 */ 0094 bool valid() const; 0095 0096 /** 0097 * @brief x-coordinate 0098 * @return the x-coordinate 0099 */ 0100 usi x() const; 0101 0102 /** 0103 * @brief y-coordinate 0104 * @return the y-coordinate 0105 */ 0106 usi y() const; 0107 0108 private: 0109 /* the coordinate */ 0110 Coord m_coord; 0111 0112 /* the player */ 0113 Player m_player; 0114 }; 0115 0116 } /* namespace gui */ 0117 0118 #endif // BOVO_MOVE_H